diff --git a/src/schala_lang/autoparser.rs b/src/schala_lang/autoparser.rs index 8816178..3a685b2 100644 --- a/src/schala_lang/autoparser.rs +++ b/src/schala_lang/autoparser.rs @@ -2,6 +2,14 @@ use schala_lib::{ProgrammingLanguageInterface, EvalOptions, TraceArtifact, Langu use itertools::Itertools; 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![]) +} + pub struct Schala { } @@ -27,8 +35,30 @@ impl ProgrammingLanguageInterface for Schala { let token_string = tokens.iter().map(|t| format!("{:?}", t.token_type, t.offset.0, t.offset.1)).join(", "); output.add_artifact(TraceArtifact::new("tokens", format!("{:?}", token_string))); } + { + let token_errors: Vec<&String> = tokens.iter().filter_map(|t| t.get_error()).collect(); + if token_errors.len() != 0 { + output.add_output(format!("Tokenization error: {:?}\n", token_errors)); + return output; + } + } + + let ast = match auto_parse(tokens) { + (Ok(ast), trace) => { + if options.debug_parse { + output.add_artifact(TraceArtifact::new_parse_trace(trace)); + output.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast))); + } + ast + }, + (Err(err), trace) => { + output.add_artifact(TraceArtifact::new_parse_trace(trace)); + output.add_output(format!("Parse error: {:?}\n", err.msg)); + return output; + } + }; - output.add_output(format!("{:?}", tokens)); + output.add_output(format!("{:?}", ast)); output } }