use alloc::borrow::ToOwned;
use alloc::vec::Vec;
use crate::query::{adj_ast, label_text, match_ast_d};
use crate::syntax::builders::argument_list::build_argument_list_node;
use crate::syntax::builders::string_literal::build_string_literal_node;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::{CodeGraph, NodeId};
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, &[]);
if c_ids.len() == 1 {
if let Some(literal_id) = match_ast_d(graph, n_id, "interpreted_string_literal", None) {
if let Some(value) = label_text(graph, literal_id) {
let value = value.to_owned();
return build_string_literal_node(args, n_id, value, &[]).map(Some);
}
}
}
let filtered: Vec<NodeId> = c_ids
.iter()
.copied()
.filter(|c_id| !matches!(graph.label_type(*c_id), Some("," | ":")))
.collect();
build_argument_list_node(args, n_id, &filtered).map(Some)
}