feat: generate unified AST and editor contracts from ASDL
Verify databases and deploy Aster VM / verify-and-deploy (push) Successful in 7m55s

This commit is contained in:
2026-10-19 14:31:28 +08:00
parent be4f1add58
commit f5268d2e09
40 changed files with 2517 additions and 172 deletions
+27 -6
View File
@@ -42,9 +42,28 @@ peg::parser! {
= [Token { kind: TokenKind::Slash, .. }]
pub rule program() -> Program
= functions:function()+ {
let span = functions[0].span.through(functions.last().unwrap().span);
Program { functions, span }
= declarations:declaration()+ {
let span = declarations[0].span.through(declarations.last().unwrap().span);
Program { declarations, span }
}
rule declaration() -> Decl
= function:function() {
Decl { span: function.span, kind: DeclKind::Function(function) }
}
pub rule interactive() -> InteractiveInput
= statement:interactive_statement() {
InteractiveInput { span: statement.span, statements: vec![statement] }
}
rule interactive_statement() -> Stmt
= declaration:declaration() {
Stmt { span: declaration.span, kind: StmtKind::Declaration(declaration) }
}
/ binding:binding() { binding_statement(binding) }
/ expression:expression() {
Stmt { span: expression.span, kind: StmtKind::Expression(expression) }
}
rule function() -> Function
@@ -60,7 +79,9 @@ peg::parser! {
rule block() -> Block
= start:lbrace() bindings:binding()* returned:return_statement() end:rbrace() {
Block { bindings, result: returned.0, return_span: returned.1, span: start.through(end) }
let mut statements: Vec<Stmt> = bindings.into_iter().map(binding_statement).collect();
statements.push(returned);
Block { statements, span: start.through(end) }
}
rule binding() -> Binding
@@ -68,10 +89,10 @@ peg::parser! {
Binding { span: start.through(value.span), name, value }
}
rule return_statement() -> (Expr, Span)
rule return_statement() -> Stmt
= start:return_keyword() value:expression() {
let span = start.through(value.span);
(value, span)
Stmt { span, kind: StmtKind::Return(ReturnStatement { value: Some(value), span }) }
}
pub rule expression() -> Expr = precedence! {