From c1698d9b25de6da404320cfd3e0da815b4b8edc9 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 18 Apr 2022 22:01:35 +0200 Subject: [PATCH] Renamed init function in parser --- ablescript/src/interpret.rs | 4 ++-- ablescript/src/parser.rs | 20 ++++++++++---------- ablescript_cli/src/main.rs | 2 +- ablescript_cli/src/repl.rs | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index 52e8894..5fe34c3 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -453,7 +453,7 @@ impl ExecEnv { }); } - let stmts = crate::parser::Parser::new(&code).init()?; + let stmts = crate::parser::Parser::new(&code).parse()?; self.eval_stmts(&stmts)?; } } @@ -697,7 +697,7 @@ mod tests { // We can assume there won't be any syntax errors in the // interpreter tests. - let ast = parser.init().unwrap(); + let ast = parser.parse().unwrap(); env.eval_stmts(&ast).map(|()| Value::Nul) } diff --git a/ablescript/src/parser.rs b/ablescript/src/parser.rs index 5fbcb80..6df7ed5 100644 --- a/ablescript/src/parser.rs +++ b/ablescript/src/parser.rs @@ -27,7 +27,7 @@ impl<'source> Parser<'source> { /// Start parsing tokens /// /// Loops trough lexer, parses statements, returns AST - pub fn init(&mut self) -> Result { + pub fn parse(&mut self) -> Result { let mut ast = vec![]; while let Some(token) = self.lexer.next() { match token { @@ -36,7 +36,7 @@ impl<'source> Parser<'source> { // T-Dark block (replace `lang` with `script`) Token::TDark => ast.extend(self.tdark_flow()?), - token => ast.push(self.parse(token)?), + token => ast.push(self.parse_stmt(token)?), } } Ok(ast) @@ -62,7 +62,7 @@ impl<'source> Parser<'source> { /// /// This function will route to corresponding flow functions /// which may advance the lexer iterator - fn parse(&mut self, token: Token) -> Result, Error> { + fn parse_stmt(&mut self, token: Token) -> Result, Error> { let start = self.lexer.span().start; match token { @@ -349,7 +349,7 @@ impl<'source> Parser<'source> { match self.checked_next()? { Token::RightCurly => break, Token::TDark => block.extend(self.tdark_flow()?), - t => block.push(self.parse(t)?), + t => block.push(self.parse_stmt(t)?), } } Ok(block) @@ -650,7 +650,7 @@ mod tests { span: 0..24, }]; - let ast = Parser::new(code).init().unwrap(); + let ast = Parser::new(code).parse().unwrap(); assert_eq!(ast, expected); } @@ -671,7 +671,7 @@ mod tests { span: 0..11, }]; - let ast = Parser::new(code).init().unwrap(); + let ast = Parser::new(code).parse().unwrap(); assert_eq!(ast, expected); } @@ -705,7 +705,7 @@ mod tests { span: 0..56, }]; - let ast = Parser::new(code).init().unwrap(); + let ast = Parser::new(code).parse().unwrap(); assert_eq!(ast, expected); } @@ -736,7 +736,7 @@ mod tests { span: 9..34, }]; - let ast = Parser::new(code).init().unwrap(); + let ast = Parser::new(code).parse().unwrap(); assert_eq!(ast, expected); } @@ -782,7 +782,7 @@ mod tests { span: 0..39, }]; - let ast = Parser::new(code).init().unwrap(); + let ast = Parser::new(code).parse().unwrap(); assert_eq!(ast, expected); } @@ -815,7 +815,7 @@ mod tests { span: 0..41, }]; - let ast = Parser::new(code).init().unwrap(); + let ast = Parser::new(code).parse().unwrap(); assert_eq!(ast, expected); } } diff --git a/ablescript_cli/src/main.rs b/ablescript_cli/src/main.rs index 70b6e51..af9c71a 100644 --- a/ablescript_cli/src/main.rs +++ b/ablescript_cli/src/main.rs @@ -43,7 +43,7 @@ fn main() { // Parse & evaluate let mut parser = Parser::new(&source); - if let Err(e) = parser.init().and_then(|ast| { + if let Err(e) = parser.parse().and_then(|ast| { if ast_print { println!("{:#?}", ast); } diff --git a/ablescript_cli/src/repl.rs b/ablescript_cli/src/repl.rs index 32f5d8a..75bd3ef 100644 --- a/ablescript_cli/src/repl.rs +++ b/ablescript_cli/src/repl.rs @@ -21,7 +21,7 @@ pub fn repl(ast_print: bool) { None => readline.to_owned(), }; - partial = match Parser::new(&partial_data).init().and_then(|ast| { + partial = match Parser::new(&partial_data).parse().and_then(|ast| { if ast_print { println!("{:#?}", &ast); }