fluidattacks-blends-domain 0.6.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use alloc::borrow::ToOwned;
use alloc::vec::Vec;

use crate::query::adj_ast;
use crate::syntax::builders::parameter::build_parameter_node;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::utilities::text_nodes::node_to_str;
use crate::{CodeGraph, NodeId};

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let c_ids: Vec<NodeId> = adj_ast(args.ast_graph, n_id, None, &[]);

    match (c_ids.first(), c_ids.last()) {
        (Some(&type_id), Some(&name_id))
            if args.ast_graph.label_type(type_id) != Some("underscore_pattern") =>
        {
            let variable = node_to_str(args.ast_graph, name_id);
            let variable_type = node_to_str(args.ast_graph, type_id);
            build_parameter_node(
                args,
                n_id,
                Some(variable),
                Some(variable_type),
                None,
                &[],
                None,
                None,
            )
            .map(Some)
        }
        _ => build_parameter_node(
            args,
            n_id,
            Some("_".to_owned()),
            None,
            None,
            &[],
            None,
            None,
        )
        .map(Some),
    }
}