fluidattacks-blends-domain 0.17.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::{adj_ast, pred_ast},
    syntax::{
        builders::argument_list::build_argument_list_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 p_id = pred_ast(graph, n_id, Some(1))
        .first()
        .copied()
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;

    let mut valid_childs: Vec<NodeId> = Vec::new();
    for c_id in adj_ast(graph, p_id, Some(1), &[]) {
        match graph.label_type(c_id) {
            Some("echo" | "," | ";") => {}
            Some("sequence_expression") => valid_childs.extend(
                adj_ast(graph, c_id, Some(1), &[])
                    .into_iter()
                    .filter(|&nid| !matches!(graph.label_type(nid), Some("echo" | "," | ";"))),
            ),
            _ => valid_childs.push(c_id),
        }
    }

    build_argument_list_node(args, n_id, &valid_childs).map(Some)
}