fluidattacks-blends-domain 0.43.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    syntax::{
        _node_builders::languages::rust::{
            array_expression::build_array_expression, transform::build_syntax_node,
        },
        builders::array_node::build_array_node,
        core_nodes::ArrayExpression,
        readers::rust::generic_reader::generic_reader,
        SyntaxGraphArgs, SyntaxGraphError,
    },
    NodeId,
};
use alloc::vec::Vec;

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    generic_reader(
        args,
        n_id,
        |g, n| build_array_expression(g, n, |n| build_syntax_node(g, n)),
        |a, array| {
            // `ArrayInitializer` cannot carry a repetition length, so `[x; N]` keeps only `x`
            let c_ids: Vec<NodeId> = match array {
                ArrayExpression::Fixed(fixed) => {
                    fixed.elements.iter().map(|(_, c_id)| *c_id).collect()
                }
                ArrayExpression::Repetition(repetition) => {
                    Vec::from([repetition.element.1, repetition.repetition.1])
                }
            };
            build_array_node(a, n_id, &c_ids, None).map(Some)
        },
    )
}