Add token-based PEG frontend and CLI source parsing
Verify databases and deploy Aster VM / verify-and-deploy (push) Successful in 7m30s

This commit is contained in:
2026-10-19 02:48:23 +08:00
parent e24909a56e
commit 0b3a480555
36 changed files with 1146 additions and 33 deletions
+90
View File
@@ -0,0 +1,90 @@
use crate::Span;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Name {
pub text: String,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Program {
pub functions: Vec<Function>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Function {
pub name: Name,
pub parameters: Vec<Parameter>,
pub return_type: Name,
pub body: Block,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Parameter {
pub name: Name,
pub type_name: Name,
pub span: Span,
}
/// Basic draft function body: zero or more bindings and one final return.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Block {
pub bindings: Vec<Binding>,
pub result: Expr,
pub return_span: Span,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Binding {
pub name: Name,
pub value: Expr,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Expr {
pub kind: ExprKind,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ExprKind {
Name(String),
/// The decimal spelling is retained, without f64 conversion.
Number(String),
String(String),
Symbol(Name),
Unary {
operation: UnaryOp,
operand: Box<Expr>,
},
Binary {
operation: BinaryOp,
left: Box<Expr>,
right: Box<Expr>,
},
Member {
object: Box<Expr>,
name: Name,
},
Call {
callee: Box<Expr>,
arguments: Vec<Expr>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UnaryOp {
Negate,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BinaryOp {
Add,
Subtract,
Multiply,
Divide,
}