Skip to main content

Parser

Struct Parser 

Source
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

Source

pub fn new(tokens: Vec<Token>) -> Self

Creates a new parser for the given token stream.

§Panics

Panics if tokens is empty. The lexer always appends an Eof token, so a well-formed token stream is never empty.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.