fluidattacks-blends-domain 0.3.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
//! Counterpart of `blends/syntax/builders/symbol_lookup.py` (the `StackGraph`
//! branch is excluded: the migration covers only AST, Syntax and CFG).

use alloc::string::String;

use crate::syntax::builders::utils::{find_definition_scope, get_event_subpath};
use crate::syntax::SanitizationEvent;
use crate::syntax::SyntaxGraphArgs;
use crate::syntax::SyntaxNode;
use crate::NodeId;

pub fn build_symbol_lookup_node(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
    symbol: String,
) -> NodeId {
    let symbol_scope = args.metadata.scope_stack.last().copied();

    let active = args
        .metadata
        .sanitization_stack
        .last()
        .filter(|(kind, _)| !kind.ends_with("_pending"))
        .map(|(kind, parent_id)| (kind.clone(), *parent_id));

    if let (Some((kind, parent_id)), Some(scope_top)) =
        (active, args.metadata.scope_stack.last().copied())
    {
        let subpath = get_event_subpath(args.metadata);
        let definition_scope = if subpath.is_some() {
            find_definition_scope(args.syntax_graph, &args.metadata.scope_stack, &symbol)
        } else {
            None
        };
        let scope = definition_scope.unwrap_or(scope_top);
        args.syntax_graph.register_sanitization(
            &symbol,
            scope,
            SanitizationEvent {
                node_id: parent_id,
                kind,
                subpath,
            },
        );
    }

    args.syntax_graph.add_node(
        n_id,
        SyntaxNode::SymbolLookup {
            symbol,
            symbol_scope,
            value: None,
        },
    );

    n_id
}