fluidattacks-blends-domain 0.30.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use alloc::vec::Vec;

use crate::query::{adj_ast, match_ast_group_d};
use crate::syntax::builders::file::build_file_node;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::{CodeGraph, NodeId};

const IGNORED: &[&str] = &["\n", "\r\n"];

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, None, &[]);

    let mut filtered_ids: Vec<NodeId> = Vec::new();
    for c_id in c_ids {
        let label_type = graph.label_type(c_id).unwrap_or_default();
        if IGNORED.contains(&label_type) {
            continue;
        }
        if label_type == "import_declaration" {
            filtered_ids.extend(match_ast_group_d(graph, c_id, "import_spec", Some(2)));
            continue;
        }
        filtered_ids.push(c_id);
    }

    build_file_node(args, n_id, &filtered_ids).map(Some)
}