fluidattacks-blends-domain 0.40.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::adj_ast,
    syntax::{
        builders::argument_list::build_argument_list_node, fields::swift::value_argument,
        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 children = adj_ast(graph, n_id, Some(1), &[]);
    let c_ids = children
        .get(1..children.len().saturating_sub(1))
        .unwrap_or_default();

    let mut arg_ids: Vec<NodeId> = Vec::new();
    for &c_id in c_ids {
        if graph.label_type(c_id) != Some("value_argument") {
            continue;
        }
        let name = args.optional_field_alt(c_id, value_argument::NAME);
        let value = args.optional_field_alt(c_id, value_argument::VALUE);
        match (name, value) {
            (None, Some(value_id)) => arg_ids.push(value_id),
            _ => arg_ids.push(c_id),
        }
    }

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