use alloc::borrow::ToOwned;
use crate::query::match_ast;
use crate::syntax::builders::object_creation::build_object_creation_node;
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 children = match_ast(args.ast_graph, n_id, &["record_pattern_body"], None);
let body_id = children.get("record_pattern_body").copied().flatten();
let type_id = children.get("__0__").copied().flatten();
let name = type_id.map_or_else(
|| "UnnamedObject".to_owned(),
|t_id| node_to_str(args.ast_graph, t_id),
);
build_object_creation_node(args, n_id, name, body_id, None, None).map(Some)
}