fluidattacks-blends-domain 0.17.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::match_ast_group,
    syntax::{builders::switch_body::build_switch_body_node, SyntaxGraphArgs, SyntaxGraphError},
    NodeId,
};
use alloc::vec::Vec;

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

    let c_ids = match_ast_group(
        graph,
        n_id,
        &["case_statement", "default_statement"],
        Some(1),
    );
    let case_ids = c_ids
        .get("case_statement")
        .map(Vec::as_slice)
        .unwrap_or_default();

    let def_n_id = c_ids
        .get("default_statement")
        .and_then(|def_n_ids| def_n_ids.first().copied());

    build_switch_body_node(args, n_id, case_ids, def_n_id).map(Some)
}