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
+30 -86
View File
@@ -1,90 +1,34 @@
use crate::Span;
//! AST types and walkers generated from the single Endor.asdl schema.
//! Runtime objects remain in the objects crate.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Name {
pub text: String,
pub span: Span,
mod generated;
pub mod visitor;
mod wire;
pub use generated::*;
pub use wire::AstError;
use crate::{SourceLocation, Span};
/// A syntax node's half-open byte range in its original UTF-8 source.
pub trait Spanned {
fn span(&self) -> Span;
fn source_text<'a>(&self, source: &'a str) -> Option<&'a str> {
self.span().slice(source)
}
fn location(&self, source: &str) -> Option<SourceLocation> {
self.span().location(source)
}
}
#[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,
impl Program {
/// Iterate the currently supported top-level function declarations.
pub fn functions(&self) -> impl Iterator<Item = &Function> {
self.declarations.iter().map(|declaration| {
let DeclKind::Function(function) = &declaration.kind;
function
})
}
}