More visitor stuff
This commit is contained in:
parent
d80a0036b1
commit
c8804eeefb
2
TODO.md
2
TODO.md
@ -7,7 +7,7 @@
|
||||
- standardize on an error type that isn't String
|
||||
-implement a visitor pattern for the use of scope_resolver
|
||||
- maybe implement this twice: 1) the value-returning, no-default one in the haoyi blogpost,
|
||||
2) the non-value-returning, default one like in rustc
|
||||
2) the non-value-returning, default one like in rustc (cf. https://github.com/rust-unofficial/patterns/blob/master/patterns/visitor.md)
|
||||
|
||||
## Reduction
|
||||
- make a good type for actual language builtins to avoid string comparisons
|
||||
|
@ -48,9 +48,15 @@ pub trait ASTVisitor: Sized {
|
||||
walker::maybe_type_identifier(self, type_anno);
|
||||
}
|
||||
|
||||
fn import(&mut self, import: &ImportSpecifier) {
|
||||
fn named_struct(&mut self, name: &QualifiedName, fields: &Vec<(Rc<String>, Expression)>) {
|
||||
self.qualified_name(name);
|
||||
for (_, expr) in fields.iter() {
|
||||
walker::expression(self, expr);
|
||||
}
|
||||
}
|
||||
|
||||
fn import(&mut self, import: &ImportSpecifier) {}
|
||||
fn qualified_name(&mut self, name: &QualifiedName) {}
|
||||
fn nat_literal(&mut self, n: u64) {}
|
||||
fn float_literal(&mut self, f: f64) {}
|
||||
fn string_literal(&mut self, s: &Rc<String>) {}
|
||||
|
@ -69,15 +69,16 @@ pub fn expression_kind<V: ASTVisitor>(v: &mut V, expression_kind: &ExpressionKin
|
||||
BoolLiteral(b) => v.bool_literal(*b),
|
||||
BinExp(op, lhs, rhs) => v.binexp(op, lhs, rhs),
|
||||
PrefixExp(op, arg) => v.prefix_exp(op, arg),
|
||||
TupleLiteral(exprs) => {
|
||||
for expr in exprs {
|
||||
v.expression(expr);
|
||||
}
|
||||
},
|
||||
Value(name) => v.qualified_name(name),
|
||||
NamedStruct { name, fields } => v.named_struct(name, fields),
|
||||
_ => (),
|
||||
}
|
||||
/*
|
||||
TupleLiteral(Vec<Expression>),
|
||||
Value(QualifiedName),
|
||||
NamedStruct {
|
||||
name: QualifiedName,
|
||||
fields: Vec<(Rc<String>, Expression)>,
|
||||
},
|
||||
Call {
|
||||
f: Box<Expression>,
|
||||
arguments: Vec<InvocationArgument>,
|
||||
@ -109,4 +110,3 @@ pub fn expression_kind<V: ASTVisitor>(v: &mut V, expression_kind: &ExpressionKin
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user