From 3bfd251a68eff9c4e58e71839da777d3398b0a02 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 10 Mar 2018 20:05:27 -0800 Subject: [PATCH] autoparser framework done --- src/schala_lang/autoparser.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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));