fluidattacks-blends-domain 0.41.0

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

use crate::query::adj_ast;
use crate::syntax::builders::execution_block::build_execution_block_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 inner = c_ids
        .get(1..c_ids.len().saturating_sub(1))
        .unwrap_or_default();

    let mut filtered_ids: BTreeSet<NodeId> = BTreeSet::new();
    for c_id in inner {
        let label_type = graph.label_type(*c_id).unwrap_or_default();
        if label_type == "expression_statement" {
            filtered_ids.extend(adj_ast(graph, *c_id, None, &[]));
        } else if !IGNORED.contains(&label_type) {
            filtered_ids.insert(*c_id);
        }
    }

    let filtered_ids: Vec<NodeId> = filtered_ids.into_iter().collect();
    build_execution_block_node(args, n_id, &filtered_ids).map(Some)
}