feat: Add Expression definition and parsing logic.
This commit is contained in:
60
src/ast.rs
Normal file
60
src/ast.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
use crate::token::Span;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct Expression {
|
||||
pub kind: ExpressionKind,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum ExpressionKind {
|
||||
Integer(u64),
|
||||
Boolean(bool),
|
||||
Identifier(Box<str>),
|
||||
|
||||
Unary {
|
||||
op: UnaryOp,
|
||||
op_span: Span,
|
||||
expr: Box<Expression>,
|
||||
},
|
||||
|
||||
Binary {
|
||||
op: BinaryOp,
|
||||
op_span: Span,
|
||||
left: Box<Expression>,
|
||||
right: Box<Expression>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum UnaryOp {
|
||||
LogicalNot,
|
||||
BitwiseNot,
|
||||
Negate,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum BinaryOp {
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide,
|
||||
Remainder,
|
||||
|
||||
BitwiseAnd,
|
||||
BitwiseOr,
|
||||
BitwiseXor,
|
||||
|
||||
LogicalAnd,
|
||||
LogicalOr,
|
||||
|
||||
Equal,
|
||||
Unequal,
|
||||
LessThan,
|
||||
LessThanOrEqual,
|
||||
GreaterThan,
|
||||
GreaterThanOrEqual,
|
||||
|
||||
Assign,
|
||||
Member,
|
||||
}
|
||||
Reference in New Issue
Block a user