diff --git a/TODO.md b/TODO.md index 25462cc..953dfef 100644 --- a/TODO.md +++ b/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 diff --git a/schala-lang/language/src/ast/visitor.rs b/schala-lang/language/src/ast/visitor.rs index c274379..889e9d8 100644 --- a/schala-lang/language/src/ast/visitor.rs +++ b/schala-lang/language/src/ast/visitor.rs @@ -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, 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) {} diff --git a/schala-lang/language/src/ast/walker.rs b/schala-lang/language/src/ast/walker.rs index bd1da10..74fca5b 100644 --- a/schala-lang/language/src/ast/walker.rs +++ b/schala-lang/language/src/ast/walker.rs @@ -69,15 +69,16 @@ pub fn expression_kind(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), - Value(QualifiedName), - NamedStruct { - name: QualifiedName, - fields: Vec<(Rc, Expression)>, - }, Call { f: Box, arguments: Vec, @@ -109,4 +110,3 @@ pub fn expression_kind(v: &mut V, expression_kind: &ExpressionKin */ } -