fluidattacks-blends-domain 0.6.1

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

use crate::query::{adj_ast, match_ast_d};
use crate::syntax::builders::member_access::build_member_access_node;
use crate::syntax::fields::c_sharp::conditional_access_expression;
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 expression_id = args.required_field_alt(n_id, conditional_access_expression::CONDITION)?;
    let expression = node_to_str(graph, expression_id);

    let member_id = match_ast_d(graph, n_id, "member_binding_expression", Some(1))
        .or_else(|| match_ast_d(graph, n_id, "element_binding_expression", Some(1)))
        .or_else(|| adj_ast(graph, n_id, None, &[]).last().copied());
    let member = member_id
        .map_or_else(String::new, |id| node_to_str(graph, id))
        .trim_matches('.')
        .to_owned();

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