Isolate import handling code

This commit is contained in:
greg 2019-09-24 18:42:01 -07:00
parent 41cad61e34
commit 9cd64d97a5
1 changed files with 18 additions and 16 deletions

View File

@ -21,27 +21,29 @@ impl<'a> ScopeResolver<'a> {
match statement.kind {
StatementKind::Declaration(ref decl) => self.decl(decl),
StatementKind::Expression(ref expr) => self.expr(expr),
StatementKind::Import(ImportSpecifier { ref path_components, ref imported_names, .. }) => {
match imported_names {
ImportedNames::All => unimplemented!(),
ImportedNames::LastOfPath => {
let name = path_components.last().unwrap(); //TODO handle better
let fqsn_prefix = path_components.iter().map(|c| ScopeSegment {
name: c.clone(), kind: ScopeSegmentKind::Type
}).collect();
self.name_scope_stack.insert(name.clone(), fqsn_prefix);
()
}
ImportedNames::List(ref names) => unimplemented!()
};
//self.name_scope_stack.insert()
Ok(())
}
StatementKind::Import(ref spec) => self.import(spec),
}?;
}
Ok(())
}
fn import(&mut self, import_spec: &ImportSpecifier) -> Result<(), String> {
let ImportSpecifier { ref path_components, ref imported_names, .. } = &import_spec;
match imported_names {
ImportedNames::All => unimplemented!(),
ImportedNames::LastOfPath => {
let name = path_components.last().unwrap(); //TODO handle better
let fqsn_prefix = path_components.iter().map(|c| ScopeSegment {
name: c.clone(), kind: ScopeSegmentKind::Type
}).collect();
self.name_scope_stack.insert(name.clone(), fqsn_prefix);
()
}
ImportedNames::List(ref names) => unimplemented!()
};
Ok(())
}
fn decl(&mut self, decl: &Declaration) -> Result<(), String> {
use Declaration::*;
match decl {