From 697a3714e705893a150cf8671428cb7e86494309 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sat, 7 Feb 2026 00:28:44 +0100 Subject: [PATCH 1/8] feat: added math op tokens --- lexer/src/lexer.rs | 4 ++++ lexer/src/token.rs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lexer/src/lexer.rs b/lexer/src/lexer.rs index 5b49cd6..37ad6fb 100644 --- a/lexer/src/lexer.rs +++ b/lexer/src/lexer.rs @@ -93,6 +93,10 @@ pub fn lexer_parse_file(file_path: &String) -> LexerParseResult> '&' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::AMPERSAND)), '<' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::ANGEL_BRACKET_OPEN)), '>' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::ANGEL_BRACKET_CLOSE)), + '+' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::MATH_ADD)), + '-' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::MATH_SUBTRACT)), + '*' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::MATH_MULTIPLY)), + '/' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::MATH_DIVIDE)), _ => continue } diff --git a/lexer/src/token.rs b/lexer/src/token.rs index 148eb69..5bfff84 100644 --- a/lexer/src/token.rs +++ b/lexer/src/token.rs @@ -19,6 +19,12 @@ pub enum LexerTokenType { LAYOUT, LAY, + MATH_ADD, + MATH_SUBTRACT, + MATH_DIVIDE, + MATH_MULTIPLY, + + /// Represent the ret keyword RETURN, From 346cf421143b16c9fbc39f84d9cfacbe1afc2904 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sat, 7 Feb 2026 00:35:09 +0100 Subject: [PATCH 2/8] feat: added MathResult ASTTreeNoode & added MathOperation (conversion from token -> operator) --- parser/src/ast/math.rs | 23 +++++++++++++++++++++++ parser/src/ast/mod.rs | 1 + parser/src/ast/tree.rs | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 parser/src/ast/math.rs diff --git a/parser/src/ast/math.rs b/parser/src/ast/math.rs new file mode 100644 index 0000000..29f1889 --- /dev/null +++ b/parser/src/ast/math.rs @@ -0,0 +1,23 @@ +use commons::err::PositionedResult; +use lexer::token::{LexerToken, LexerTokenType}; + +/// The different operators +#[derive(Debug, PartialEq, Clone)] +pub enum MathOperator { + ADD, + SUBSTRACT, + MULTIPLY, + DIVIDE +} + +/// Obtains the operator from the token type +pub fn operator_from_token_type(token: LexerToken) -> PositionedResult { + match &token.tok_type { + LexerTokenType::MATH_ADD => return Ok(MathOperator::ADD), + LexerTokenType::MATH_SUBTRACT => return Ok(MathOperator::SUBSTRACT), + LexerTokenType::MATH_MULTIPLY => return Ok(MathOperator::MULTIPLY), + LexerTokenType::MATH_DIVIDE => return Ok(MathOperator::DIVIDE), + + _ => return Err(token.make_err("Expected math operator!")) + } +} \ No newline at end of file diff --git a/parser/src/ast/mod.rs b/parser/src/ast/mod.rs index b6041d1..0cf5a07 100644 --- a/parser/src/ast/mod.rs +++ b/parser/src/ast/mod.rs @@ -20,6 +20,7 @@ pub mod var; pub mod literals; pub mod cond; pub mod control; +pub mod math; pub fn parse_ast_value_post_l(tokens: &Vec, ind: &mut usize, original: PositionedResult>) -> PositionedResult> { match &tokens[*ind].tok_type { diff --git a/parser/src/ast/tree.rs b/parser/src/ast/tree.rs index b23c121..81a37dd 100644 --- a/parser/src/ast/tree.rs +++ b/parser/src/ast/tree.rs @@ -4,7 +4,7 @@ use utils::hash::{TypeHash, WithHash}; -use crate::ast::cond::operators::ConditionOperator; +use crate::ast::{cond::operators::ConditionOperator, math::MathOperator}; #[derive(Debug, PartialEq, Clone)] pub struct FunctionDeclarationArgument { @@ -26,6 +26,8 @@ pub enum ASTTreeNode { OperatorBasedConditionMember { lval: Box, rval: Box, operator: ConditionOperator }, BooleanBasedConditionMember { val: Box, negate: bool }, + MathResult { lval: Box, rval: Box, operator: MathOperator }, + VariableReference(WithHash), VarDeclaration { varName: WithHash, varType: TypeHash, value: Option> }, From a8718cda793f5b0e8285f1a0a29a06f4f0e103b5 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sat, 7 Feb 2026 00:42:20 +0100 Subject: [PATCH 3/8] feat: made math operators a single type in the lexer --- lexer/src/lib.rs | 1 + lexer/src/token.rs | 9 ++++----- lexer/src/toks/math.rs | 10 ++++++++++ lexer/src/toks/mod.rs | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 lexer/src/toks/math.rs create mode 100644 lexer/src/toks/mod.rs diff --git a/lexer/src/lib.rs b/lexer/src/lib.rs index b5629cc..ffd87a9 100644 --- a/lexer/src/lib.rs +++ b/lexer/src/lib.rs @@ -7,6 +7,7 @@ use core::fmt; pub mod token; pub mod lexer; +pub mod toks; type LexerParseResult = std::result::Result; diff --git a/lexer/src/token.rs b/lexer/src/token.rs index 5bfff84..1460e26 100644 --- a/lexer/src/token.rs +++ b/lexer/src/token.rs @@ -6,7 +6,7 @@ use std::any::Any; use commons::{Position, err::{PositionedError, PositionedResult}}; -use crate::{LexerParseResult, LexerParsingError}; +use crate::{LexerParseResult, LexerParsingError, toks::math::MathOperator}; /// The token type for the lexer #[derive(PartialEq, Debug)] @@ -19,10 +19,9 @@ pub enum LexerTokenType { LAYOUT, LAY, - MATH_ADD, - MATH_SUBTRACT, - MATH_DIVIDE, - MATH_MULTIPLY, + /// 0: the operator + /// 1: does the operator affect the original variable! + MATH_OPERATOR(MathOperator, bool), /// Represent the ret keyword diff --git a/lexer/src/toks/math.rs b/lexer/src/toks/math.rs new file mode 100644 index 0000000..0621019 --- /dev/null +++ b/lexer/src/toks/math.rs @@ -0,0 +1,10 @@ +///! Maths token related utils + +/// The different operators +#[derive(Debug, PartialEq, Clone)] +pub enum MathOperator { + ADD, + SUBSTRACT, + MULTIPLY, + DIVIDE +} \ No newline at end of file diff --git a/lexer/src/toks/mod.rs b/lexer/src/toks/mod.rs new file mode 100644 index 0000000..354c7c9 --- /dev/null +++ b/lexer/src/toks/mod.rs @@ -0,0 +1 @@ +pub mod math; \ No newline at end of file From f24e630a8034c797ad4b3b4da7bd071e2cc0e183 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sat, 7 Feb 2026 00:50:18 +0100 Subject: [PATCH 4/8] feat: added lexer tok parsing --- lexer/src/lexer.rs | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/lexer/src/lexer.rs b/lexer/src/lexer.rs index 37ad6fb..55bb041 100644 --- a/lexer/src/lexer.rs +++ b/lexer/src/lexer.rs @@ -6,7 +6,7 @@ use std::{fs, hash::{DefaultHasher, Hash, Hasher}, io::Error}; use commons::Position; -use crate::{LexerParseResult, LexerParsingError, token::LexerToken, token::LexerTokenType}; +use crate::{LexerParseResult, LexerParsingError, token::{LexerToken, LexerTokenType}, toks::math::MathOperator}; const FUNC_KEYWORD_HASH: u64 = 17439195341824537259; const RET_KEYWORD_HASH: u64 = 9222097151127739705; @@ -93,10 +93,7 @@ pub fn lexer_parse_file(file_path: &String) -> LexerParseResult> '&' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::AMPERSAND)), '<' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::ANGEL_BRACKET_OPEN)), '>' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::ANGEL_BRACKET_CLOSE)), - '+' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::MATH_ADD)), - '-' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::MATH_SUBTRACT)), - '*' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::MATH_MULTIPLY)), - '/' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::MATH_DIVIDE)), + '+' | '-' | '*' | '/' => tokens.push(parse_math_operator(&contents, &mut i, pos)?), _ => continue } @@ -107,6 +104,36 @@ pub fn lexer_parse_file(file_path: &String) -> LexerParseResult> Ok(tokens) } +fn parse_math_operator(contents: &String, ind: &mut usize, start_pos: Position) -> LexerParseResult { + let operatorChar = contents.chars().nth(*ind).unwrap(); + + let operator = match operatorChar { + '+' => MathOperator::ADD, + '-' => MathOperator::SUBSTRACT, + '*' => MathOperator::MULTIPLY, + '/' => MathOperator::DIVIDE, + _ => return Err(LexerParsingError::new(String::from("Invalid operator sign!"), 0)) + }; + + *ind += 1; + + let assigns = match contents.chars().nth(*ind + 1) { + Some(v) => v == '=', + None => false + }; + + let mut incrementCount = 1; + + if assigns { + incrementCount += 1; + } + + let end = start_pos.increment_by(incrementCount); + + return Ok(LexerToken::new(start_pos, end, LexerTokenType::MATH_OPERATOR(operator, assigns))); + +} + fn parse_number_token(str: &String, ind: &mut usize, start_pos: Position) -> LexerParseResult { let start = *ind + 1; let mut end: usize = start; From 2c769f863f641b8cb5494f587f667c641cebbc8d Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sat, 7 Feb 2026 00:50:44 +0100 Subject: [PATCH 5/8] chore: removed AST math mod --- parser/src/ast/math.rs | 23 ----------------------- parser/src/ast/mod.rs | 1 - 2 files changed, 24 deletions(-) delete mode 100644 parser/src/ast/math.rs diff --git a/parser/src/ast/math.rs b/parser/src/ast/math.rs deleted file mode 100644 index 29f1889..0000000 --- a/parser/src/ast/math.rs +++ /dev/null @@ -1,23 +0,0 @@ -use commons::err::PositionedResult; -use lexer::token::{LexerToken, LexerTokenType}; - -/// The different operators -#[derive(Debug, PartialEq, Clone)] -pub enum MathOperator { - ADD, - SUBSTRACT, - MULTIPLY, - DIVIDE -} - -/// Obtains the operator from the token type -pub fn operator_from_token_type(token: LexerToken) -> PositionedResult { - match &token.tok_type { - LexerTokenType::MATH_ADD => return Ok(MathOperator::ADD), - LexerTokenType::MATH_SUBTRACT => return Ok(MathOperator::SUBSTRACT), - LexerTokenType::MATH_MULTIPLY => return Ok(MathOperator::MULTIPLY), - LexerTokenType::MATH_DIVIDE => return Ok(MathOperator::DIVIDE), - - _ => return Err(token.make_err("Expected math operator!")) - } -} \ No newline at end of file diff --git a/parser/src/ast/mod.rs b/parser/src/ast/mod.rs index 0cf5a07..b6041d1 100644 --- a/parser/src/ast/mod.rs +++ b/parser/src/ast/mod.rs @@ -20,7 +20,6 @@ pub mod var; pub mod literals; pub mod cond; pub mod control; -pub mod math; pub fn parse_ast_value_post_l(tokens: &Vec, ind: &mut usize, original: PositionedResult>) -> PositionedResult> { match &tokens[*ind].tok_type { From f7378163d60b7f281fb11ea45c4df57c9877e938 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sat, 7 Feb 2026 01:01:10 +0100 Subject: [PATCH 6/8] feat: added math operator parsing in vals --- lexer/src/token.rs | 7 +++++++ parser/src/ast/math.rs | 18 ++++++++++++++++++ parser/src/ast/mod.rs | 10 +++++++++- parser/src/ast/tree.rs | 5 +++-- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 parser/src/ast/math.rs diff --git a/lexer/src/token.rs b/lexer/src/token.rs index 1460e26..1d7e27d 100644 --- a/lexer/src/token.rs +++ b/lexer/src/token.rs @@ -96,6 +96,13 @@ impl LexerToken { }; } + pub fn expects_math_operator(&self) -> PositionedResult<(MathOperator, bool)> { + match &self.tok_type { + LexerTokenType::MATH_OPERATOR(a, b) => return Ok((a.clone(), *b)), + _ => return Err(self.make_err("Expected math operator here!")) + }; + } + pub fn expects_string_lit(&self) -> PositionedResult { match &self.tok_type { LexerTokenType::STRING_LIT(v) => return Ok(v.to_string()), diff --git a/parser/src/ast/math.rs b/parser/src/ast/math.rs new file mode 100644 index 0000000..82aa244 --- /dev/null +++ b/parser/src/ast/math.rs @@ -0,0 +1,18 @@ +use commons::err::PositionedResult; +use lexer::token::LexerToken; + +use crate::ast::{parse_ast_value, tree::ASTTreeNode}; + +pub fn parse_math_operation(tokens: &Vec, ind: &mut usize, original: Box, restricts_to_assigns: bool) -> PositionedResult> { + let oper = tokens[*ind].expects_math_operator()?; + + if !oper.1 && restricts_to_assigns { + return Err(tokens[*ind].make_err("Using math operation without assigments is forbidden here!")); + } + + *ind += 1; + + let rightMember = parse_ast_value(tokens, ind)?; + + return Ok(Box::new(ASTTreeNode::MathResult { lval: original, rval: rightMember, operator: oper.0, assigns: oper.1 })) +} \ No newline at end of file diff --git a/parser/src/ast/mod.rs b/parser/src/ast/mod.rs index b6041d1..02288b8 100644 --- a/parser/src/ast/mod.rs +++ b/parser/src/ast/mod.rs @@ -12,7 +12,7 @@ use commons::err::PositionedResult; use lexer::token::{LexerToken, LexerTokenType}; use utils::hash::WithHash; -use crate::{ParserError, ParserResult, ast::{cond::operators::parse_condition_operator, control::{forloop::parse_for_loop, ifelse::parse_if_statement, whileblock::parse_while_block}, func::{call::parse_function_call, decl::parse_function_declaraction}, literals::{parse_integer_literal, parse_string_literal}, tree::ASTTreeNode, var::decl::parse_variable_declaration}}; +use crate::{ParserError, ParserResult, ast::{cond::operators::parse_condition_operator, control::{forloop::parse_for_loop, ifelse::parse_if_statement, whileblock::parse_while_block}, func::{call::parse_function_call, decl::parse_function_declaraction}, literals::{parse_integer_literal, parse_string_literal}, math::parse_math_operation, tree::ASTTreeNode, var::decl::parse_variable_declaration}}; pub mod tree; pub mod func; @@ -20,6 +20,7 @@ pub mod var; pub mod literals; pub mod cond; pub mod control; +pub mod math; pub fn parse_ast_value_post_l(tokens: &Vec, ind: &mut usize, original: PositionedResult>) -> PositionedResult> { match &tokens[*ind].tok_type { @@ -43,6 +44,13 @@ pub fn parse_ast_value_post_l(tokens: &Vec, ind: &mut usize, origina return Err(tokens[*ind].make_err("Invalid token type to use dot access!")); }, + LexerTokenType::MATH_OPERATOR(_, _) => { + let o = &original?; + let k = Box::new(ASTTreeNode::clone(o.as_ref())); + + return Ok(parse_math_operation(tokens, ind, k, false)?); + }, + LexerTokenType::ANGEL_BRACKET_CLOSE | LexerTokenType::EQUAL_SIGN | LexerTokenType::ANGEL_BRACKET_OPEN => { let operator = parse_condition_operator(tokens, ind)?; diff --git a/parser/src/ast/tree.rs b/parser/src/ast/tree.rs index 81a37dd..a05aef8 100644 --- a/parser/src/ast/tree.rs +++ b/parser/src/ast/tree.rs @@ -2,9 +2,10 @@ //! AST tree related definitions. //! +use lexer::toks::math::MathOperator; use utils::hash::{TypeHash, WithHash}; -use crate::ast::{cond::operators::ConditionOperator, math::MathOperator}; +use crate::ast::{cond::operators::ConditionOperator}; #[derive(Debug, PartialEq, Clone)] pub struct FunctionDeclarationArgument { @@ -26,7 +27,7 @@ pub enum ASTTreeNode { OperatorBasedConditionMember { lval: Box, rval: Box, operator: ConditionOperator }, BooleanBasedConditionMember { val: Box, negate: bool }, - MathResult { lval: Box, rval: Box, operator: MathOperator }, + MathResult { lval: Box, rval: Box, operator: MathOperator, assigns: bool }, VariableReference(WithHash), From f93a27e55d89205885b7e7148ff7b34db068fa6f Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sat, 7 Feb 2026 01:05:28 +0100 Subject: [PATCH 7/8] =?UTF-8?q?feat:=20added=20math=20operator=20parsing?= =?UTF-8?q?=20in=20func=20body=20(keyword=20only=C3=83)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parser/src/ast/mod.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/parser/src/ast/mod.rs b/parser/src/ast/mod.rs index 02288b8..3be3f13 100644 --- a/parser/src/ast/mod.rs +++ b/parser/src/ast/mod.rs @@ -130,11 +130,23 @@ pub fn parse_ast_node(tokens: &Vec, ind: &mut usize) -> PositionedRe LexerTokenType::FOR => { return parse_for_loop(tokens, ind); - } + }, + + LexerTokenType::KEYWORD(str, _) => { + if tokens[*ind + 1].tok_type == LexerTokenType::PAREN_OPEN { + let call = parse_function_call(tokens, ind); + return parse_ast_value_post_l(tokens, ind, call); + } + + let n = Ok(Box::new(ASTTreeNode::VariableReference(WithHash::new(String::clone(str))))); + + *ind += 1; + + return parse_ast_value_post_l(tokens, ind, n); + }, _ => { - return Err(tokens[*ind].make_err("Invalid token type! Shouldn't be there!")); + return Err(tokens[*ind].make_err("Expected valid token type in this context!")); } - } } \ No newline at end of file From 52ad6c15c7957609361595dccb69bbaa46adf8ed Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sat, 7 Feb 2026 01:26:40 +0100 Subject: [PATCH 8/8] push --- commons/src/err/mod.rs | 4 ++-- examples/math.qf | 5 +++++ lexer/src/lexer.rs | 17 ++++++++++++++--- parser/src/ast/mod.rs | 18 +++++++++--------- 4 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 examples/math.qf diff --git a/commons/src/err/mod.rs b/commons/src/err/mod.rs index 0cef6bd..0052d5d 100644 --- a/commons/src/err/mod.rs +++ b/commons/src/err/mod.rs @@ -39,8 +39,8 @@ impl fmt::Display for PositionedError { }; let before = &line[0..self.start.col - 1]; - let target = &line[self.start.col - 1..self.end.col].cyan().underline(); - let after = &line[self.end.col..]; + let target = &line[self.start.col - 1..self.end.col - 1].cyan().underline(); + let after = &line[self.end.col - 1..]; writeln!(f, "{}{}{}", before, target, after)?; writeln!(f, "")?; diff --git a/examples/math.qf b/examples/math.qf new file mode 100644 index 0000000..caf381a --- /dev/null +++ b/examples/math.qf @@ -0,0 +1,5 @@ +func test() { + var i32 e = !56 + + eee +} \ No newline at end of file diff --git a/lexer/src/lexer.rs b/lexer/src/lexer.rs index 55bb041..2bc997c 100644 --- a/lexer/src/lexer.rs +++ b/lexer/src/lexer.rs @@ -72,6 +72,14 @@ pub fn lexer_parse_file(file_path: &String) -> LexerParseResult> continue; } + if c == '+' || c == '-' || c == '*' || c == '/' { + let col = i - last_line_break + 1; + + tokens.push(parse_math_operator(&contents, &mut i, Position::new(file_path.to_string(), line, col))?); + + continue; + } + i += c.len_utf8(); @@ -93,8 +101,7 @@ pub fn lexer_parse_file(file_path: &String) -> LexerParseResult> '&' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::AMPERSAND)), '<' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::ANGEL_BRACKET_OPEN)), '>' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::ANGEL_BRACKET_CLOSE)), - '+' | '-' | '*' | '/' => tokens.push(parse_math_operator(&contents, &mut i, pos)?), - _ => continue + _ => continue } } @@ -117,11 +124,15 @@ fn parse_math_operator(contents: &String, ind: &mut usize, start_pos: Position) *ind += 1; - let assigns = match contents.chars().nth(*ind + 1) { + let assigns = match contents.chars().nth(*ind) { Some(v) => v == '=', None => false }; + if assigns { + *ind += 1; + } + let mut incrementCount = 1; if assigns { diff --git a/parser/src/ast/mod.rs b/parser/src/ast/mod.rs index 3be3f13..20bfadd 100644 --- a/parser/src/ast/mod.rs +++ b/parser/src/ast/mod.rs @@ -22,7 +22,7 @@ pub mod cond; pub mod control; pub mod math; -pub fn parse_ast_value_post_l(tokens: &Vec, ind: &mut usize, original: PositionedResult>) -> PositionedResult> { +pub fn parse_ast_value_post_l(tokens: &Vec, ind: &mut usize, original: PositionedResult>, invoked_on_body: bool) -> PositionedResult> { match &tokens[*ind].tok_type { LexerTokenType::DOT => { let o = &original?; @@ -48,7 +48,7 @@ pub fn parse_ast_value_post_l(tokens: &Vec, ind: &mut usize, origina let o = &original?; let k = Box::new(ASTTreeNode::clone(o.as_ref())); - return Ok(parse_math_operation(tokens, ind, k, false)?); + return Ok(parse_math_operation(tokens, ind, k, invoked_on_body)?); }, LexerTokenType::ANGEL_BRACKET_CLOSE | LexerTokenType::EQUAL_SIGN | LexerTokenType::ANGEL_BRACKET_OPEN => { @@ -83,28 +83,28 @@ pub fn parse_ast_value(tokens: &Vec, ind: &mut usize) -> PositionedR LexerTokenType::INT_LIT(_) => { let int = parse_integer_literal(tokens, ind); - return parse_ast_value_post_l(tokens, ind, int); + return parse_ast_value_post_l(tokens, ind, int, false); }, LexerTokenType::STRING_LIT(_) => { let str = parse_string_literal(tokens, ind); - return parse_ast_value_post_l(tokens, ind, str); + return parse_ast_value_post_l(tokens, ind, str, false); }, LexerTokenType::KEYWORD(str, _) => { if tokens[*ind + 1].tok_type == LexerTokenType::PAREN_OPEN { let call = parse_function_call(tokens, ind); - return parse_ast_value_post_l(tokens, ind, call); + return parse_ast_value_post_l(tokens, ind, call, false); } let n = Ok(Box::new(ASTTreeNode::VariableReference(WithHash::new(String::clone(str))))); *ind += 1; - return parse_ast_value_post_l(tokens, ind, n); + return parse_ast_value_post_l(tokens, ind, n, false); } - _ => return Err(tokens[*ind].make_err("Cannot be parsed as value!")) + _ => return Err(tokens[*ind].make_err("Invalid token to parse as a value!")) } } @@ -135,14 +135,14 @@ pub fn parse_ast_node(tokens: &Vec, ind: &mut usize) -> PositionedRe LexerTokenType::KEYWORD(str, _) => { if tokens[*ind + 1].tok_type == LexerTokenType::PAREN_OPEN { let call = parse_function_call(tokens, ind); - return parse_ast_value_post_l(tokens, ind, call); + return parse_ast_value_post_l(tokens, ind, call, true); } let n = Ok(Box::new(ASTTreeNode::VariableReference(WithHash::new(String::clone(str))))); *ind += 1; - return parse_ast_value_post_l(tokens, ind, n); + return parse_ast_value_post_l(tokens, ind, n, true); }, _ => {