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::import_statement::{build_import_node, ImportElement},
        SyntaxGraphArgs, SyntaxGraphError,
    },
    utilities::text_nodes::node_to_str,
    CodeGraph, NodeId,
};
use alloc::{string::String, vec::Vec};

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 name = c_ids
        .first()
        .map_or_else(String::new, |&first| node_to_str(graph, first));

    let mut node_ids: Vec<NodeId> = Vec::new();
    for &c_id in c_ids.iter().skip(1) {
        if graph.label_type(c_id) == Some("parenthesized_expression") {
            if let Some(&inner) = adj_ast(graph, c_id, Some(1), &[]).get(1) {
                node_ids.push(inner);
            }
        } else {
            node_ids.push(c_id);
        }
    }

    build_import_node(
        args,
        n_id,
        &ImportElement {
            expression: Some(name),
            module_nodes: node_ids,
            ..ImportElement::default()
        },
    )
    .map(Some)
}