fluidattacks-blends-domain 0.17.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::{adj_ast, label_text},
    syntax::{
        builders::member_access::build_member_access_node, SyntaxGraphArgs, SyntaxGraphError,
    },
    utilities::text_nodes::node_to_str,
    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 obj_id = c_ids
        .first()
        .copied()
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;

    let expression = node_to_str(graph, obj_id);

    let member_n_id = c_ids
        .last()
        .copied()
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;

    let member = label_text(graph, member_n_id).unwrap_or("");

    build_member_access_node(args, n_id, member.to_owned(), expression, obj_id).map(Some)
}