use crate::syntax::fields::kotlin::while_statement;
use crate::{
query::adj_ast,
syntax::{
builders::while_statement::build_while_statement_node, SyntaxGraphArgs, SyntaxGraphError,
},
NodeId,
};
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let block = adj_ast(graph, n_id, Some(1), &[])
.last()
.copied()
.ok_or(SyntaxGraphError::UnexpectedAstShape)?;
let conditional_node = args.required_field_alt(n_id, while_statement::CONDITION)?;
build_while_statement_node(args, n_id, block, Some(conditional_node)).map(Some)
}