fluidattacks-blends-domain 0.40.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::label_text,
    syntax::{
        builders::binary_operation::build_binary_operation_node, fields::Field, SyntaxGraphArgs,
        SyntaxGraphError,
    },
    NodeId,
};
use alloc::borrow::ToOwned;

const LHS: Field<true> = Field::new("lhs_id");
const OP: Field<true> = Field::new("op_id");
const RHS: Field<true> = Field::new("rhs_id");

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

    let left_id = args.required_field_alt(n_id, LHS)?;
    let right_id = args.required_field_alt(n_id, RHS)?;
    let operator_id = args.required_field_alt(n_id, OP)?;
    let operator = label_text(graph, operator_id).unwrap_or("").to_owned();

    build_binary_operation_node(args, n_id, operator, Some(left_id), Some(right_id)).map(Some)
}