Skip to main content

cp_ast_core/structure/
node_kind.rs

1use super::node_id::NodeId;
2use super::reference::Reference;
3use super::types::{Ident, Literal, NodeKindHint};
4use crate::constraint::Expression;
5
6/// The kind of structure node in a competitive programming problem specification.
7///
8/// Rev.1: Rich variants with embedded data. Type and separator info
9/// moved to `ConstraintAST` (`TypeDecl`, `RenderHint`).
10#[derive(Debug, Clone, PartialEq)]
11pub enum NodeKind {
12    /// Single variable: N, M, S, etc.
13    Scalar { name: Ident },
14    /// 1D array: `A_1` ... `A_N`.
15    Array { name: Ident, length: Expression },
16    /// 2D grid, such as `C[i][j]` or `A_{i,j}`.
17    Matrix {
18        name: Ident,
19        rows: Reference,
20        cols: Reference,
21    },
22    /// Same-line variable group: (N, M, K), (`u_i`, `v_i`).
23    Tuple { elements: Vec<NodeId> },
24    /// Variable-dependent repetition: M lines, T test cases.
25    Repeat {
26        count: Expression,
27        index_var: Option<Ident>,
28        body: Vec<NodeId>,
29    },
30    /// Semantically delimited block: header + body.
31    Section {
32        header: Option<NodeId>,
33        body: Vec<NodeId>,
34    },
35    /// Ordered root of the entire input.
36    Sequence { children: Vec<NodeId> },
37    /// Tag-dependent branching (query type variants).
38    Choice {
39        tag: Reference,
40        variants: Vec<(Literal, Vec<NodeId>)>,
41    },
42    /// Unfilled position (first-class hole).
43    Hole { expected_kind: Option<NodeKindHint> },
44}