This repository has been archived on 2026-03-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
bucky-old/src/ast.rs
2026-01-16 21:21:38 +01:00

124 lines
2.0 KiB
Rust

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,
}
#[derive(Debug, PartialEq, Eq)]
pub enum Statement {
Let {
name: Box<str>,
name_span: Span,
type_: Option<Type>,
value: Option<Expression>,
},
If {
kw_span: Span,
condition: Expression,
then: Box<Statement>,
elze: Option<Box<Statement>>,
},
Loop {
kw_span: Span,
body: Box<Statement>,
},
Break {
kw_span: Span,
},
Return {
kw_span: Span,
value: Option<Expression>,
},
Compound {
body: Vec<Statement>,
},
Expr(Expression),
}
#[derive(Debug, PartialEq, Eq)]
pub enum Type {
Integer { size: u8, signed: bool },
Boolean,
Named { name: Box<str>, name_span: Span },
}
#[derive(Debug, PartialEq, Eq)]
pub enum Declaration {
Function {
name: Box<str>,
name_span: Span,
parameters: Vec<Parameter>,
return_type: Option<Type>,
body: Option<Statement>,
},
}
#[derive(Debug, PartialEq, Eq)]
pub struct Parameter {
pub name: Box<str>,
pub name_span: Span,
pub type_: Type,
}