fluidattacks-blends-domain 0.22.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::{adj_ast, match_ast_group},
    syntax::{
        builders::method_invocation::{build_method_invocation_node, DirectChildren},
        SyntaxGraphArgs, SyntaxGraphError,
    },
    utilities::text_nodes::node_to_str,
    NodeId,
};

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

    let Some(expr_id) = adj_ast(graph, n_id, Some(1), &[]).first().copied() else {
        return Ok(None);
    };
    let expr = node_to_str(graph, expr_id);

    let matches = match_ast_group(
        graph,
        n_id,
        &["value_arguments", "annotated_lambda"],
        Some(1),
    );

    let arguments_id = matches
        .get("value_arguments")
        .and_then(|ids| ids.first().copied());

    let object_id = matches
        .get("annotated_lambda")
        .and_then(|ids| ids.first().copied())
        .and_then(|lambda_id| {
            adj_ast(graph, lambda_id, Some(1), &["lambda_literal"])
                .first()
                .copied()
        });

    let children = DirectChildren {
        expression_id: Some(expr_id),
        arguments_id,
        object_id,
        ..DirectChildren::default()
    };

    build_method_invocation_node(args, n_id, expr, children, None).map(Some)
}