use crate::{
query::label_text,
syntax::{
builders::{literal::build_literal_node, symbol_lookup::build_symbol_lookup_node},
SyntaxGraphArgs, SyntaxGraphError,
},
utilities::text_nodes::node_to_str,
NodeId,
};
use alloc::borrow::ToOwned;
#[expect(
clippy::unnecessary_wraps,
reason = "the signature must match the reader dispatch table"
)]
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let symbol = label_text(graph, n_id)
.filter(|text| !text.is_empty())
.map_or_else(|| node_to_str(graph, n_id), str::to_owned);
if matches!(symbol.as_str(), "false" | "true") {
return Ok(Some(build_literal_node(
args,
n_id,
symbol,
"bool".to_owned(),
)));
}
if symbol.as_str() == "null" {
return Ok(Some(build_literal_node(
args,
n_id,
symbol,
"null".to_owned(),
)));
}
Ok(Some(build_symbol_lookup_node(args, n_id, symbol)))
}