Skip to content

Commit

Permalink
fix(parser): add unary operators to both expressions and statements.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Mar 5, 2024
1 parent dac23a2 commit 1f3b7ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/fuse-parser/src/parsers/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ impl<'a> Parser<'a> {
.map(|id| self.ast.identifier_expression(id)),
TokenKind::Function | TokenKind::Fn => self.parse_function_expression(),
TokenKind::If => self.parse_if_expression(),

TokenKind::Not | TokenKind::Plus | TokenKind::Minus => {
self.parse_unary_operator_expression()
}

_ => Err(Self::unexpected_error(self.cur_token())),
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/fuse-parser/src/parsers/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl<'a> Parser<'a> {
.parse_expression()
.map(|expr| self.ast.expression_statement(expr)),

// Short circuit the unary operators to prevent extra checks.
TokenKind::Not | TokenKind::Plus | TokenKind::Minus => self
.parse_unary_operator_expression()
.map(|expr| self.ast.expression_statement(expr)),
Expand Down

0 comments on commit 1f3b7ef

Please sign in to comment.