rils_frontend 0.4.0

Static analysis and semantic frontend for the Rils scripting language
Documentation
//! Copied defaults resolve free names in the trait's lexical module.
use super::*;

impl Analyzer {
    pub(super) fn with_default_scope(
        &mut self,
        module: Option<&[String]>,
        action: impl FnOnce(&mut Self),
    ) {
        let Some(module) = module else {
            action(self);
            return;
        };
        let mut scope = self
            .scopes
            .iter()
            .take(2)
            .flatten()
            .filter(|(_, definition)| definition.span.is_none())
            .map(|(name, definition)| (name.clone(), definition.clone()))
            .collect::<HashMap<_, _>>();
        for (name, span, kind) in self.declaration_types.lexical_symbols(module) {
            let id = self
                .result
                .symbols
                .iter()
                .find(|symbol| symbol.is_definition && symbol.span == span)
                .and_then(|symbol| symbol.symbol_id);
            scope.insert(
                name,
                Definition {
                    canonical_path: None,
                    external_function: None,
                    span: Some(span),
                    id,
                    kind,
                    container: Some(SymbolContainer::Module(module.join("::"))),
                },
            );
        }
        let scopes = std::mem::replace(&mut self.scopes, vec![scope]);
        let enclosing = std::mem::replace(&mut self.module_scope_start, 0);
        let saved = std::mem::replace(&mut self.module_path, module.to_vec());
        action(self);
        self.module_path = saved;
        self.scopes = scopes;
        self.module_scope_start = enclosing;
    }
}