fluidattacks-blends-domain 0.6.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
//! Counterpart of `blends/syntax/builders/module_decl.py` (the `StackGraph`
//! definition setup and module descent wiring are excluded: the migration
//! covers only AST, Syntax and CFG).

use alloc::string::String;

use crate::syntax::builders::utils::{enter_scope_stack, exit_scope_stack_if_current};
use crate::syntax::SyntaxNode;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::NodeId;

pub fn build_module_node(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
    name: String,
    block_id: Option<NodeId>,
    access_modifiers: Option<String>,
) -> Result<NodeId, SyntaxGraphError> {
    args.syntax_graph.add_node(
        n_id,
        SyntaxNode::Declaration {
            name,
            block_id,
            access_modifiers: access_modifiers.filter(|value| !value.is_empty()),
        },
    );

    enter_scope_stack(args.syntax_graph, args.metadata, n_id);

    if let Some(block_id) = block_id {
        let built = args.generic(block_id)?;
        args.syntax_graph.add_ast_edge(n_id, built);
    }

    exit_scope_stack_if_current(args.metadata, n_id);

    Ok(n_id)
}