fluidattacks-blends-domain 0.6.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError, SyntaxNode};
use crate::{CodeGraph, NodeId};

pub fn build_new_expression_node(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
    constructor_id: NodeId,
    arguments_id: Option<NodeId>,
) -> Result<NodeId, SyntaxGraphError> {
    // Python drops the arguments child when its AST node is a bare `const`.
    let arguments_id = arguments_id.filter(|id| args.ast_graph.label_type(*id) != Some("const"));

    args.syntax_graph.add_node(
        n_id,
        SyntaxNode::NewExpression {
            constructor_id,
            arguments_id,
        },
    );

    let built_constructor = args.generic(constructor_id)?;
    args.syntax_graph.add_ast_edge(n_id, built_constructor);

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

    Ok(n_id)
}