pub struct Parser { /* private fields */ }Expand description
A parser that transforms a token stream into a Song AST.
The parser is created from a Vec<Token> (typically produced by
Lexer::tokenize) and consumes tokens one at a time, building up the
AST line by line.
Implementations§
Source§impl Parser
impl Parser
Sourcepub fn parse(self) -> Result<Song, ParseError>
pub fn parse(self) -> Result<Song, ParseError>
Parses the token stream and returns a Song AST.
Metadata directives ({title}, {artist}, etc.) automatically
populate Song::metadata. Comment directives are converted to
Line::Comment with the appropriate CommentStyle.
Returns a ParseError on the first structural problem encountered
(e.g., unclosed directives or chords). Use parse_lenient to
collect all errors and obtain a partial AST.
Sourcepub fn parse_lenient(self) -> ParseResult
pub fn parse_lenient(self) -> ParseResult
Parses the token stream leniently, collecting all errors.
Unlike parse, this method does not stop at the first error.
When a line cannot be parsed, the error is recorded and the parser
skips to the next line to continue. The returned ParseResult
contains the partial AST (all successfully parsed lines) and a
list of all errors encountered.
Sourcepub fn parse_lenient_limited(self, max_errors: usize) -> ParseResult
pub fn parse_lenient_limited(self, max_errors: usize) -> ParseResult
Like parse_lenient, but stops collecting errors
after max_errors have been recorded. Set to 0 to disable the limit.
Sourcepub fn populate_metadata(metadata: &mut Metadata, directive: &Directive)
pub fn populate_metadata(metadata: &mut Metadata, directive: &Directive)
Populate metadata fields from a directive’s kind and value.
This is called during parsing for unselectored directives, and again
by SelectorContext::filter_song
after filtering to re-derive metadata from matching selector-bearing directives.