fluidattacks-blends-domain 0.28.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::{adj_ast, match_ast_d},
    syntax::{
        builders::method_invocation::{build_method_invocation_node, DirectChildren},
        SyntaxGraphArgs, SyntaxGraphError,
    },
    utilities::text_nodes::node_to_str,
    CodeGraph, NodeId,
};

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let graph = args.ast_graph;

    let expr_id = adj_ast(graph, n_id, Some(1), &[])
        .first()
        .copied()
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;
    let expr = node_to_str(graph, expr_id);

    let mut arguments_id = match_ast_d(graph, n_id, "call_suffix", Some(1));
    if let Some(suffix_id) = arguments_id {
        if let [only_child] = adj_ast(graph, suffix_id, Some(1), &[]).as_slice() {
            if graph.label_type(*only_child) == Some("value_arguments") {
                arguments_id = Some(*only_child);
            }
        }
    }

    let direct_children = DirectChildren {
        expression_id: Some(expr_id),
        arguments_id,
        ..DirectChildren::default()
    };

    build_method_invocation_node(args, n_id, expr, direct_children, None).map(Some)
}