fluidattacks-blends-domain 0.17.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::adj_ast,
    syntax::{
        builders::element_access::build_element_access_node, SyntaxGraphArgs, SyntaxGraphError,
    },
    NodeId,
};

const EXPECTED_CHILDREN_FOR_SUBSCRIPT_WITH_ARGUMENTS: usize = 4;

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

    let c_ids = adj_ast(graph, n_id, Some(1), &[]);

    let expr_id = c_ids.first().copied().unwrap_or(n_id);

    let arguments_id = if c_ids.len() == EXPECTED_CHILDREN_FOR_SUBSCRIPT_WITH_ARGUMENTS {
        c_ids.get(2).copied()
    } else {
        None
    };

    build_element_access_node(args, n_id, expr_id, arguments_id).map(Some)
}