use alloc::borrow::ToOwned;
use crate::query::label_text;
use crate::syntax::builders::binary_operation::build_binary_operation_node;
use crate::syntax::fields::go::binary_expression;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::NodeId;
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let left_id = args.required_field_alt(n_id, binary_expression::LEFT)?;
let right_id = args.required_field_alt(n_id, binary_expression::RIGHT)?;
let operator_id = args.required_field_alt(n_id, binary_expression::OPERATOR)?;
let operator = label_text(graph, operator_id)
.ok_or(SyntaxGraphError::UnexpectedAstShape)?
.to_owned();
build_binary_operation_node(args, n_id, operator, Some(left_id), Some(right_id)).map(Some)
}