autoparser framework done

This commit is contained in:
greg 2018-03-10 20:05:27 -08:00
parent a033c82d13
commit 3bfd251a68

View File

@ -5,11 +5,25 @@ use schala_lang::{tokenizing, parsing};
use self::tokenizing::*; use self::tokenizing::*;
use self::parsing::*; use self::parsing::*;
fn auto_parse(input: Vec<Token>) -> (Result<AST, ParseError>, Vec<String>) { struct AutoParser {
tokens: Vec<Token>,
}
impl AutoParser {
fn new(tokens: Vec<Token>) -> 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<AST, ParseError>, Vec<String>) {
let err = ParseError { msg: format!("Not yet implemented") }; let err = ParseError { msg: format!("Not yet implemented") };
(Err(err), vec![]) (Err(err), vec![])
} }
}
pub struct Schala { } pub struct Schala { }
@ -43,7 +57,9 @@ impl ProgrammingLanguageInterface for Schala {
} }
} }
let ast = match auto_parse(tokens) { let mut parser = AutoParser::new(tokens);
let ast = match parser.parse() {
(Ok(ast), trace) => { (Ok(ast), trace) => {
if options.debug_parse { if options.debug_parse {
output.add_artifact(TraceArtifact::new_parse_trace(trace)); output.add_artifact(TraceArtifact::new_parse_trace(trace));