fluidattacks-blends-domain 0.19.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::{adj_ast, match_ast_d},
    syntax::{builders::annotation::build_annotation_node, SyntaxGraphArgs, SyntaxGraphError},
    utilities::text_nodes::node_to_str,
    NodeId,
};
use alloc::string::String;

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

    let mut annotation_name = String::from("@");
    let mut args_id = None;

    if let Some(constructor_id) = match_ast_d(graph, n_id, "constructor_invocation", Some(1)) {
        let children = adj_ast(graph, constructor_id, Some(1), &[]);
        if let Some(&name_id) = children.first() {
            annotation_name.push_str(&node_to_str(graph, name_id));
            args_id = children.get(1).copied();
        }
    }

    build_annotation_node(args, n_id, annotation_name, args_id).map(Some)
}