pub struct Parser {
tokens: Vec<Token>,
position: usize,
}Fields§
§tokens: Vec<Token>§position: usizeImplementations§
§impl Parser
impl Parser
pub fn parse(&mut self) -> Result<AstNode, CompilerError>
pub fn parse(&mut self) -> Result<AstNode, CompilerError>
Parse the token stream into an AST
fn parse_statement(&mut self) -> Result<Option<AstNode>, CompilerError>
fn is_at_end(&self) -> bool
fn current_token(&self) -> Result<&Token, CompilerError>
fn advance(&mut self) -> Result<&Token, CompilerError>
fn check(&self, token_type: &TokenType) -> bool
fn match_token(&mut self, token_type: &TokenType) -> Result<bool, CompilerError>
fn consume(&mut self, token_type: TokenType) -> Result<&Token, CompilerError>
fn consume_identifier(&mut self) -> Result<String, CompilerError>
fn error_eof(&self) -> CompilerError
fn error_eof(&self) -> CompilerError
Create an “unexpected end of input” error
fn error_expected(&self, expected: &TokenType) -> CompilerError
fn error_expected(&self, expected: &TokenType) -> CompilerError
Create an “expected X” error with location
fn error_expected_identifier(&self) -> CompilerError
fn error_expected_identifier(&self) -> CompilerError
Create an “expected identifier” error
fn last_position(&self) -> (usize, usize)
fn last_position(&self) -> (usize, usize)
Get the position of the last token (for EOF errors)
§impl Parser
impl Parser
fn parse_block(&mut self) -> Result<Option<AstNode>, CompilerError>
fn parse_assignment(&mut self) -> Result<Option<AstNode>, CompilerError>
§impl Parser
impl Parser
fn parse_expression(&mut self) -> Result<AstNode, CompilerError>
fn parse_expression_statement( &mut self, ) -> Result<Option<AstNode>, CompilerError>
§impl Parser
impl Parser
fn parse_if(&mut self) -> Result<Option<AstNode>, CompilerError>
fn parse_for(&mut self) -> Result<Option<AstNode>, CompilerError>
fn parse_switch(&mut self) -> Result<Option<AstNode>, CompilerError>
§impl Parser
impl Parser
fn parse_function(&mut self) -> Result<Option<AstNode>, CompilerError>
Auto Trait Implementations§
impl Freeze for Parser
impl RefUnwindSafe for Parser
impl Send for Parser
impl Sync for Parser
impl Unpin for Parser
impl UnwindSafe for Parser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more