use alloc::string::String;
use crate::query::{adj_ast, match_ast_d};
use crate::syntax::builders::method_declaration::{
build_method_declaration_node, MethodDirectChildren, MethodListChildren,
};
use crate::syntax::fields::c_sharp::lambda_expression;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::NodeId;
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let body_id = args.required_field_alt(n_id, lambda_expression::BODY)?;
let graph = args.ast_graph;
let param_id = match_ast_d(graph, n_id, "identifier", Some(1))
.or_else(|| match_ast_d(graph, n_id, "parameter_list", Some(1)))
.or_else(|| adj_ast(graph, n_id, None, &[]).first().copied());
let direct = MethodDirectChildren {
block_id: Some(body_id),
parameters_id: param_id,
..MethodDirectChildren::default()
};
build_method_declaration_node(
args,
n_id,
Some(String::from("LambdaExpression")),
&direct,
&MethodListChildren::default(),
None,
)
.map(Some)
}