From fd66a9711da16890a2e7eeef351622bfce5a0b83 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 3 Sep 2019 10:23:38 -0700 Subject: [PATCH] More work on fully-qualified names --- schala-lang/language/src/ast.rs | 1 + schala-lang/language/src/scope_resolution.rs | 38 +++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/schala-lang/language/src/ast.rs b/schala-lang/language/src/ast.rs index ce59dfe..b30268a 100644 --- a/schala-lang/language/src/ast.rs +++ b/schala-lang/language/src/ast.rs @@ -242,6 +242,7 @@ pub enum PatternLiteral { }, StringPattern(Rc), BoolPattern(bool), + //TODO I think VarPattern also needs to know about FQSNs VarPattern(Rc) } diff --git a/schala-lang/language/src/scope_resolution.rs b/schala-lang/language/src/scope_resolution.rs index 63f7fcd..995a699 100644 --- a/schala-lang/language/src/scope_resolution.rs +++ b/schala-lang/language/src/scope_resolution.rs @@ -29,18 +29,48 @@ impl ScopeResolver { } fn expr(&mut self, expr: &mut Meta) -> Result<(), String> { - match &expr.node().kind { - - //TODO this needs to fully recurse + use ExpressionKind::*; + let inner_expr = expr.mut_node(); + match &mut inner_expr.kind { ExpressionKind::Value(qualified_name) => { - //TODO fill this out let fqsn = lookup_name_in_scope(&qualified_name); expr.fqsn = Some(fqsn); }, + NamedStruct { name, .. } => { + let fqsn = lookup_name_in_scope(&name); + expr.fqsn = Some(fqsn); + }, + BinExp(_, ref mut lhs, ref mut rhs) => { + self.expr(lhs)?; + self.expr(rhs)?; + }, + PrefixExp(_, ref mut arg) => { + self.expr(arg)?; + }, + TupleLiteral(exprs) => { + for expr in exprs.iter_mut() { + self.expr(expr)?; + } + }, + Call { ref mut f, arguments } => { + self.expr(f)?; + for arg in arguments.iter_mut() { + self.invoc(arg)?; + } + } _ => () }; Ok(()) } + + fn invoc(&mut self, invoc: &mut InvocationArgument) -> Result<(), String> { + use InvocationArgument::*; + match invoc { + Positional(expr) => self.expr(expr), + Keyword { expr, .. } => self.expr(expr), + _ => Ok(()) + } + } } //TODO this is incomplete