fluidattacks-blends-domain 0.41.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::{adj_ast, label_text},
    syntax::{
        builders::unary_expression::build_unary_expression_node, SyntaxGraphArgs, SyntaxGraphError,
    },
    CodeGraph, NodeId,
};
use alloc::borrow::ToOwned;

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

    let val_id = c_ids
        .first()
        .copied()
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;

    let operator = c_ids
        .get(1)
        .filter(|&&op_id| graph.label_type(op_id) == Some("bang"))
        .and_then(|&op_id| adj_ast(graph, op_id, Some(1), &[]).first().copied())
        .map_or_else(
            || "Unary".to_owned(),
            |text_id| label_text(graph, text_id).unwrap_or("").to_owned(),
        );

    build_unary_expression_node(args, n_id, operator, val_id).map(Some)
}