More visitor stuff

This commit is contained in:
greg 2019-09-26 03:26:14 -07:00
parent d80a0036b1
commit c8804eeefb
3 changed files with 15 additions and 9 deletions

View File

@ -7,7 +7,7 @@
- standardize on an error type that isn't String - standardize on an error type that isn't String
-implement a visitor pattern for the use of scope_resolver -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, - 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 ## Reduction
- make a good type for actual language builtins to avoid string comparisons - make a good type for actual language builtins to avoid string comparisons

View File

@ -48,9 +48,15 @@ pub trait ASTVisitor: Sized {
walker::maybe_type_identifier(self, type_anno); 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 nat_literal(&mut self, n: u64) {}
fn float_literal(&mut self, f: f64) {} fn float_literal(&mut self, f: f64) {}
fn string_literal(&mut self, s: &Rc<String>) {} fn string_literal(&mut self, s: &Rc<String>) {}

View File

@ -69,15 +69,16 @@ pub fn expression_kind<V: ASTVisitor>(v: &mut V, expression_kind: &ExpressionKin
BoolLiteral(b) => v.bool_literal(*b), BoolLiteral(b) => v.bool_literal(*b),
BinExp(op, lhs, rhs) => v.binexp(op, lhs, rhs), BinExp(op, lhs, rhs) => v.binexp(op, lhs, rhs),
PrefixExp(op, arg) => v.prefix_exp(op, arg), 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 { Call {
f: Box<Expression>, f: Box<Expression>,
arguments: Vec<InvocationArgument>, arguments: Vec<InvocationArgument>,
@ -109,4 +110,3 @@ pub fn expression_kind<V: ASTVisitor>(v: &mut V, expression_kind: &ExpressionKin
*/ */
} }