use crate::query::{adj_ast, match_ast_d};
use crate::syntax::builders::switch_statement::build_switch_statement_node;
use crate::syntax::fields::Field;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::NodeId;
const INITIALIZER: Field<false> = Field::new("initializer_id");
const VALUE: Field<false> = Field::new("value_id");
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let body_id = match_ast_d(graph, n_id, "switch", None)
.or_else(|| adj_ast(graph, n_id, None, &[]).first().copied())
.ok_or(SyntaxGraphError::UnexpectedAstShape)?;
let value_id = args
.optional_field_alt(n_id, INITIALIZER)
.or_else(|| args.optional_field_alt(n_id, VALUE))
.or_else(|| adj_ast(graph, n_id, None, &[]).get(2).copied())
.ok_or(SyntaxGraphError::UnexpectedAstShape)?;
build_switch_statement_node(args, n_id, body_id, value_id).map(Some)
}