fluidattacks-blends-domain 0.22.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::adj_ast,
    syntax::{
        builders::{return_statement::build_return_node, throw::build_throw_node},
        SyntaxGraphArgs, SyntaxGraphError,
    },
    CodeGraph, NodeId,
};

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

    let has_throw = child_ids
        .iter()
        .any(|&c_id| graph.label_type(c_id) == Some("throw"));
    let has_return = child_ids
        .iter()
        .any(|&c_id| graph.label_type(c_id) == Some("return"));
    let val_id = child_ids
        .iter()
        .copied()
        .find(|&c_id| !matches!(graph.label_type(c_id), Some("throw" | "return")));

    if let Some(val) = val_id {
        if has_throw {
            return build_throw_node(args, n_id, Some(val)).map(Some);
        }
        if has_return {
            return build_return_node(args, n_id, Some(val)).map(Some);
        }
    }

    build_return_node(args, n_id, None).map(Some)
}