Make lookup_name_in_scope a method
This commit is contained in:
parent
031ff9fe7e
commit
1fc028c9fc
@ -21,6 +21,22 @@ 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 len = vec.len();
|
||||
let new_vec: Vec<ScopeSegment> = vec.iter().enumerate().map(|(i, name)| {
|
||||
let kind = if i == (len - 1) {
|
||||
ScopeSegmentKind::Terminal
|
||||
} else {
|
||||
ScopeSegmentKind::Type
|
||||
};
|
||||
ScopeSegment { name: name.clone(), kind }
|
||||
}).collect();
|
||||
FullyQualifiedSymbolName(new_vec)
|
||||
}
|
||||
|
||||
fn import(&mut self, import_spec: &ImportSpecifier) -> Result<(), String> {
|
||||
let ImportSpecifier { ref path_components, ref imported_names, .. } = &import_spec;
|
||||
match imported_names {
|
||||
@ -68,13 +84,13 @@ impl<'a> ScopeResolver<'a> {
|
||||
use ExpressionKind::*;
|
||||
match &expr.kind {
|
||||
ExpressionKind::Value(qualified_name) => {
|
||||
let fqsn = lookup_name_in_scope(&qualified_name);
|
||||
let fqsn = self.lookup_name_in_scope(&qualified_name);
|
||||
let ref id = qualified_name.id;
|
||||
self.symbol_table.map_id_to_fqsn(id, fqsn);
|
||||
},
|
||||
NamedStruct { name, .. } => {
|
||||
let ref id = name.id;
|
||||
let fqsn = lookup_name_in_scope(&name);
|
||||
let fqsn = self.lookup_name_in_scope(&name);
|
||||
self.symbol_table.map_id_to_fqsn(id, fqsn);
|
||||
},
|
||||
BinExp(_, ref lhs, ref rhs) => {
|
||||
@ -173,28 +189,13 @@ impl<'a> ScopeResolver<'a> {
|
||||
/// this might be a variable or a pattern. if a variable, set to none
|
||||
fn qualified_name_in_pattern(&mut self, qualified_name: &QualifiedName) {
|
||||
let ref id = qualified_name.id;
|
||||
let fqsn = lookup_name_in_scope(qualified_name);
|
||||
let fqsn = self.lookup_name_in_scope(qualified_name);
|
||||
if self.symbol_table.lookup_by_fqsn(&fqsn).is_some() {
|
||||
self.symbol_table.map_id_to_fqsn(&id, fqsn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO this is incomplete
|
||||
fn lookup_name_in_scope(sym_name: &QualifiedName) -> FullyQualifiedSymbolName {
|
||||
let QualifiedName { components: vec, .. } = sym_name;
|
||||
let len = vec.len();
|
||||
let new_vec: Vec<ScopeSegment> = vec.iter().enumerate().map(|(i, name)| {
|
||||
let kind = if i == (len - 1) {
|
||||
ScopeSegmentKind::Terminal
|
||||
} else {
|
||||
ScopeSegmentKind::Type
|
||||
};
|
||||
ScopeSegment { name: name.clone(), kind }
|
||||
}).collect();
|
||||
FullyQualifiedSymbolName(new_vec)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user