feat: Add Expression definition and parsing logic.

This commit is contained in:
Jooris Hadeler
2026-01-12 16:47:52 +01:00
parent 0599a5fb98
commit 2170be5204
4 changed files with 269 additions and 15 deletions

60
src/ast.rs Normal file
View 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,
}