#[non_exhaustive]pub struct BlockScalarSyntax {
pub header_chars_before_span: u32,
pub header_bytes_before_span: u32,
pub chomping: Chomping,
pub indentation_indicator: Option<u8>,
pub digit_first: bool,
pub content_indent: u32,
}Expand description
Source syntax attached to a literal or folded block scalar.
Available only with extended_details.
Coordinates are relative to the start of the accompanying scalar span. Keep that span
together with this value: rebasing or replacing its start invalidates these distances.
The ordinary scalar span retains its existing meaning, which need not include the header.
This type does not store another crate::Marker or retain borrowed source text.
The header ranges cover | or > and its adjacent indicators, excluding whitespace,
comments, and the header line break. Character and byte distances differ when, for example,
a header comment contains Unicode. Use Self::header_byte_range to inspect byte distances
when available. Indicator offsets are computed from the chomping mode, indentation digit,
and their order.
Distances and content indentation use u32. If a parsed value cannot fit, the scalar’s
syntax is None; scalar decoding and the accompanying span remain available.
Normal builds provide no equality, ordering, or hashing. Inspect the individual fields
relevant to your use case. The opt-in test_equality feature enables equality for testing;
it ignores optional byte distances, like crate::Marker, and irrelevant indicator order.
This is an explicit comparison of source syntax. Equality of ScalarStyle, events, and
tokens instead ignores this metadata altogether, keeping output comparisons independent of
whether extended_details is enabled.
Comparing synthetic syntax with parsed syntax is intentionally unavailable by default:
use granit_parser::BlockScalarSyntax;
let syntax = BlockScalarSyntax::default();
let _ = syntax == BlockScalarSyntax::default();Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.header_chars_before_span: u32Character distance backwards from the scalar span’s start to | or >.
header_bytes_before_span: u32Byte distance backwards from the scalar span’s start to | or >.
Meaningful only when the accompanying span’s start has a byte offset. Otherwise zero.
chomping: ChompingChomping mode selected by the header.
indentation_indicator: Option<u8>Explicit indentation digit (1..=9), or None when indentation was inferred.
digit_first: boolWhether the indentation digit precedes the chomping sign when both are present.
Ignored when either indicator is absent, including by test_equality comparisons.
Parsed headers set this to false in that case.
content_indent: u32Effective number of leading indentation spaces removed from content lines.
This is an absolute content indentation level, not the explicit indentation digit.
For an inferred header ending at EOF before its line break, this reports the minimum
level required by the enclosing block. At the root it is zero by default, or one when
crate::Options::block_scalar_indent_at_least_one is enabled.
Implementations§
Source§impl BlockScalarSyntax
impl BlockScalarSyntax
Sourcepub const fn new(
chomping: Chomping,
indentation_indicator: Option<u8>,
content_indent: usize,
) -> Option<Self>
pub const fn new( chomping: Chomping, indentation_indicator: Option<u8>, content_indent: usize, ) -> Option<Self>
Construct synthetic syntax whose header begins at the accompanying span’s start.
chompingselects clipping, stripping, or keeping trailing line breaks.indentation_indicatoris the optional explicit digit, which must be in1..=9.content_indentis the effective absolute content indentation level.
Returns None for an invalid digit or content indentation larger than u32::MAX.
Otherwise the sign precedes the digit when both are present, and both backwards
distances are zero. Set the public fields to describe a different indicator order or
a header preceding the scalar span.
Sourcepub const fn header_len(&self) -> usize
pub const fn header_len(&self) -> usize
Return the header-indicator length in both characters and bytes, excluding whitespace.
Parsed headers contain one to three ASCII characters.
Sourcepub const fn chomping_offset(&self) -> Option<u8>
pub const fn chomping_offset(&self) -> Option<u8>
Return the chomping sign’s offset from the header start, or None for clipping.
Offsets are the same in characters and bytes: a block header contains only ASCII.
Sourcepub const fn indentation_offset(&self) -> Option<u8>
pub const fn indentation_offset(&self) -> Option<u8>
Return the indentation digit’s offset from the header start, or None if inferred.
Offsets are the same in characters and bytes: a block header contains only ASCII.
Sourcepub fn header_char_range(&self, span: &Span) -> Option<Range<usize>>
pub fn header_char_range(&self, span: &Span) -> Option<Range<usize>>
Return the header’s character-index range using its accompanying scalar span.
Returns None if the coordinates underflow or overflow. The caller must supply the
original matching span; arithmetic checks cannot detect every mismatched span.
Sourcepub fn header_byte_range(&self, span: &Span) -> Option<Range<usize>>
pub fn header_byte_range(&self, span: &Span) -> Option<Range<usize>>
Return the header’s byte range using its accompanying scalar span.
Returns None for inputs without byte offsets or if coordinates underflow or overflow.
The caller must supply the original matching span.
Sourcepub fn chomping_char_range(&self, span: &Span) -> Option<Range<usize>>
pub fn chomping_char_range(&self, span: &Span) -> Option<Range<usize>>
Return the explicit chomping sign’s character range, or None if absent/unavailable.
Sourcepub fn chomping_byte_range(&self, span: &Span) -> Option<Range<usize>>
pub fn chomping_byte_range(&self, span: &Span) -> Option<Range<usize>>
Return the explicit chomping sign’s byte range, or None if absent/unavailable.
Sourcepub fn indentation_char_range(&self, span: &Span) -> Option<Range<usize>>
pub fn indentation_char_range(&self, span: &Span) -> Option<Range<usize>>
Return the explicit indentation digit’s character range, or None if absent/unavailable.
Sourcepub fn indentation_byte_range(&self, span: &Span) -> Option<Range<usize>>
pub fn indentation_byte_range(&self, span: &Span) -> Option<Range<usize>>
Return the explicit indentation digit’s byte range, or None if absent/unavailable.
Sourcepub fn header_slice<'source>(
&self,
span: &Span,
source: &'source str,
) -> Option<&'source str>
pub fn header_slice<'source>( &self, span: &Span, source: &'source str, ) -> Option<&'source str>
Return the raw header indicators from the original source.
spanis the original accompanying scalar span.sourceis the complete original UTF-8 source, using the span’s coordinate origin.
Returns None when byte positions are unavailable or outside valid source boundaries.