Minimal parser that actually does something

This commit is contained in:
greg 2018-03-10 20:26:40 -08:00
parent 2431a074b0
commit 7afb9d47fc
2 changed files with 21 additions and 3 deletions

View File

@ -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 {

View File

@ -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() })
}
}