Constants, Tokens & Attribute Bags
Immutable let tokens, attribute bags with ... spread, anti-tuple sub-attributes, 2-tier scoping, arithmetic, and ${TOKEN} interpolation.
The let keyword declares immutable compile-time constants, design tokens, and reusable attribute presets across all four pillars. Tokens use UPPER_SNAKE_CASE and always end with a semicolon (E004).
Scalar Values vs. Attribute Bags
| Inferred Type | Example Literals | Valid Target Slots |
|---|---|---|
| Numeric (int / f64) | 40, 12.5, 3 | Spatial gaps, dimensions, offsets, grid columns, stroke widths |
| Duration | 50ms, 2s, 500us | Timed arrows ([min: ..., max: ..., timeout: ...]), timing delays |
| Color | #1a73e8, #fff, "#1e1e2e" | theme properties (fill, stroke, border, color) |
| String | "checkout", "v2.4" | Labels, phase titles, string interpolation (${TOKEN}) |
| Boolean | true, false | Flags (hidden, strict, pii) |
| AttributeBag | [gap: 40, align: center] | Spread unpacking targets ([...PRESET]) |
Spread Unpacking (...) & Anti-Tuple Rule
Multi-axis properties strictly require explicit key-value sub-bags like gap: [col: 70, row: 30]—anonymous tuples like (70, 30) are rejected (E001). Reuse attribute bags with the spread operator (...); keys listed after a spread override matching keys from the preset.
layout {
let WIDE_GRID = [
gap: [col: 70, row: 30],
align: center
];
branch matrix_a: grid [...WIDE_GRID];
branch matrix_b: grid [...WIDE_GRID, align: left]; // align overridden to left
}2-Tier Lexical Scoping & Type Safety
- Tier 1 (Diagram-Root Scope): Declared directly inside the diagram body and visible across all four pillars (schema, flow, layout, theme).
- Tier 2 (Block-Local Scope): Declared inside schema { }, layout { }, or theme { } and strictly encapsulated to that block (E197 if referenced outside). Inner tokens may shadow Tier 1 tokens.
- No Exports (Zero pub let): Design tokens are private to their diagram file; pub let is forbidden (E001).
Arithmetic & String Interpolation (${TOKEN})
Numeric tokens support compile-time arithmetic (+, -, *, /) with automatic int-to-f64 promotion, and any scalar token can be embedded into display strings with ${TOKEN} (escape literal sequences with \${...}).
diagram "Telemetry Pipeline" {
let BASE_GAP = 40;
let TIMEOUT_SLA = 50ms;
let SERVICE_NAME = "AuthService";
schema {
node rounded @Ingest [label: "Ingest -> ${SERVICE_NAME}"];
node @Kafka;
}
flow {
Ingest -> Kafka: "timeout=${TIMEOUT_SLA}" [timeout: TIMEOUT_SLA];
}
layout {
let WIDE_GAP = BASE_GAP * 1.5; // Evaluates to 60.0
reference pipeline: row [gap: WIDE_GAP, align: middle] {
node @Ingest;
node @Kafka;
}
}
}