pub struct BasicScanner {Show 25 fields
input: String,
position: Position,
current_char: Option<char>,
tokens: Vec<Token>,
token_index: usize,
done: bool,
indent_stack: Vec<usize>,
current_indent: usize,
allow_simple_key: bool,
simple_key_allowed: bool,
flow_level: usize,
preserve_comments: bool,
detected_indent_style: Option<IndentStyle>,
indent_samples: Vec<(usize, bool)>,
previous_indent_level: usize,
buffer: String,
char_cache: Vec<char>,
current_char_index: usize,
profiler: Option<YamlProfiler>,
scanning_error: Option<Error>,
limits: Limits,
resource_tracker: ResourceTracker,
inline_sequence_depth: usize,
compact_sequence_indents: Vec<usize>,
indent_is_sequence: Vec<bool>,
}Expand description
A basic scanner implementation for YAML tokenization
Fields§
§input: String§position: Position§current_char: Option<char>§tokens: Vec<Token>§token_index: usize§done: bool§indent_stack: Vec<usize>§current_indent: usize§allow_simple_key: bool§simple_key_allowed: bool§flow_level: usize§preserve_comments: bool§detected_indent_style: Option<IndentStyle>§indent_samples: Vec<(usize, bool)>§previous_indent_level: usize§buffer: String§char_cache: Vec<char>§current_char_index: usize§profiler: Option<YamlProfiler>§scanning_error: Option<Error>§limits: Limits§resource_tracker: ResourceTracker§inline_sequence_depth: usize§compact_sequence_indents: Vec<usize>§indent_is_sequence: Vec<bool>Implementations§
Source§impl BasicScanner
impl BasicScanner
Sourcepub fn with_limits(input: String, limits: Limits) -> Self
pub fn with_limits(input: String, limits: Limits) -> Self
Create a new scanner with custom resource limits
Sourcepub fn new_eager(input: String) -> Self
pub fn new_eager(input: String) -> Self
Create a new scanner with eager token scanning (for compatibility)
Sourcepub fn new_eager_with_limits(input: String, limits: Limits) -> Self
pub fn new_eager_with_limits(input: String, limits: Limits) -> Self
Create a new scanner with eager token scanning and custom limits
Sourcepub fn new_with_comments(input: String) -> Self
pub fn new_with_comments(input: String) -> Self
Create a new scanner with comment preservation enabled
Sourcepub fn new_with_comments_and_limits(input: String, limits: Limits) -> Self
pub fn new_with_comments_and_limits(input: String, limits: Limits) -> Self
Create a new scanner with comments and custom limits
Sourcepub fn new_eager_with_comments(input: String) -> Self
pub fn new_eager_with_comments(input: String) -> Self
Create a new scanner with eager scanning and comment preservation
Sourcepub const fn detected_indent_style(&self) -> Option<&IndentStyle>
pub const fn detected_indent_style(&self) -> Option<&IndentStyle>
Get the detected indentation style from the document
Sourcepub const fn has_scanning_error(&self) -> bool
pub const fn has_scanning_error(&self) -> bool
Check if there was a scanning error
Sourcepub fn take_scanning_error(&mut self) -> Option<Error>
pub fn take_scanning_error(&mut self) -> Option<Error>
Get the scanning error if any
Sourcefn skip_whitespace(&mut self)
fn skip_whitespace(&mut self)
Skip whitespace characters (excluding newlines)
Sourcefn handle_indentation(&mut self) -> Result<()>
fn handle_indentation(&mut self) -> Result<()>
Handle indentation and produce block tokens if necessary
Sourcefn analyze_indentation_pattern(
&mut self,
current_indent: usize,
has_tabs: bool,
has_spaces: bool,
) -> Result<()>
fn analyze_indentation_pattern( &mut self, current_indent: usize, has_tabs: bool, has_spaces: bool, ) -> Result<()>
Analyze indentation pattern to detect the document’s indentation style
Sourcefn detect_space_indentation_width(&mut self)
fn detect_space_indentation_width(&mut self)
Detect the consistent space indentation width from samples
Sourcefn is_valid_indentation_level(&self, indent: usize) -> bool
fn is_valid_indentation_level(&self, indent: usize) -> bool
Check if the given indentation level is valid based on current context
Sourcefn validate_indentation_consistency(&self, current_indent: usize) -> Result<()>
fn validate_indentation_consistency(&self, current_indent: usize) -> Result<()>
Validate that current indentation is consistent with detected style
Sourcefn is_plain_scalar_start(&self) -> bool
fn is_plain_scalar_start(&self) -> bool
Check if current position starts a plain scalar
Sourcefn is_yaml_bool(value: &str) -> bool
fn is_yaml_bool(value: &str) -> bool
Check if the value is a YAML boolean
Sourcefn is_yaml_null(value: &str) -> bool
fn is_yaml_null(value: &str) -> bool
Check if the value is a YAML null
Sourcefn normalize_scalar(value: String) -> String
fn normalize_scalar(value: String) -> String
Normalize a scalar value based on YAML rules.
The scanner preserves the original text of plain scalars. Type
resolution (including version-aware bool/null mapping) happens in
the composer (see crate::resolver::resolve_plain_scalar). This
preserves enough information for the composer to apply the
YAML 1.1 vs 1.2 distinction and for round-trip emitters to
recover the original spelling.
Sourcefn scan_number(&mut self) -> Result<Token>
fn scan_number(&mut self) -> Result<Token>
Scan a number token
Sourcefn scan_plain_scalar(&mut self) -> Result<Token>
fn scan_plain_scalar(&mut self) -> Result<Token>
Scan a plain scalar (unquoted string)
Sourcefn scan_quoted_string(&mut self, quote_char: char) -> Result<Token>
fn scan_quoted_string(&mut self, quote_char: char) -> Result<Token>
Scan a quoted string
Sourcefn scan_document_start(&mut self) -> Result<Option<Token>>
fn scan_document_start(&mut self) -> Result<Option<Token>>
Scan document start marker (—)
Sourcefn scan_yaml_directive(&mut self) -> Result<Option<Token>>
fn scan_yaml_directive(&mut self) -> Result<Option<Token>>
Scan YAML version directive (%YAML)
Sourcefn scan_tag_directive(&mut self) -> Result<Option<Token>>
fn scan_tag_directive(&mut self) -> Result<Option<Token>>
Scan TAG directive (%TAG)
Sourcefn scan_tag_handle(&mut self) -> Result<String>
fn scan_tag_handle(&mut self) -> Result<String>
Scan a tag handle for TAG directive
Sourcefn scan_tag_prefix(&mut self) -> Result<String>
fn scan_tag_prefix(&mut self) -> Result<String>
Scan a tag prefix (URI) for TAG directive
Sourcefn is_directive(&self) -> bool
fn is_directive(&self) -> bool
Check if current position might be a directive
Sourcefn scan_document_end(&mut self) -> Result<Option<Token>>
fn scan_document_end(&mut self) -> Result<Option<Token>>
Scan document end marker (…)
Sourcefn scan_comment(&mut self) -> Result<Token>
fn scan_comment(&mut self) -> Result<Token>
Scan a comment token
Sourcefn process_line(&mut self) -> Result<()>
fn process_line(&mut self) -> Result<()>
Process a line and generate appropriate tokens
Sourcefn scan_next_token(&mut self) -> Result<()>
fn scan_next_token(&mut self) -> Result<()>
Scan the next token lazily
Sourcefn scan_all_tokens(&mut self) -> Result<()>
fn scan_all_tokens(&mut self) -> Result<()>
Pre-scan all tokens (simplified approach for basic implementation)
Sourcefn is_pure_number(&self) -> bool
fn is_pure_number(&self) -> bool
Peek at a character at the given offset (can be negative) Check if the current position starts a pure number (digits/dots/minus only, not followed by letters). Values like 500m, 128Mi should be treated as plain scalars.
fn peek_char(&self, offset: isize) -> Option<char>
Sourcefn scan_anchor(&mut self) -> Result<Token>
fn scan_anchor(&mut self) -> Result<Token>
Scan an anchor token (&name)
Sourcefn scan_alias(&mut self) -> Result<Token>
fn scan_alias(&mut self) -> Result<Token>
Scan an alias token (*name)
Sourcefn scan_identifier(&mut self) -> Result<String>
fn scan_identifier(&mut self) -> Result<String>
Scan an identifier (used for anchor and alias names)
Sourcefn scan_literal_block_scalar(&mut self) -> Result<Token>
fn scan_literal_block_scalar(&mut self) -> Result<Token>
Scan a literal block scalar (|)
Sourcefn scan_folded_block_scalar(&mut self) -> Result<Token>
fn scan_folded_block_scalar(&mut self) -> Result<Token>
Scan a folded block scalar (>)
Sourcefn scan_block_scalar_header(&mut self) -> Result<(ChompingMode, Option<usize>)>
fn scan_block_scalar_header(&mut self) -> Result<(ChompingMode, Option<usize>)>
Parse block scalar header indicators (+, -, and explicit indent)
Sourcefn skip_to_next_line(&mut self) -> Result<()>
fn skip_to_next_line(&mut self) -> Result<()>
Advance the cursor PAST the next line break, but do not consume any leading whitespace on the line that follows. The block- scalar header parser uses this to step from the indicator line to the start of the content line — the next line’s leading spaces are part of its content_indent, not header whitespace.
Sourcefn find_block_scalar_indent(&mut self, base_indent: usize) -> Result<usize>
fn find_block_scalar_indent(&mut self, base_indent: usize) -> Result<usize>
Find the content indentation for a block scalar.
Per spec §8.1.1.1, indent is the leading-space count of the first
non-empty content line (or the longest blank-line indent if no
non-empty line exists). A non-empty line whose indent is not
strictly deeper than base_indent is outside the scalar’s
scope — that line is a sibling structure, not content
(yaml-test-suite K858).
Sourcefn count_line_indent(&mut self) -> usize
fn count_line_indent(&mut self) -> usize
Count indentation at start of current line
Sourcefn collect_literal_block_content(
&mut self,
content_indent: usize,
chomping: ChompingMode,
) -> Result<String>
fn collect_literal_block_content( &mut self, content_indent: usize, chomping: ChompingMode, ) -> Result<String>
Collect content for a literal block scalar.
Each line is preserved with its terminating newline. After collection we apply the chomping mode per spec §8.1.1.2.
Sourcefn is_doc_marker_here(&self) -> bool
fn is_doc_marker_here(&self) -> bool
Check if cursor is at --- or ... followed by whitespace/EOL.
Sourcefn collect_folded_block_content(
&mut self,
content_indent: usize,
chomping: ChompingMode,
) -> Result<String>
fn collect_folded_block_content( &mut self, content_indent: usize, chomping: ChompingMode, ) -> Result<String>
Collect content for a folded block scalar.
Folding rules (§8.1.3): a sequence of single blank lines between
equally-indented non-empty content lines collapses into a single
space; runs of blank lines emit n-1 newlines; more-indented
lines preserve their newline boundaries. After collection, apply
chomping (§8.1.1.2).
Sourcefn maybe_open_block_mapping_for_key(&mut self) -> Result<()>
fn maybe_open_block_mapping_for_key(&mut self) -> Result<()>
Emit a BlockMappingStart token if the current position is the
start of an implicit key and no mapping is yet active at this
indent level. Shared by plain and quoted scalar dispatch.
Sourcefn colon_belongs_to_alias_anchor_name(&self) -> bool
fn colon_belongs_to_alias_anchor_name(&self) -> bool
Look ahead on the current line for a : that marks a mapping key.
Per YAML 1.2 §7.3.3, a plain scalar may contain a : that is not
followed by whitespace. Only : terminates the scalar. If the
line begins with " or ', the leading quoted scalar’s contents
are scanned past (including '' and \" escapes) before looking
for the : that would make this scalar a key. This handles
yaml-test-suite 6H3V ('foo: bar\': baz') and 6SLA.
For an alias/anchor at the current position, scan past
the &/* and the name characters; if the FIRST char that
would terminate the name is :, the colon is PART of the
alias/anchor name (yaml-test-suite 2SXE). Returns true in
that case so the caller can skip the implicit-key fast-path.
Sourcefn line_after_indent_is_implicit_key(&self) -> bool
fn line_after_indent_is_implicit_key(&self) -> bool
Scan ahead on the current line (the rest of the post-indent
content) to determine whether it looks like an implicit
mapping key — i.e. has a : separator (or : at line end)
before any newline.
Sourcefn most_recent_token_is_value_separator(&self) -> bool
fn most_recent_token_is_value_separator(&self) -> bool
Walk back through recent tokens; if the last non-property
token was Value (:), the parser is in value-expectation
mode (key not yet matched with a value).
fn check_for_mapping_ahead(&self) -> bool
Sourcefn check_active_mapping_at_level(&self, _target_indent: usize) -> bool
fn check_active_mapping_at_level(&self, _target_indent: usize) -> bool
Check if there’s an active mapping at the specified indentation level This method properly handles BlockEnd tokens by tracking mapping start/end pairs
Trait Implementations§
Source§impl Debug for BasicScanner
impl Debug for BasicScanner
Source§impl ScalarScanner for BasicScanner
Implementation of ScalarScanner for BasicScanner
impl ScalarScanner for BasicScanner
Implementation of ScalarScanner for BasicScanner