From 016d8fc9004f112838c89fc285eed78639bc627f Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 21 Oct 2019 02:56:21 -0700 Subject: [PATCH] Fixed tests but I think importing is still not working properly --- schala-lang/language/src/scope_resolution.rs | 20 ++++++++++++------- .../language/src/symbol_table/symbol_trie.rs | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/schala-lang/language/src/scope_resolution.rs b/schala-lang/language/src/scope_resolution.rs index a9b3a64..89b1158 100644 --- a/schala-lang/language/src/scope_resolution.rs +++ b/schala-lang/language/src/scope_resolution.rs @@ -23,7 +23,6 @@ impl<'a> ASTVisitor for ScopeResolver<'a> { let members = self.symbol_table.lookup_children_of_fqsn(&prefix); for member in members.into_iter() { let local_name = member.0.last().unwrap().name.clone(); - println!("LOCAL NAME: {:?} and member: {:?}", local_name, member); self.name_scope_stack.insert(local_name.clone(), member.0); } }, @@ -80,13 +79,20 @@ impl<'a> ScopeResolver<'a> { Ok(()) } - //TODO this is incomplete fn lookup_name_in_scope(&self, sym_name: &QualifiedName) -> FullyQualifiedSymbolName { - let QualifiedName { components: vec, .. } = sym_name; - let new_vec: Vec = vec.iter().map(|name| { - ScopeSegment { name: name.clone() } - }).collect(); - FullyQualifiedSymbolName(new_vec) + let QualifiedName { components, .. } = sym_name; + let first_component = &components[0]; + match self.name_scope_stack.lookup(first_component) { + None => { + FullyQualifiedSymbolName(components.iter().map(|name| ScopeSegment { name: name.clone() }).collect()) + }, + Some(fqsn_prefix) => { + let mut full_name = fqsn_prefix.clone(); + let rest_of_name: FQSNPrefix = components[1..].iter().map(|name| ScopeSegment { name: name.clone() }).collect(); + full_name.extend_from_slice(&rest_of_name); + FullyQualifiedSymbolName(full_name) + } + } } /// this might be a variable or a pattern. if a variable, set to none diff --git a/schala-lang/language/src/symbol_table/symbol_trie.rs b/schala-lang/language/src/symbol_table/symbol_trie.rs index 904a7b5..d5690da 100644 --- a/schala-lang/language/src/symbol_table/symbol_trie.rs +++ b/schala-lang/language/src/symbol_table/symbol_trie.rs @@ -48,5 +48,5 @@ fn test_trie_insertion() { trie.insert(&fqsn!("outer"; ty, "inner"; ty, "still_inner"; tr)); let children = trie.get_children(&fqsn!("outer"; ty, "inner"; tr)); - assert_eq!(children.len(), 2); + assert_eq!(children.len(), 1); }