feat: add managed types, source classes and scoped native calls
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
use super::Spanned;
|
||||
use crate::Span;
|
||||
pub const AST_SCHEMA_ID: &str =
|
||||
"urn:endor:ast:sha256:8c89fde6c029357a0809751c41cb46d59972b987bbe1b25c0cced4bfcdbe2a7b";
|
||||
"urn:endor:ast:sha256:ad2ac52943dd26e08395c0d2698861da98bb89c360241c4712c769de86709fd0";
|
||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct AstDocument {
|
||||
@@ -63,16 +63,32 @@ impl Spanned for Decl {
|
||||
#[serde(tag = "kind", content = "data", deny_unknown_fields)]
|
||||
pub enum DeclKind {
|
||||
Function(Function),
|
||||
Class(Class),
|
||||
}
|
||||
impl Spanned for DeclKind {
|
||||
fn span(&self) -> Span {
|
||||
match self {
|
||||
Self::Function(node) => node.span(),
|
||||
Self::Class(node) => node.span(),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Class {
|
||||
pub name: Name,
|
||||
pub base: Option<Name>,
|
||||
pub fields: Vec<Parameter>,
|
||||
pub methods: Vec<Function>,
|
||||
pub span: Span,
|
||||
}
|
||||
impl Spanned for Class {
|
||||
fn span(&self) -> Span {
|
||||
self.span
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Function {
|
||||
pub name: Name,
|
||||
pub parameters: Vec<Parameter>,
|
||||
@@ -124,6 +140,7 @@ impl Spanned for Stmt {
|
||||
pub enum StmtKind {
|
||||
Binding(Binding),
|
||||
Assignment(Assignment),
|
||||
MemberAssignment(MemberAssignment),
|
||||
Return(ReturnStatement),
|
||||
Expression(Expr),
|
||||
Declaration(Decl),
|
||||
@@ -133,6 +150,7 @@ impl Spanned for StmtKind {
|
||||
match self {
|
||||
Self::Binding(node) => node.span(),
|
||||
Self::Assignment(node) => node.span(),
|
||||
Self::MemberAssignment(node) => node.span(),
|
||||
Self::Return(node) => node.span(),
|
||||
Self::Expression(node) => node.span(),
|
||||
Self::Declaration(node) => node.span(),
|
||||
@@ -165,6 +183,19 @@ impl Spanned for Assignment {
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct MemberAssignment {
|
||||
pub object: Expr,
|
||||
pub name: Name,
|
||||
pub value: Expr,
|
||||
pub span: Span,
|
||||
}
|
||||
impl Spanned for MemberAssignment {
|
||||
fn span(&self) -> Span {
|
||||
self.span
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ReturnStatement {
|
||||
pub value: Option<Expr>,
|
||||
pub span: Span,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// Generated by scripts/generate_ast.py from Endor.asdl. Do not edit.
|
||||
|
||||
use super::{
|
||||
Assignment, AstDocument, AstRoot, BinaryOp, Binding, Block, Decl, DeclKind, Expr, ExprKind,
|
||||
Function, InteractiveInput, Name, Parameter, Program, ReturnStatement, Spanned, Stmt, StmtKind,
|
||||
UnaryOp,
|
||||
Assignment, AstDocument, AstRoot, BinaryOp, Binding, Block, Class, Decl, DeclKind, Expr,
|
||||
ExprKind, Function, InteractiveInput, MemberAssignment, Name, Parameter, Program,
|
||||
ReturnStatement, Spanned, Stmt, StmtKind, UnaryOp,
|
||||
};
|
||||
use crate::Span;
|
||||
pub trait Visitor {
|
||||
@@ -48,6 +48,12 @@ pub trait Visitor {
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_class(&mut self, node: &Class) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_class(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);
|
||||
@@ -90,6 +96,12 @@ pub trait Visitor {
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_member_assignment(&mut self, node: &MemberAssignment) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_member_assignment(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);
|
||||
@@ -163,9 +175,26 @@ pub fn walk_decl_kind<V: Visitor + ?Sized>(
|
||||
DeclKind::Function(value) => {
|
||||
visitor.visit_function(value)?;
|
||||
}
|
||||
DeclKind::Class(value) => {
|
||||
visitor.visit_class(value)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_class<V: Visitor + ?Sized>(visitor: &mut V, node: &Class) -> Result<(), V::Error> {
|
||||
visitor.visit_name(&node.name)?;
|
||||
if let Some(value) = &node.base {
|
||||
visitor.visit_name(value)?;
|
||||
}
|
||||
for value in &node.fields {
|
||||
visitor.visit_parameter(value)?;
|
||||
}
|
||||
for value in &node.methods {
|
||||
visitor.visit_function(value)?;
|
||||
}
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_function<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &Function,
|
||||
@@ -211,6 +240,9 @@ pub fn walk_stmt_kind<V: Visitor + ?Sized>(
|
||||
StmtKind::Assignment(value) => {
|
||||
visitor.visit_assignment(value)?;
|
||||
}
|
||||
StmtKind::MemberAssignment(value) => {
|
||||
visitor.visit_member_assignment(value)?;
|
||||
}
|
||||
StmtKind::Return(value) => {
|
||||
visitor.visit_return_statement(value)?;
|
||||
}
|
||||
@@ -238,6 +270,16 @@ pub fn walk_assignment<V: Visitor + ?Sized>(
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_member_assignment<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &MemberAssignment,
|
||||
) -> Result<(), V::Error> {
|
||||
visitor.visit_expr(&node.object)?;
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user