pub(super) struct Reader<'a> {
text: &'a str,
document: &'a YamlDoc,
step: usize,
}Expand description
Reads a document by the byte spans yaml-rt reports.
A mapping that does not fit the tree, such as one with explicit or complex keys, is kept as raw text instead.
Fields§
§text: &'a str§document: &'a YamlDoc§step: usizeImplementations§
Source§impl Reader<'_>
impl Reader<'_>
Sourcepub(super) fn opaque(
&self,
site: Site,
node: NodeId,
span: Bounds,
) -> Result<Parsed<Value>, DocumentError>
pub(super) fn opaque( &self, site: Site, node: NodeId, span: Bounds, ) -> Result<Parsed<Value>, DocumentError>
A mapping the tree cannot edit, kept as raw text. A flow mapping with entries also gets the block rewrite that edits use.
Sourcepub(super) fn is_flow_with_entries(&self, node: NodeId) -> bool
pub(super) fn is_flow_with_entries(&self, node: NodeId) -> bool
Whether node is a flow mapping with entries.
Sourcefn flow_rewrite(
&self,
site: Site,
node: NodeId,
span: Bounds,
end: usize,
) -> Result<Option<Mapping>, DocumentError>
fn flow_rewrite( &self, site: Site, node: NodeId, span: Bounds, end: usize, ) -> Result<Option<Mapping>, DocumentError>
The flow mapping node as a block mapping, or None when it has a
comment, a key that is not a scalar, or a value that spans lines.
end is where the line of the closing brace ends.
fn push_line(out: &mut String, pad: &str, key: &str, rest: &str)
Sourcefn block_source(
&self,
node: NodeId,
indent: usize,
) -> Result<Option<String>, DocumentError>
fn block_source( &self, node: NodeId, indent: usize, ) -> Result<Option<String>, DocumentError>
The entries of the flow mapping node written as block source with
keys at indent. A document cannot start indented, so the caller
moves the result to where the mapping sits.
Source§impl Reader<'_>
impl Reader<'_>
Sourcepub(super) fn value(
&self,
name: &str,
node: NodeId,
span: Bounds,
colon_end: usize,
indent: usize,
) -> Result<Parsed<Value>, DocumentError>
pub(super) fn value( &self, name: &str, node: NodeId, span: Bounds, colon_end: usize, indent: usize, ) -> Result<Parsed<Value>, DocumentError>
The value of a key as a node, and where its text ends. A mapping the tree cannot edit is kept as raw text.
Sourcepub(super) fn mapping_style(&self, node: NodeId) -> Option<CollectionStyle>
pub(super) fn mapping_style(&self, node: NodeId) -> Option<CollectionStyle>
The style of node when it is a mapping.
Sourcepub(super) fn mapping(
&self,
node: NodeId,
span: Bounds,
site: Site,
) -> Result<Option<Parsed<Mapping>>, DocumentError>
pub(super) fn mapping( &self, node: NodeId, span: Bounds, site: Site, ) -> Result<Option<Parsed<Mapping>>, DocumentError>
node as an editable mapping, or None when it is not a mapping, is a
flow mapping with entries, or does not fit the tree.
fn block_mapping( &self, node: NodeId, site: Site, ) -> Result<Option<Parsed<Mapping>>, DocumentError>
fn empty_flow_mapping( &self, node: NodeId, span: Bounds, site: Site, ) -> Result<Option<Parsed<Mapping>>, DocumentError>
Source§impl<'a> Reader<'a>
impl<'a> Reader<'a>
pub(super) fn new(text: &'a str, document: &'a YamlDoc) -> Self
pub(super) fn tree(&self) -> Result<Tree, DocumentError>
Sourcefn block(
&self,
mapping: NodeId,
from: usize,
) -> Result<Option<Parsed<Block>>, DocumentError>
fn block( &self, mapping: NodeId, from: usize, ) -> Result<Option<Parsed<Block>>, DocumentError>
The entries of a block mapping, with the first one’s leading text
starting at from. A mapping that does not fit the tree stays raw.
A key that appears twice is an error.
fn entry( &self, key: NodeId, value: NodeId, cursor: usize, ) -> Result<Option<Parsed<Entry>>, DocumentError>
Sourcefn leaf(
&self,
colon_end: usize,
value: NodeId,
span: Bounds,
) -> Result<Parsed<Leaf>, DocumentError>
fn leaf( &self, colon_end: usize, value: NodeId, span: Bounds, ) -> Result<Parsed<Leaf>, DocumentError>
A value kept as raw text. What follows it on its last line, such as a comment, goes into the tail.
Sourcefn scalar(&self, node: NodeId) -> Option<String>
fn scalar(&self, node: NodeId) -> Option<String>
The value of a scalar node, with quotes removed and escapes resolved.
Sourcefn comment_start(&self, value: NodeId, span: Bounds, fallback: usize) -> usize
fn comment_start(&self, value: NodeId, span: Bounds, fallback: usize) -> usize
Where the whitespace before a trailing comment starts, or fallback
when there is no comment inside the value’s span.
yaml-rt extends the span of a plain scalar over a comment that
follows it. Other scalars end before it.
Sourcefn empty_braces(&self, node: NodeId, span: Bounds) -> Option<usize>
fn empty_braces(&self, node: NodeId, span: Bounds) -> Option<usize>
The offset of the { of a flow mapping with nothing but whitespace
between its braces, which ends its node.
Sourcefn colon_end(&self, key_end: usize) -> Option<usize>
fn colon_end(&self, key_end: usize) -> Option<usize>
The offset after the colon that follows a key.
Sourcefn extent(&self, node: NodeId) -> Result<Bounds, DocumentError>
fn extent(&self, node: NodeId) -> Result<Bounds, DocumentError>
The span of a node, widened to cover its descendants.
yaml-rt ends a collection’s span before the content of a block
scalar that closes it.
fn range(&self, node: NodeId) -> Result<Bounds, DocumentError>
fn slice(&self, start: usize, end: usize) -> Result<&'a str, DocumentError>
Sourcefn line_start(&self, offset: usize) -> usize
fn line_start(&self, offset: usize) -> usize
The offset of the start of the line that holds offset.
Sourcefn line_end(&self, offset: usize) -> usize
fn line_end(&self, offset: usize) -> usize
The offset after the line break that ends the line holding offset.
An offset that already follows a line break is its own answer.
fn with_detected_step(self) -> Self
Sourcefn detect_step(&self, mapping: NodeId) -> Option<usize>
fn detect_step(&self, mapping: NodeId) -> Option<usize>
The indent of the first nested block mapping below its key.