zenith_core/ast/recipe.rs
1//! Recipe block declaration AST types.
2//!
3//! The top-level `recipes` block declares named generative recipes — each
4//! `recipe` entry specifies an `id`, a generator `kind`, an optional integer
5//! `seed`, optional `generator` version/hash, an optional `bounds` frame id,
6//! an optional `detached` link state, typed `param` children, `palette` token
7//! children, and `expanded` materialized-node children. It is a sibling of the
8//! `variants`/`provenance`/`document` blocks. The engine round-trips and
9//! validates these records but does NOT act on them; expansion is deferred to
10//! a later unit.
11
12use std::collections::BTreeMap;
13
14use super::Span;
15use super::node::UnknownProperty;
16use super::value::PropertyValue;
17
18/// A single recipe declaration within a `recipes` block.
19#[derive(Debug, Clone, PartialEq)]
20pub struct RecipeDef {
21 /// The recipe's own stable id. Required.
22 pub id: String,
23 /// Generator kind (freeform string, e.g. `"aurora"`, `"scatter"`). Required.
24 pub kind: String,
25 /// Optional integer seed for deterministic generation.
26 pub seed: Option<i64>,
27 /// Optional generator version/hash string (e.g. `"aurora@1"`).
28 pub generator: Option<String>,
29 /// Optional frame/page id this recipe applies within.
30 pub bounds: Option<String>,
31 /// Optional link/detach state: `Some(false)` = linked (default), `Some(true)` = detached.
32 pub detached: Option<bool>,
33 /// Typed generation parameters; empty when no `param` children are present.
34 pub params: Vec<RecipeParam>,
35 /// Palette token ids; each comes from a `palette token="<id>"` child node.
36 pub palette: Vec<String>,
37 /// Materialized node ids; each comes from an `expanded node="<id>"` child node.
38 pub expanded: Vec<String>,
39 /// Source declaration span, when available.
40 pub source_span: Option<Span>,
41 /// Forward-compat: unrecognized attributes preserved with typed values +
42 /// annotations.
43 pub unknown_props: BTreeMap<String, UnknownProperty>,
44}
45
46/// A single typed generation parameter within a [`RecipeDef`].
47#[derive(Debug, Clone, PartialEq)]
48pub struct RecipeParam {
49 /// Parameter name. Required.
50 pub name: String,
51 /// Parameter value (number dimension, token ref, or string literal). Required.
52 pub value: PropertyValue,
53 /// Source declaration span, when available.
54 pub source_span: Option<Span>,
55 /// Forward-compat: unrecognized attributes preserved with typed values +
56 /// annotations.
57 pub unknown_props: BTreeMap<String, UnknownProperty>,
58}