use crate::{
query::adj_ast,
syntax::{
builders::named_argument::build_named_argument_node, SyntaxGraphArgs, SyntaxGraphError,
},
utilities::text_nodes::node_to_str,
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, Some(1), &[]);
let value_id = c_ids
.last()
.copied()
.ok_or(SyntaxGraphError::UnexpectedAstShape)?;
let arg_name = if c_ids
.get(1)
.is_some_and(|&id| node_to_str(graph, id) == "=")
{
c_ids.first().map(|&id| node_to_str(graph, id))
} else {
None
};
build_named_argument_node(args, n_id, arg_name, value_id).map(Some)
}