diff --git a/src/schala_lang/autoparser.rs b/src/schala_lang/autoparser.rs index 3a685b2..30b546f 100644 --- a/src/schala_lang/autoparser.rs +++ b/src/schala_lang/autoparser.rs @@ -5,11 +5,25 @@ use schala_lang::{tokenizing, parsing}; use self::tokenizing::*; use self::parsing::*; -fn auto_parse(input: Vec) -> (Result, Vec) { - let err = ParseError { msg: format!("Not yet implemented") }; - (Err(err), vec![]) +struct AutoParser { + tokens: Vec, } +impl AutoParser { + fn new(tokens: Vec) -> AutoParser { + AutoParser { tokens: tokens.into_iter().rev().collect() } + } + fn peek(&mut self) -> TokenType { + self.tokens.last().map(|ref t| { t.token_type.clone() }).unwrap_or(TokenType::EOF) + } + fn next(&mut self) -> TokenType { + self.tokens.pop().map(|t| { t.token_type }).unwrap_or(TokenType::EOF) + } + fn parse(&mut self) -> (Result, Vec) { + let err = ParseError { msg: format!("Not yet implemented") }; + (Err(err), vec![]) + } +} pub struct Schala { } @@ -42,8 +56,10 @@ impl ProgrammingLanguageInterface for Schala { return output; } } + + let mut parser = AutoParser::new(tokens); - let ast = match auto_parse(tokens) { + let ast = match parser.parse() { (Ok(ast), trace) => { if options.debug_parse { output.add_artifact(TraceArtifact::new_parse_trace(trace));