fluidattacks-blends-domain 0.17.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::{adj_ast, match_ast_group_d},
    syntax::{builders::array_node::build_array_node, SyntaxGraphArgs, SyntaxGraphError},
    CodeGraph, NodeId,
};
use alloc::vec::Vec;

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

    let mut c_ids = Vec::new();

    for id in match_ast_group_d(graph, n_id, "array_element_initializer", Some(1)) {
        let element_c_ids = adj_ast(graph, id, Some(1), &[]);

        if let Some(&arrow) = element_c_ids
            .iter()
            .find(|&&c| graph.label_type(c) == Some("=>"))
        {
            c_ids.push(arrow);
        } else {
            c_ids.extend(element_c_ids);
        }
    }

    build_array_node(args, n_id, &c_ids).map(Some)
}