fluidattacks-blends-domain 0.3.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::string_literal::build_string_literal_node;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::utilities::text_nodes::node_to_str;
use crate::{CodeGraph, NodeId};

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let graph = args.ast_graph;
    let value = node_to_str(graph, n_id);
    let declaration_ids = match_ast_group_d(graph, n_id, "interpolation", Some(1))
        .into_iter()
        .flat_map(|interp_id| adj_ast(graph, interp_id, None, &[]))
        .filter(|var_id| {
            !matches!(
                graph.label_type(*var_id),
                Some("{" | "}" | "," | "interpolation_brace")
            )
        })
        .collect::<Vec<NodeId>>();

    build_string_literal_node(args, n_id, value, &declaration_ids).map(Some)
}