use alloc::vec::Vec;
use crate::{
query::{match_ast_group, match_ast_group_d, pred_ast},
syntax::{
builders::string_literal::build_string_literal_node, SyntaxGraphArgs, SyntaxGraphError,
},
utilities::text_nodes::node_to_str,
CodeGraph, NodeId,
};
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let text = node_to_str(graph, n_id);
let mut c_ids: Vec<NodeId> = Vec::new();
if let Some(&parent) = pred_ast(graph, n_id, Some(1)).first() {
if graph.label_type(parent) == Some("subshell") {
for interpolation in match_ast_group_d(graph, parent, "interpolation", Some(1)) {
let mut childs = match_ast_group(
graph,
interpolation,
&["identifier", "element_reference"],
Some(1),
);
c_ids.extend(childs.remove("identifier").unwrap_or_default());
c_ids.extend(childs.remove("element_reference").unwrap_or_default());
}
}
}
build_string_literal_node(args, n_id, text, &c_ids).map(Some)
}