feat: generate unified AST and editor contracts from ASDL
Verify databases and deploy Aster VM / verify-and-deploy (push) Successful in 7m55s
Verify databases and deploy Aster VM / verify-and-deploy (push) Successful in 7m55s
This commit is contained in:
@@ -0,0 +1,300 @@
|
||||
// Generated by scripts/generate_ast.py from Endor.asdl. Do not edit.
|
||||
|
||||
use super::{
|
||||
AstDocument, AstRoot, BinaryOp, Binding, Block, Decl, DeclKind, Expr, ExprKind, Function,
|
||||
InteractiveInput, Name, Parameter, Program, ReturnStatement, Spanned, Stmt, StmtKind, UnaryOp,
|
||||
};
|
||||
use crate::Span;
|
||||
pub trait Visitor {
|
||||
type Error;
|
||||
fn enter_node(&mut self, _span: Span) -> Result<(), Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
fn leave_node(&mut self) {}
|
||||
fn visit_span(&mut self, _span: &Span) -> Result<(), Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
fn visit_ast_document(&mut self, node: &AstDocument) -> Result<(), Self::Error> {
|
||||
walk_ast_document(self, node)
|
||||
}
|
||||
fn visit_ast_root(&mut self, node: &AstRoot) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_ast_root(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_name(&mut self, node: &Name) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_name(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_program(&mut self, node: &Program) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_program(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_decl(&mut self, node: &Decl) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_decl(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_decl_kind(&mut self, node: &DeclKind) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_decl_kind(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_function(&mut self, node: &Function) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_function(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_parameter(&mut self, node: &Parameter) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_parameter(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_block(&mut self, node: &Block) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_block(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_stmt(&mut self, node: &Stmt) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_stmt(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_stmt_kind(&mut self, node: &StmtKind) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_stmt_kind(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_binding(&mut self, node: &Binding) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_binding(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_return_statement(&mut self, node: &ReturnStatement) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_return_statement(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_interactive_input(&mut self, node: &InteractiveInput) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_interactive_input(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_expr(&mut self, node: &Expr) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_expr(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_expr_kind(&mut self, node: &ExprKind) -> Result<(), Self::Error> {
|
||||
walk_expr_kind(self, node)
|
||||
}
|
||||
fn visit_unary_op(&mut self, node: &UnaryOp) -> Result<(), Self::Error> {
|
||||
walk_unary_op(self, node)
|
||||
}
|
||||
fn visit_binary_op(&mut self, node: &BinaryOp) -> Result<(), Self::Error> {
|
||||
walk_binary_op(self, node)
|
||||
}
|
||||
}
|
||||
pub fn walk_ast_document<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &AstDocument,
|
||||
) -> Result<(), V::Error> {
|
||||
visitor.visit_ast_root(&node.root)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_ast_root<V: Visitor + ?Sized>(visitor: &mut V, node: &AstRoot) -> Result<(), V::Error> {
|
||||
match node {
|
||||
AstRoot::Module(value) => {
|
||||
visitor.visit_program(value)?;
|
||||
}
|
||||
AstRoot::Expression(value) => {
|
||||
visitor.visit_expr(value)?;
|
||||
}
|
||||
AstRoot::Interactive(value) => {
|
||||
visitor.visit_interactive_input(value)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_name<V: Visitor + ?Sized>(visitor: &mut V, node: &Name) -> Result<(), V::Error> {
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_program<V: Visitor + ?Sized>(visitor: &mut V, node: &Program) -> Result<(), V::Error> {
|
||||
for value in &node.declarations {
|
||||
visitor.visit_decl(value)?;
|
||||
}
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_decl<V: Visitor + ?Sized>(visitor: &mut V, node: &Decl) -> Result<(), V::Error> {
|
||||
visitor.visit_decl_kind(&node.kind)?;
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_decl_kind<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &DeclKind,
|
||||
) -> Result<(), V::Error> {
|
||||
match node {
|
||||
DeclKind::Function(value) => {
|
||||
visitor.visit_function(value)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_function<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &Function,
|
||||
) -> Result<(), V::Error> {
|
||||
visitor.visit_name(&node.name)?;
|
||||
for value in &node.parameters {
|
||||
visitor.visit_parameter(value)?;
|
||||
}
|
||||
visitor.visit_name(&node.return_type)?;
|
||||
visitor.visit_block(&node.body)?;
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_parameter<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &Parameter,
|
||||
) -> Result<(), V::Error> {
|
||||
visitor.visit_name(&node.name)?;
|
||||
visitor.visit_name(&node.type_name)?;
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_block<V: Visitor + ?Sized>(visitor: &mut V, node: &Block) -> Result<(), V::Error> {
|
||||
for value in &node.statements {
|
||||
visitor.visit_stmt(value)?;
|
||||
}
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_stmt<V: Visitor + ?Sized>(visitor: &mut V, node: &Stmt) -> Result<(), V::Error> {
|
||||
visitor.visit_stmt_kind(&node.kind)?;
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_stmt_kind<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &StmtKind,
|
||||
) -> Result<(), V::Error> {
|
||||
match node {
|
||||
StmtKind::Binding(value) => {
|
||||
visitor.visit_binding(value)?;
|
||||
}
|
||||
StmtKind::Return(value) => {
|
||||
visitor.visit_return_statement(value)?;
|
||||
}
|
||||
StmtKind::Expression(value) => {
|
||||
visitor.visit_expr(value)?;
|
||||
}
|
||||
StmtKind::Declaration(value) => {
|
||||
visitor.visit_decl(value)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_binding<V: Visitor + ?Sized>(visitor: &mut V, node: &Binding) -> Result<(), V::Error> {
|
||||
visitor.visit_name(&node.name)?;
|
||||
visitor.visit_expr(&node.value)?;
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_return_statement<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &ReturnStatement,
|
||||
) -> Result<(), V::Error> {
|
||||
if let Some(value) = &node.value {
|
||||
visitor.visit_expr(value)?;
|
||||
}
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_interactive_input<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &InteractiveInput,
|
||||
) -> Result<(), V::Error> {
|
||||
for value in &node.statements {
|
||||
visitor.visit_stmt(value)?;
|
||||
}
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_expr<V: Visitor + ?Sized>(visitor: &mut V, node: &Expr) -> Result<(), V::Error> {
|
||||
visitor.visit_expr_kind(&node.kind)?;
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_expr_kind<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &ExprKind,
|
||||
) -> Result<(), V::Error> {
|
||||
match node {
|
||||
ExprKind::Name(_) => {}
|
||||
ExprKind::Number(_) => {}
|
||||
ExprKind::String(_) => {}
|
||||
ExprKind::Symbol(value) => {
|
||||
visitor.visit_name(value)?;
|
||||
}
|
||||
ExprKind::Unary {
|
||||
operation, operand, ..
|
||||
} => {
|
||||
visitor.visit_unary_op(operation)?;
|
||||
visitor.visit_expr(operand)?;
|
||||
}
|
||||
ExprKind::Binary {
|
||||
operation,
|
||||
left,
|
||||
right,
|
||||
..
|
||||
} => {
|
||||
visitor.visit_binary_op(operation)?;
|
||||
visitor.visit_expr(left)?;
|
||||
visitor.visit_expr(right)?;
|
||||
}
|
||||
ExprKind::Member { object, name, .. } => {
|
||||
visitor.visit_expr(object)?;
|
||||
visitor.visit_name(name)?;
|
||||
}
|
||||
ExprKind::Call {
|
||||
callee, arguments, ..
|
||||
} => {
|
||||
visitor.visit_expr(callee)?;
|
||||
for value in arguments {
|
||||
visitor.visit_expr(value)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_unary_op<V: Visitor + ?Sized>(
|
||||
_visitor: &mut V,
|
||||
_node: &UnaryOp,
|
||||
) -> Result<(), V::Error> {
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_binary_op<V: Visitor + ?Sized>(
|
||||
_visitor: &mut V,
|
||||
_node: &BinaryOp,
|
||||
) -> Result<(), V::Error> {
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user