From d602902d7b96ad0c3f4d6f82ae8bba50848e29da Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Wed, 3 Aug 2022 20:50:07 +0100 Subject: [PATCH] parser: make Assign an InfixOp instead of expression type Closes #14 --- trunk_parser/src/ast.rs | 2 ++ trunk_parser/src/parser/mod.rs | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/trunk_parser/src/ast.rs b/trunk_parser/src/ast.rs index f558609..6411e66 100644 --- a/trunk_parser/src/ast.rs +++ b/trunk_parser/src/ast.rs @@ -320,6 +320,7 @@ pub enum InfixOp { NotIdentical, And, Or, + Assign, AddAssign, } @@ -341,6 +342,7 @@ impl From for InfixOp { TokenKind::BangDoubleEquals => Self::NotIdentical, TokenKind::BooleanAnd => Self::And, TokenKind::BooleanOr => Self::Or, + TokenKind::Equals => Self::Assign, TokenKind::PlusEquals => Self::AddAssign, _ => unreachable!() } diff --git a/trunk_parser/src/parser/mod.rs b/trunk_parser/src/parser/mod.rs index 0620b81..ebc1823 100644 --- a/trunk_parser/src/parser/mod.rs +++ b/trunk_parser/src/parser/mod.rs @@ -1202,10 +1202,6 @@ fn prefix(op: &TokenKind, rhs: Expression) -> Expression { } fn infix(lhs: Expression, op: TokenKind, rhs: Expression) -> Expression { - if op == TokenKind::Equals { - return Expression::Assign(Box::new(lhs), Box::new(rhs)); - } - Expression::Infix(Box::new(lhs), op.into(), Box::new(rhs)) } @@ -1350,11 +1346,12 @@ mod tests { #[test] fn array_index_assign() { assert_ast("