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 {
let err = ParseError { msg: format!("Not yet implemented") }; tokens: Vec<Token>,
(Err(err), vec![])
} }
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") };
(Err(err), vec![])
}
}
pub struct Schala { } pub struct Schala { }
@ -42,8 +56,10 @@ impl ProgrammingLanguageInterface for Schala {
return output; return output;
} }
} }
let mut parser = AutoParser::new(tokens);
let ast = match auto_parse(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));