Core concepts
Two references in one: the full surface syntax of a .lucu file, and the model that makes UI output derive from state. Luca UI 1.0.3 Beta: the locked behaviors are stable for the 1.0 generation; the exact spelling of some blocks is still a labeled assumption (◐) that may change before 1.0 stable.
The .lucu language
Contents:
- Files
- Comments
- Components
- Properties
- Values and types
- The locked properties: id, visible, disabled, label
- Declaration blocks
- Bindings
- What is not allowed
- Indentation and layout of the file
1. Files
- A
.lucufile is one UI declaration: exactly one root component, with children nested under it (● locked: a single-root tree). - The CLI refuses every source that does not end in
.lucu;.luccmeans Luca Code logic and never goes through this parser (● locked boundary). See the CLI reference. - Every failure is a source-located diagnostic:
Error at line:column: message(● locked — see the diagnostics catalog).line:columnis 1-based and counts characters, not bytes (Unicode-safe: a file containingこんにちはstill gets correct columns).
2. Comments
Two comment forms, matching Luca Code (● locked):
-- Everything from `--` to end of line is ignored (outside a string).
[[ this spans
multiple lines ]]
--comments are stripped outside double-quoted strings, sotext = "-- hi"is the string"-- hi", not a comment.- An unterminated
[[is an error:Unterminated multiline comment, located at the[[. - Multiline comments keep line numbers intact (the parser preserves the content after the comment).
3. Components
Every component is one line ending with a colon:
App:
Text:
...
MyWidget:
- The name is an identifier: ASCII letters, digits, and
_, starting with a letter or_.App,Button,Textare registered; every other name is accepted as an unregistered component (the component vocabulary is open). - Nesting is expressed by indentation (spaces only — see §10).
- A component at column 1 when the root already exists is a second root — error:
Expected a single root component per .lucu file. - The root itself must start at column 1: an indented first line fails with
Root component must start at column 1.
4. Properties
Properties are key = value lines that belong to the component they are indented under:
App:
id = "app"
visible = true
custom_note = "anything"
- The key is an identifier (names like
my-propfail withInvalid property name 'my-prop'). - Duplicates are errors:
Duplicate property 'text' on component 'Text' (first at 3:3). - The property name must be written before
=on one line;text =with no value isExpected a value after '='.
5. Values and types
Every property value is either a literal or a binding:
| Literal form | Meaning | Example |
|---|---|---|
"…" | A string. Escapes: \", \\, \n. Any other backslash escape is an error (Unknown escape '\q' in string). | text = "Hello\nline two" |
true / false | Booleans | visible = false |
| integer | A whole number | count = 12 |
| decimal | A number containing a dot. The written scale is preserved exactly (2.50 stays 2.50 — Luca Code exact-decimal semantics) | ratio = -3.50 |
none | The absent value; occupies any type | missing = none |
| bare identifier | A binding to a state variable | text = title |
Types of state variables are the Luca Code types: str, bool, int, dec, and uni (inferred when a state entry is none).
- Strings never span lines; a missing closing quote is
Unterminated string literal. - Malformed numbers (
1.2.3) fail withInvalid value '1.2.3'.
6. The locked properties: id, visible, disabled, label
Four property names are locked (●): the toolchain enforces their type everywhere they appear, on registered and unregistered components alike.
| Property | Rule |
|---|---|
id | Optional on every component. A non-empty unique string; duplicates across the tree fail: Duplicate id 'a' (first at 2:3); ids must be unique for tests. Ids are the addressing mechanism — tests, events, and navigation address components by id only. |
visible | Optional; must be a boolean (or a binding resolving to one). Absent visible means shown. When it is false, the component and its whole subtree are skipped entirely by every backend. There is no hide() — visibility is always just this property. |
disabled | Optional; must be a boolean (or a binding resolving to one). An ordinary property; how "disabled" presents is a backend concern. |
label | Optional; must be a string (or a binding resolving to one). The explicit accessible label — when present, it wins over text inference (see below). |
Accessibility from these (● locked): every component's accessible label is either its explicit label, or — only when there is no label — its string text, inferred automatically. Missing labels are perfectly valid; not every component needs one. Platform mapping of labels is part of the backend adapter milestone (○ not implemented).
7. Declaration blocks
Six block names attach to a component and each may appear at most once per component:
App:
id = "app"
layout:
gap = 2
style:
tone = "soft"
state:
title = "Luca UI"
events:
tap = record_visit
| Block | Purpose | Details |
|---|---|---|
layout: | Platform-independent layout entries | Styling and theming |
style: | Platform-independent style entries | Styling and theming |
state: | Typed scalar variables | State and events |
events: | event = handler routing declarations | State and events |
transitions: | Declarative animation entries (reduced-motion aware) | Styling and theming |
theme: | Theme selection (name, mode) | Styling and theming |
Block rules shared by all six:
- Must live inside a component; one written at the file root is rejected:
`layout` must belong to a component. - Hold only
key = valueentries — nesting a component inside a block fails:Only `key = value` entries are allowed inside `state` (found component 'Text'). - A duplicated block fails (
Duplicate 'layout' block on component 'App'), and a duplicated entry within a block fails naming the first location (Duplicate 'gap' in `layout` block of component 'App' (first at 3:5)). layout:/style:entry names are structurally validated (identifier keys, scalar values, no duplicates). The visual pipeline interprets the documented ◐ subset —direction,gap,padding,width,height,alignandbackground,color,border,radius,font_size— and leaves every other entry opaque. Invalid values for recognized entries become non-fatal render warnings, never parse errors. See Styling and theming.
8. Bindings
A bare-identifier value is a binding to a state variable:
App:
id = "app"
state:
title = "Luca UI"
Text:
id = "t"
text = title
Rules:
- The name must be declared in some
state:block in the tree; otherwise the binding site reports'title' is not declared. - Locked property rules apply to the resolved value:
visible = text_fieldwheretext_fieldholds a string fails at the binding withProperty 'visible' must be bool, found str. - Bindings are allowed on component properties only;
state:initial values must be literals (this keeps declaration order-free).layout:/style:entries bind like component props and carry no locked type checks; the visual pipeline applies its documented ◐ expectations to recognized entries and reports mismatches as non-fatal render warnings, while unknown entries stay opaque. - A binding resolves to a value only — never to a component reference (● locked: no component references exist in the model).
9. What is not allowed
Every line below is a compile-time Luca error:
| You write | Rejected message |
|---|---|
hide() / show() / set_text = "hi" | Imperative component operation 'hide' is not supported; update state and allow the UI to react |
text = greet("hi") (call-shaped value) | Imperative component operations are not supported; update state and allow the UI to react |
hide = true / show = false / set_text keys | same imperative-operation message |
Why: Luca UI is deliberately declarative (● locked design). You cannot command a component; you change state, and components that bind to it re-render. There is no component-mutation API anywhere — set/flush on state is the only path a change takes.
10. Indentation and layout of the file
App:
id = "app"
Text:
id = "greeting"
text = "Hello, Luca!"
- Indentation is spaces; tabs are rejected:
Tabs are not allowed for indentation; use spaces. - The root component must start at column 1 (
Root component must start at column 1); a second column-1 component isExpected a single root component per .lucu file. - Levels are lenient but deterministic: any deeper indentation under a parent opens a child level; you do not have to use consistent multiples of any number. Properties and components belong to the most recent component line above them with smaller indentation.
- Once an indent level exists, later lines may return to it. The flagged errors cover the pathological cases only (
Property outside a component,Inconsistent indentation).
State and events — 1.0.3 Beta
Luca UI 1.0.3 Beta. This section explains how UI output is derived from state, and how user interactions route to Luca Code logic. It is the conceptual heart of Luca UI. All outputs are verified with
luca-ui 1.0.3 Beta.
What you will learn:
- What
state:blocks declare and how types work. - How bindings make components react to state.
- The batched update model (
set→flush). - The
events:block and the four-step wiring contract for running Luca Code logic in response to interaction. - Lifecycle: tree swaps, listener pruning, and scoped-task cancellation.
The central rule
UI output derives from state. There is no
hide(), noshow(), noset_text()— no component-mutation API at all (● locked). Components read state through bindings; when state changes and the tree is re-resolved, output changes.set/flushon state is the only path a change takes.
1. Declaring state with state: blocks
A state: block lives inside a component and declares variables:
App:
id = "app"
state:
title = "Luca UI"
visits = 2
ratio = 2.50
show_detail = true
missing = none
Rules:
- Literal values only — a state initial value must be written as a literal, never as a binding (
State initial values must be literals (found reference 'b')). This keeps declarations order-free: it never matters whether a state line appears before or after the names it would reference. - Every state variable is scalar (collections are not accepted:
State 'x' must be a scalar value in 0.4). - Types are inferred and enforced:
str— quoted stringbool—true/falseint— whole numberdec— number with a dot, exact scale (2.50keeps scale2)uni— inferred when the initial value isnone; aunivariable accepts any later value
- Duplicate declarations fail:
Duplicate state 'visits' (first at 3:5). - Assignments never silently convert:
intdoes not implicitly becomedec. StoringValue::Intin adecvariable failsExpected dec, found int for state …. (Luca Code's explicit-conversionchangeis available in your.lucclogic.) - State variables declared anywhere in the tree go into one shared store, keyed by variable name.
2. Bindings: how components react
A bare identifier in a property is a binding to that state variable:
Text:
id = "title"
text = title
- When the tree is resolved against committed state,
textobtains the committed value oftitle. - The name must be declared somewhere in the tree, or resolution fails at the binding site:
'title' is not declared. - Locked property typing applies to the resolved value: if
titlewere anint,visible = titlewould fail withProperty 'visible' must be bool, found int. - Bindings are values, never component references (● locked — no component references exist).
What "re-resolve" means
Output is not a stream; it is a function. Given the tree and the committed state,
resolve_tree(tree, state) → resolved output
produces a fresh resolved tree in which every binding is a concrete Value. Nothing else in the model mutates output — re-rendering simply means resolving again (and rendering the new resolved tree).
3. Updates are batched: set and flush
The update model is two-step:
state.set("visits", Value::Int(n + 1))?; // stage (type-checked now)
state.flush(); // commit + notify together
state.pending_count() == 0; // after flush, the batch is empty
setstages an update. Type-checks happen immediately at the declaration site, so errors are caught at the change site; nothing is committed yet.flushcommits every staged update at once and emits notifications: one notification per subscribed component per changed key, holding the final value.- Repeated sets of one key coalesce to the final value:
set(x, 1) → set(x, 2) → flush()is exactly one committed change (x = 2). setof an undeclared name fails immediately:'visits' is not declared.
This batching is locked design (● locked): a long handler logic can make dozens of state changes and produce exactly one update round.
4. Events: the interaction boundary
Events as the interaction boundary are locked (●); the events: block spelling is a labeled assumption. A component declares, in one events: block, that certain events route to handler names:
Button:
id = "visit"
text = "Visit"
events:
tap = record_visit
- The right-hand side must be a bare identifier — a handler name (literals are rejected:
Event 'tap' handler must be a Luca Code handler name, found str). - One
events:block per component. - Events are names, and each component declares its own; two components may both declare
tapwith different handlers.
dispatch returns a name, not a call
Dispatch validates and routes:
let routed = luca_ui::dispatch(&tree, "visit", "tap")?;
assert_eq!(routed.handler, "record_visit");
Dispatch carries three names — component_id, event, handler — and never a component reference. Errors, all source-located Luca errors:
| Mistake | Message |
|---|---|
| No such component id | No component with id 'missing' |
Component with no events: block | Component 'greeting' declares no events |
| Event not declared on that component | Component 'visit' declares no event 'swipe' |
Dispatch intentionally does not run anything. It is routing, not execution.
5. Wiring events to logic (the intended contract)
This contract is the working, intended wiring (◐ assumption — awaiting the full design record, like all event execution details). The full flow — demonstrated in tests/events.rs and the examples/events*.{lucu,lucc} pair (all of them run in CI) — is:
- Dispatch the event on the component id → obtain the handler name.
- Run the handler logic through the Luca Code seam (
luca_ui::seam::run_logic— see below). - Apply results with
State::set, thenState::flush(batched, coalesced). - Re-resolve and re-render the tree from the committed state.
No automatic event-to-state system exists, and none is planned for the 1.0 generation — an application host (or future app framework) brings logic and state together. In practice:
- Tests use
TestHarness::tap(id, event), which performs step 1 and hands back the handler name. - Application code performs steps 1–4 itself, exactly like the repository's
tests/events.rsdoes end-to-end.
Why not automatic? (open)
Automatically executing .lucc handlers directly from UI events requires an event-execution protocol between the two languages (argument passing, result application, error policy). That protocol awaits the design record; this release deliberately implements the smaller, composable contract above.
6. Lifecycle swaps: Runtime
Runtime owns a tree, its state, the set of mounted component ids, and component-scoped tasks.
let mut runtime = Runtime::new(tree)?; // declares state, mounts ids
let diff = runtime.update_tree(new_tree)?;
// diff.mounted / diff.unmounted
On every tree swap:
- Newly declared state merges in; existing variables keep their committed values — state outlives any single tree.
- Components present before but absent now are unmounted; new ids are mounted (
LifecycleDifflists both, sorted). - Listeners of unmounted ids are pruned so their pending notifications are never emitted.
- Tasks scoped to unmounted components are cancelled (● locked: component-scoped async work dies with the component).
- Scoping work to a component that is not mounted is an error:
Cannot scope work to unmounted component 'x'.
○ Not implemented: an async executor. A ScopedTask is a labeled unit with a cancellation flag; actual executors arrive with the platform/adapter milestone.
7. What the diagnostics look like
Every failure in this area is a cataloged Luca error, frozen in the diagnostics catalog:
Error at 1:1: 'missing' is not declared
Error at 6:7: Duplicate state 'a' (first at 3:5)
Error at 3:5: Expected int, found str for state 'visits'
Where next
- Backends & rendering — the resolution + rendering path every backend shares.
- CLI reference — the
inspectdevelopment tool. - Examples —
state.lucu,events.lucuwith verified output.