rascal_parser 0.1.2

Rascal programming language parser.
Documentation
use crate::ast::Expression;
use crate::scanner::token::Token;

/// The parser takes an iterator of [Token]s from the scanner, and uses the grammar of the language
/// to convert this stream of tokens into a semantically valid Abstract Syntax Tree (AST).
///
/// Whereas the scanner ensures incoming syntax is correct, e.g. the characters are arranged into
/// chunks of valid tokens, the parser ensures the order of these tokens is meaningful and correct.
pub struct Parser {
    tokens: Vec<Token>,
}
impl From<Vec<Token>> for Parser {
    fn from(tokens: Vec<Token>) -> Self {
        Parser { tokens }
    }
}
impl Parser {
    pub fn parse(&mut self) -> Result<Expression, Vec<ParserError>> {
        todo!()
    }
    /// Returns the next value in the token list, or the EOF token when the end of the iterator is
    /// reached.
    pub fn next_or_eof(&mut self) -> Token {
        self.tokens.pop().unwrap_or(Token::Eof)
    }
    pub fn peek(&self) -> &Token {
        self.tokens.last().unwrap_or(&Token::Eof)
    }
}

#[derive(Debug, Clone)]
pub enum ParserError {
    UnmatchedBrace,
    UnexpectedToken(Token),
}