use alloc::borrow::ToOwned;
use alloc::vec::Vec;
use crate::query::match_ast_group_d;
use crate::syntax::builders::string_literal::build_string_literal_node;
use crate::syntax::fields::python::interpolation;
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 = node_to_str(graph, n_id);
if text.starts_with("f\"") || text.starts_with("f'") {
let stripped = text.trim_start_matches('f').to_owned();
let mut int_subs: Vec<NodeId> = Vec::new();
for interp_id in match_ast_group_d(graph, n_id, "interpolation", Some(1)) {
int_subs.push(args.required_field_alt(interp_id, interpolation::EXPRESSION)?);
}
if !int_subs.is_empty() {
return build_string_literal_node(args, n_id, stripped, &int_subs).map(Some);
}
}
build_string_literal_node(args, n_id, text, &[]).map(Some)
}