autoparser framework done
This commit is contained in:
parent
a033c82d13
commit
3bfd251a68
@ -5,11 +5,25 @@ use schala_lang::{tokenizing, parsing};
|
||||
use self::tokenizing::*;
|
||||
use self::parsing::*;
|
||||
|
||||
fn auto_parse(input: Vec<Token>) -> (Result<AST, ParseError>, Vec<String>) {
|
||||
let err = ParseError { msg: format!("Not yet implemented") };
|
||||
(Err(err), vec![])
|
||||
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") };
|
||||
(Err(err), vec![])
|
||||
}
|
||||
}
|
||||
|
||||
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) => {
|
||||
if options.debug_parse {
|
||||
output.add_artifact(TraceArtifact::new_parse_trace(trace));
|
||||
|
Loading…
Reference in New Issue
Block a user