fluidattacks-blends-domain 0.19.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::adj_ast,
    syntax::{
        builders::switch_section::build_switch_section_node, 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 child_ids = adj_ast(graph, n_id, Some(1), &[]);

    let value_id = child_ids
        .first()
        .copied()
        .ok_or(SyntaxGraphError::MissingAstNode)?;
    let case_value = node_to_str(graph, value_id);

    let body_id = child_ids
        .get(2)
        .copied()
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;

    build_switch_section_node(args, n_id, case_value, &[body_id]).map(Some)
}