fluidattacks-blends-domain 0.34.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::{adj_ast, label_text, match_ast_d},
    syntax::{
        builders::member_access::build_member_access_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 relative_n_id = c_ids
        .first()
        .copied()
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;
    let member_n_id = c_ids
        .last()
        .copied()
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;

    if graph.label_type(relative_n_id) == Some("relative_scope") {
        let expression = label_text(graph, member_n_id).unwrap_or("");
        let obj_id =
            match_ast_d(graph, relative_n_id, "self", Some(1)).map_or(member_n_id, |id| id);
        return build_member_access_node(
            args,
            n_id,
            "self".to_owned(),
            expression.to_owned(),
            obj_id,
        )
        .map(Some);
    }

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

    build_member_access_node(
        args,
        n_id,
        member.to_owned(),
        class_name.to_owned(),
        relative_n_id,
    )
    .map(Some)
}