Minimal parser that actually does something
This commit is contained in:
parent
2431a074b0
commit
7afb9d47fc
@ -5,6 +5,8 @@ use schala_lang::{tokenizing, parsing};
|
||||
use self::tokenizing::*;
|
||||
use self::parsing::*;
|
||||
|
||||
use schala_lang::tokenizing::TokenType::*;
|
||||
|
||||
struct AutoParser {
|
||||
tokens: Vec<Token>,
|
||||
}
|
||||
@ -32,11 +34,27 @@ impl AutoParser {
|
||||
self.tokens.pop().map(|t| { t.token_type }).unwrap_or(TokenType::EOF)
|
||||
}
|
||||
fn parse(&mut self) -> (Result<AST, ParseError>, Vec<String>) {
|
||||
let err = ParseError { msg: format!("Not yet implemented") };
|
||||
(Err(err), vec![])
|
||||
let ast = self.program();
|
||||
(ast, vec![])
|
||||
}
|
||||
}
|
||||
|
||||
impl AutoParser {
|
||||
fn program(&mut self) -> ParseResult<AST> {
|
||||
let etype = self.literal()?;
|
||||
Ok(AST(vec![Statement::ExpressionStatement(Expression(etype, None))]))
|
||||
}
|
||||
|
||||
fn literal(&mut self) -> ParseResult<ExpressionType> {
|
||||
Ok(match self.next() {
|
||||
Keyword(Kw::True) => ExpressionType::BoolLiteral(true),
|
||||
Keyword(Kw::False) => ExpressionType::BoolLiteral(false),
|
||||
_ => return ParseError::new("bad!")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct Schala { }
|
||||
|
||||
impl Schala {
|
||||
|
@ -101,7 +101,7 @@ pub struct ParseError {
|
||||
}
|
||||
|
||||
impl ParseError {
|
||||
fn new<T>(msg: &str) -> ParseResult<T> {
|
||||
pub fn new<T>(msg: &str) -> ParseResult<T> {
|
||||
Err(ParseError { msg: msg.to_string() })
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user