use crate::{
query::{label_text, match_ast},
syntax::{
builders::variable_declaration::build_variable_declaration_node, SyntaxGraphArgs,
SyntaxGraphError,
},
NodeId,
};
use alloc::borrow::ToOwned;
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let identifier_id = match_ast(graph, n_id, &["identifier"], Some(1));
let ident_id = identifier_id.get("identifier").copied().flatten();
let var_name = ident_id.map_or("", |id| label_text(graph, id).unwrap_or(""));
build_variable_declaration_node(args, n_id, var_name.to_owned(), None, ident_id, None, None)
.map(Some)
}