schala/schala-lang/language/src/ast/visitor.rs

44 lines
2.3 KiB
Rust
Raw Normal View History

2019-09-26 02:29:20 -07:00
use std::rc::Rc;
2019-09-25 18:41:07 -07:00
use std::error::Error;
use crate::ast::*;
2019-09-26 02:29:20 -07:00
use crate::ast::walker;
2019-09-25 18:41:07 -07:00
2019-09-26 02:29:20 -07:00
//TODO maybe these functions should take closures that return a KeepRecursing | StopHere type,
//or a tuple of (T, <that type>)
2019-09-25 18:41:07 -07:00
2019-09-26 02:29:20 -07:00
//TODO default implmentations should call walk methods - then I can test printing
pub trait ASTVisitor: Sized {
2019-09-28 01:58:22 -07:00
fn ast(&mut self, ast: &AST) {}
fn block(&mut self, statements: &Vec<Statement>) {}
fn statement(&mut self, statement: &Statement) {}
2019-09-28 01:58:22 -07:00
fn declaration(&mut self, declaration: &Declaration) {}
fn signature(&mut self, signature: &Signature) {}
fn type_declaration(&mut self, name: &TypeSingletonName, body: &TypeBody, mutable: bool) {}
fn type_alias(&mut self, old_name: &Rc<String>, new_name: &Rc<String>) {}
fn binding(&mut self, name: &Rc<String>, constant: bool, type_anno: Option<&TypeIdentifier>, expr: &Expression) {}
fn implemention(&mut self, type_name: &TypeIdentifier, interface_name: Option<&TypeSingletonName>, block: &Vec<Declaration>) {}
fn interface(&mut self, name: &Rc<String>, signatures: &Vec<Signature>) {}
fn expression(&mut self, expression: &Expression) {}
fn expression_kind(&mut self, kind: &ExpressionKind) {}
fn type_annotation(&mut self, type_anno: Option<&TypeIdentifier>) {}
fn named_struct(&mut self, name: &QualifiedName, fields: &Vec<(Rc<String>, Expression)>) {}
fn call(&mut self, f: &Expression, arguments: &Vec<InvocationArgument>) {}
fn index(&mut self, indexee: &Expression, indexers: &Vec<Expression>) {}
fn if_expression(&mut self, discrim: &Discriminator, body: &IfExpressionBody) {}
fn while_expression(&mut self, condition: Option<&Expression>, body: &Block) {}
fn for_expression(&mut self, enumerators: &Vec<Enumerator>, body: &ForBody) {}
fn lambda(&mut self, params: &Vec<FormalParam>, type_anno: Option<&TypeIdentifier>, body: &Block) {}
fn invocation_argument(&mut self, arg: &InvocationArgument) {}
fn formal_param(&mut self, param: &FormalParam) {}
2019-09-26 03:26:14 -07:00
fn import(&mut self, import: &ImportSpecifier) {}
fn qualified_name(&mut self, name: &QualifiedName) {}
2019-09-26 02:29:20 -07:00
fn nat_literal(&mut self, n: u64) {}
fn float_literal(&mut self, f: f64) {}
fn string_literal(&mut self, s: &Rc<String>) {}
fn bool_literal(&mut self, b: bool) {}
2019-09-28 01:58:22 -07:00
fn binexp(&mut self, op: &BinOp, lhs: &Expression, rhs: &Expression) {}
fn prefix_exp(&mut self, op: &PrefixOp, arg: &Expression) {}
2019-09-25 18:41:07 -07:00
}
2019-09-26 02:29:20 -07:00