From 926d767ad55174e502032e19ea48c8abcedbd832 Mon Sep 17 00:00:00 2001 From: rzvxa Date: Tue, 5 Mar 2024 17:54:55 +0330 Subject: [PATCH] feat(ast): add types to support unary operators. --- crates/fuse-ast/src/ast.rs | 19 +++++++++++++++++-- crates/fuse-ast/src/ast_factory.rs | 4 ++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/fuse-ast/src/ast.rs b/crates/fuse-ast/src/ast.rs index 8798833..fa58b32 100644 --- a/crates/fuse-ast/src/ast.rs +++ b/crates/fuse-ast/src/ast.rs @@ -95,7 +95,8 @@ pub enum Expression { BooleanLiteral(Box), Identifier(Box), Function(Box), - If(Box) + If(Box), + UnaryOperator(Box), } #[serializable] @@ -218,10 +219,24 @@ pub struct If { pub r#else: Option, } - #[serializable] #[derive(Debug, PartialEq)] pub enum Else { If(Box), Block(Box), } + +#[serializable] +#[derive(Debug, PartialEq)] +pub struct UnaryOperator { + pub kind: UnaryOperatorKind, + pub expression: Expression, +} + +#[serializable] +#[derive(Debug, PartialEq)] +pub enum UnaryOperatorKind { + Not(Span), + Minus(Span), + Plus(Span), +} diff --git a/crates/fuse-ast/src/ast_factory.rs b/crates/fuse-ast/src/ast_factory.rs index 7120106..50ff4c7 100644 --- a/crates/fuse-ast/src/ast_factory.rs +++ b/crates/fuse-ast/src/ast_factory.rs @@ -121,4 +121,8 @@ impl AstFactory { pub fn if_expression(&self, expr: If) -> Expression { Expression::If(Box::from(expr)) } + + pub fn unary_operator_expression(&self, op: UnaryOperator) -> Expression { + Expression::UnaryOperator(Box::from(op)) + } }