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::string_literal::build_string_literal_node, SyntaxGraphArgs, SyntaxGraphError,
    },
    utilities::text_nodes::node_to_str,
    CodeGraph, NodeId,
};
use alloc::borrow::ToOwned;
use alloc::vec::Vec;

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let graph = args.ast_graph;

    let full = node_to_str(graph, n_id);
    let mut chars = full.chars();
    chars.next();
    chars.next_back();
    let value = chars.as_str().to_owned();

    let c_ids: Vec<NodeId> = adj_ast(graph, n_id, Some(1), &[])
        .into_iter()
        .filter(|&c_id| {
            matches!(
                graph.label_type(c_id),
                Some("variable_name" | "subscript_expression")
            )
        })
        .collect();

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