1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! Core AST model for competitive-programming problem specifications.
//!
//! `cp-ast-core` models an input format as two cooperating trees:
//!
//! - [`structure`] describes the shape of the input: scalars, arrays, matrices,
//! tuples, repeated blocks, choices, sections, and holes.
//! - [`constraint`] attaches semantic facts to those nodes: numeric ranges,
//! expected value types, distinctness, sortedness, string character sets,
//! rendering hints, and similar problem-statement constraints.
//!
//! Most applications use [`operation::AstEngine`] as the main entry point. It
//! stores both trees and applies high-level [`operation::Action`] values that
//! are convenient for editors and other interactive tools.
//!
//! # Public API Map
//!
//! - [`structure`] - AST node IDs, node kinds, references, literals, and the
//! arena-backed [`structure::StructureAst`].
//! - [`constraint`] - constraint expressions, IDs, and
//! [`constraint::ConstraintSet`].
//! - [`operation`] - mutation API centered on [`operation::AstEngine`].
//! - [`projection`] - UI-friendly read models, including
//! [`projection::project_full`].
//! - [`render`] - deterministic text rendering for input formats and
//! constraints.
//! - [`render_tex`] - deterministic TeX/KaTeX rendering.
//! - [`sample`] - deterministic sample input generation from an AST.
//!
//! # Example
//!
//! Build a tiny input format for `N` followed by an array `A` of length `N`:
//!
//! ```
//! use cp_ast_core::constraint::{Constraint, ExpectedType, Expression};
//! use cp_ast_core::operation::AstEngine;
//! use cp_ast_core::render::render_input;
//! use cp_ast_core::structure::{Ident, NodeKind, Reference};
//!
//! let mut engine = AstEngine::new();
//! let n = engine.structure.add_node(NodeKind::Scalar {
//! name: Ident::new("N"),
//! });
//! let a = engine.structure.add_node(NodeKind::Array {
//! name: Ident::new("A"),
//! length: Expression::Var(Reference::VariableRef(n)),
//! });
//!
//! let root = engine.structure.add_node(NodeKind::Sequence {
//! children: vec![n, a],
//! });
//! engine.structure.set_root(root);
//! engine.constraints.add(
//! Some(n),
//! Constraint::TypeDecl {
//! target: Reference::VariableRef(n),
//! expected: ExpectedType::Int,
//! },
//! );
//!
//! let rendered = render_input(&engine);
//! assert!(rendered.starts_with("N\nA_1"));
//! ```
//!
//! For JSON roundtrips and browser integration, pair this crate with
//! `cp-ast-json` and `cp-ast-wasm`.
/// Constraint AST types and storage.
/// High-level mutation API for building and editing AST documents.
/// UI-friendly read projections derived from AST documents.
/// Plain-text rendering helpers.
/// TeX and KaTeX rendering helpers.
/// Deterministic sample input generation.
/// Structure AST types and storage.