fluidattacks-blends-domain 0.3.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use alloc::string::String;

use crate::query::adj_ast;
use crate::syntax::builders::unary_expression::build_unary_expression_node;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::utilities::text_nodes::node_to_str;
use crate::NodeId;

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let graph = args.ast_graph;
    let (operator, operand_id) = match adj_ast(graph, n_id, None, &[]).as_slice() {
        [operator, operand] => (node_to_str(graph, *operator), *operand),
        [operand, ..] => (String::from("Undefined"), *operand),
        [] => return Err(SyntaxGraphError::UnexpectedAstShape),
    };
    build_unary_expression_node(args, n_id, operator, operand_id).map(Some)
}