fluidattacks-blends-domain 0.6.1

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

use crate::query::{adj_ast, label_text, 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::NodeId;

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let graph = args.ast_graph;
    let text = label_text(graph, n_id)
        .filter(|text| !text.is_empty())
        .map_or_else(|| node_to_str(graph, n_id), ToOwned::to_owned);
    let int_subs: Vec<NodeId> = match_ast_group_d(graph, n_id, "template_substitution", Some(1))
        .into_iter()
        .filter_map(|sub_id| adj_ast(graph, sub_id, None, &[]).get(1).copied())
        .collect();
    build_string_literal_node(args, n_id, text, &int_subs).map(Some)
}