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
+37 -1
View File
@@ -1,9 +1,38 @@
use crate::ast::{
BinaryOp, Binding, Block, Expr, ExprKind, Function, Name, Parameter, Program, UnaryOp,
AstRoot, BinaryOp, Binding, Block, Decl, DeclKind, Expr, ExprKind, Function, InteractiveInput,
Name, Parameter, Program, ReturnStatement, Stmt, StmtKind, UnaryOp,
};
use crate::lexer::decode_string;
use crate::{Diagnostic, DiagnosticKind, Span, Token, TokenKind, lex};
/// Select the syntax root without implying any execution or REPL session.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParseMode {
Module,
Expression,
Interactive,
}
pub fn parse_ast(source: &str, mode: ParseMode) -> Result<AstRoot, Diagnostic> {
match mode {
ParseMode::Module => parse(source).map(AstRoot::Module),
ParseMode::Expression => parse_expression(source).map(AstRoot::Expression),
ParseMode::Interactive => {
let tokens = lex(source)?;
syntax::interactive(&tokens, source)
.map(AstRoot::Interactive)
.map_err(|error| diagnostic(error, &tokens, source.len()))
}
}
}
pub fn parse_source_ast(
source: &crate::SourceUnit,
mode: ParseMode,
) -> Result<AstRoot, crate::SourceDiagnostic> {
parse_ast(source.text(), mode).map_err(|error| source.annotate(error))
}
/// Parse a reader snapshot, retaining its origin and resolved revision on error.
pub fn parse_source(source: &crate::SourceUnit) -> Result<Program, crate::SourceDiagnostic> {
parse(source.text()).map_err(|error| source.annotate(error))
@@ -41,6 +70,13 @@ fn diagnostic(error: peg::error::ParseError<usize>, tokens: &[Token], end: usize
}
}
fn binding_statement(binding: Binding) -> Stmt {
Stmt {
span: binding.span,
kind: StmtKind::Binding(binding),
}
}
fn binary(left: Expr, operation: BinaryOp, right: Expr) -> Expr {
Expr {
span: left.span.through(right.span),