Skip to content

Commit

Permalink
feat(ast): add types to support unary operators.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Mar 5, 2024
1 parent ca31ea9 commit 926d767
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/fuse-ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ pub enum Expression {
BooleanLiteral(Box<BooleanLiteral>),
Identifier(Box<Identifier>),
Function(Box<Function>),
If(Box<If>)
If(Box<If>),
UnaryOperator(Box<UnaryOperator>),
}

#[serializable]
Expand Down Expand Up @@ -218,10 +219,24 @@ pub struct If {
pub r#else: Option<Else>,
}


#[serializable]
#[derive(Debug, PartialEq)]
pub enum Else {
If(Box<If>),
Block(Box<Block>),
}

#[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),
}
4 changes: 4 additions & 0 deletions crates/fuse-ast/src/ast_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

0 comments on commit 926d767

Please sign in to comment.