From c26c4a14bbb40d06e3cdae34200cfa7904102c9e Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 29 Apr 2021 19:19:35 +0200 Subject: [PATCH] Tidy up --- able-script-test/parse_test.able | 2 +- src/parser/item.rs | 6 ++++++ src/parser/ops.rs | 10 ++++------ src/parser/utils.rs | 2 ++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/able-script-test/parse_test.able b/able-script-test/parse_test.able index 4848030..4ac0e3e 100644 --- a/able-script-test/parse_test.able +++ b/able-script-test/parse_test.able @@ -1 +1 @@ -a(3,) \ No newline at end of file +1 + 4 \ No newline at end of file diff --git a/src/parser/item.rs b/src/parser/item.rs index eabea92..34d0b48 100644 --- a/src/parser/item.rs +++ b/src/parser/item.rs @@ -35,6 +35,12 @@ pub enum Expr { iden: Iden, args: Vec, }, + + Addition { + left: Box, + right: Box, + }, + Literal(Value), Identifier(Iden), Melo(Iden), diff --git a/src/parser/ops.rs b/src/parser/ops.rs index 0e8bb5d..04ebde3 100644 --- a/src/parser/ops.rs +++ b/src/parser/ops.rs @@ -1,8 +1,7 @@ -use std::collections::HashMap; - use super::*; impl<'a> Parser<'a> { + /// Parse operations (got identifier/value) pub(super) fn parse_ops(&mut self, token: Token) -> Result { let iden = if let Token::Identifier(i) = token { Iden(i) @@ -20,9 +19,11 @@ impl<'a> Parser<'a> { Ok(buf[0].clone()) } + /// Parse function call fn fn_call(&mut self, iden: Iden) -> Result { self.lexer.next(); let mut args: Vec = Vec::new(); + while let Some(token) = self.lexer.peek() { match token { Token::Identifier(id) => { @@ -38,9 +39,6 @@ impl<'a> Parser<'a> { self.require(Token::Comma)?; } self.require(Token::RightParenthesis)?; - Ok(Expr::FunctionCall { - iden, - args, - }) + Ok(Expr::FunctionCall { iden, args }) } } diff --git a/src/parser/utils.rs b/src/parser/utils.rs index eddfbea..2b83f1a 100644 --- a/src/parser/utils.rs +++ b/src/parser/utils.rs @@ -30,6 +30,7 @@ impl<'a> Parser<'a> { } } + /// Require an identifier on next and return it pub(super) fn require_iden(&mut self) -> Result { if let Some(Token::Identifier(id)) = self.lexer.next() { Ok(id) @@ -41,6 +42,7 @@ impl<'a> Parser<'a> { } } + /// Throw unexpected token error (optionally what was expected) pub(super) fn unexpected_token(&mut self, expected: Option) -> Error { let error_msg = match expected { Some(s) => format!(