| 66 | } |
| 67 | |
| 68 | pub fn insert(&mut self, fq_ident: Ident, decl: Decl) -> Result<Option<Decl>, Error> { |
| 69 | if fq_ident.path.is_empty() { |
| 70 | Ok(self.names.insert(fq_ident.name, decl)) |
| 71 | } else { |
| 72 | let (top_level, remaining) = fq_ident.pop_front(); |
| 73 | let entry = self.names.entry(top_level).or_default(); |
| 74 | |
| 75 | if let DeclKind::Module(inner) = &mut entry.kind { |
| 76 | inner.insert(remaining.unwrap(), decl) |
| 77 | } else { |
| 78 | Err(Error::new_simple( |
| 79 | "path does not resolve to a module or a table", |
| 80 | )) |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | pub fn get_mut(&mut self, ident: &Ident) -> Option<&mut Decl> { |
| 86 | let mut ns = self; |