ExpressionParser

Trait ExpressionParser 

Source
pub trait ExpressionParser {
    // Required methods
    fn current_token(&self) -> &Token;
    fn advance(&mut self);
    fn peek(&self) -> Option<&Token>;
    fn is_at_end(&self) -> bool;
    fn consume(&mut self, expected: Token) -> Result<(), String>;
    fn parse_identifier(&mut self) -> Result<String, String>;
}
Expand description

Trait for expression parsers This allows us to modularize expression parsing while maintaining consistency

Required Methods§

Source

fn current_token(&self) -> &Token

Get the current token

Source

fn advance(&mut self)

Advance to the next token

Source

fn peek(&self) -> Option<&Token>

Peek at the next token without consuming it

Source

fn is_at_end(&self) -> bool

Check if we’re at the end of input

Source

fn consume(&mut self, expected: Token) -> Result<(), String>

Consume a specific token or return error

Source

fn parse_identifier(&mut self) -> Result<String, String>

Parse an identifier and return its name

Implementors§