pub struct Parser<'lexer> { /* private fields */ }
Expand description
The Parser
struct is responsible for parsing a sequence of tokens into an abstract
syntax tree (AST). The parser is implemented as a recursive descent parser, which is
a top-down parser that starts from the root of the syntax tree and works its way down
to the leaves.
The Parser
struct contains a reference to a Lexer
instance, which is used to
obtain the tokens that make up the input program. The parser is also responsible for
reporting syntax errors in the input program. When a syntax error is encountered, the
parser returns an error containing a message describing the error.
Implementations§
Source§impl<'lexer> Parser<'lexer>
impl<'lexer> Parser<'lexer>
pub fn new(lexer: Lexer<'lexer>) -> Self
Sourcepub fn parse_program(&mut self) -> Result<Program, Error>
pub fn parse_program(&mut self) -> Result<Program, Error>
The main entry point for the parser. This method is responsible for parsing and lexing the entire input program, and returning the resulting AST or a syntax error.
§Returns
An Ok
containing the AST (starting with the root Program
node) if the input
program is successfully parsed, otherwise an Err
containing a syntax error.