From d7baf065fb88f383136c5cf59fade52a1bdbd1ca Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 20 Oct 2018 15:41:09 -0700 Subject: [PATCH] Changing what method to call to start parsing --- schala-lang/language/src/eval.rs | 2 +- schala-lang/language/src/lib.rs | 2 +- schala-lang/language/src/parsing.rs | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/schala-lang/language/src/eval.rs b/schala-lang/language/src/eval.rs index 3d5c6fe..735be43 100644 --- a/schala-lang/language/src/eval.rs +++ b/schala-lang/language/src/eval.rs @@ -445,7 +445,7 @@ mod eval_tests { fn parse(tokens: Vec) -> ParseResult { let mut parser = ::parsing::Parser::new(tokens); - parser.program() + parser.parse() } macro_rules! all_output { diff --git a/schala-lang/language/src/lib.rs b/schala-lang/language/src/lib.rs index 480da11..12632f0 100644 --- a/schala-lang/language/src/lib.rs +++ b/schala-lang/language/src/lib.rs @@ -102,7 +102,7 @@ fn parsing(handle: &mut Schala, input: Vec, comp: Option<&mut Some(parser) => parser }; - let ast = parser.program(); + let ast = parser.parse(); let trace = parser.format_parse_trace(); comp.map(|comp| { diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index 33b1a7a..78ae9ad 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -46,9 +46,9 @@ struct ParserRestrictions { } impl Parser { - pub fn new(input: Vec) -> Parser { + pub fn new(initial_input: Vec) -> Parser { Parser { - tokens: input.into_iter().peekable(), + tokens: initial_input.into_iter().peekable(), parse_record: vec![], parse_level: 0, restrictions: ParserRestrictions { no_struct_literal: false } @@ -65,6 +65,16 @@ impl Parser { self.tokens.next().map(|ref t| { t.token_type.clone() }).unwrap_or(TokenType::EOF) } + pub fn parse(&mut self) -> ParseResult { + self.program() + } + + /* + pub fn parse_with_new_tokens(&mut self, new_tokens: Vec) -> ParseResult { + + } + */ + pub fn format_parse_trace(self) -> Vec { self.parse_record.into_iter().map(|r| { let mut indent = String::new(); @@ -252,7 +262,7 @@ enumerator := identifier '<-' expression | identifier '=' expression //TODO add impl Parser { //TODO make this a proper public interface #[recursive_descent_method] - pub fn program(&mut self) -> ParseResult { + fn program(&mut self) -> ParseResult { let mut statements = Vec::new(); loop { match self.peek() { @@ -1063,7 +1073,7 @@ mod parse_tests { fn parse(tokens: Vec<::tokenizing::Token>) -> ParseResult { let mut parser = super::Parser::new(tokens); - parser.program() + parser.parse() } macro_rules! rc {