fluidattacks-blends-domain 0.2.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
//! Counterpart of `blends/syntax/builders/object_creation.py`.

use alloc::string::String;

use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError, SyntaxNode};
use crate::NodeId;

#[allow(
    clippy::too_many_arguments,
    reason = "mirrors the Python builder: name plus three role-specific child ids"
)]
pub fn build_object_creation_node(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
    name: String,
    arguments_id: Option<NodeId>,
    initializer_id: Option<NodeId>,
    constructor_id: Option<NodeId>,
) -> Result<NodeId, SyntaxGraphError> {
    args.syntax_graph.add_node(
        n_id,
        SyntaxNode::ObjectCreation {
            name,
            arguments_id,
            initializer_id,
        },
    );

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

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

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

    Ok(n_id)
}