Skip to content
Documentation

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:

  1. Files
  2. Comments
  3. Components
  4. Properties
  5. Values and types
  6. The locked properties: id, visible, disabled, label
  7. Declaration blocks
  8. Bindings
  9. What is not allowed
  10. Indentation and layout of the file

1. Files

  • A .lucu file 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; .lucc means 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:column is 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, so text = "-- 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, Text are 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-prop fail with Invalid 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 is Expected a value after '='.

5. Values and types

Every property value is either a literal or a binding:

Literal formMeaningExample
"…"A string. Escapes: \", \\, \n. Any other backslash escape is an error (Unknown escape '\q' in string).text = "Hello\nline two"
true / falseBooleansvisible = false
integerA whole numbercount = 12
decimalA number containing a dot. The written scale is preserved exactly (2.50 stays 2.50 — Luca Code exact-decimal semantics)ratio = -3.50
noneThe absent value; occupies any typemissing = none
bare identifierA binding to a state variabletext = 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 with Invalid 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.

PropertyRule
idOptional 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.
visibleOptional; 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.
disabledOptional; must be a boolean (or a binding resolving to one). An ordinary property; how "disabled" presents is a backend concern.
labelOptional; 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
BlockPurposeDetails
layout:Platform-independent layout entriesStyling and theming
style:Platform-independent style entriesStyling and theming
state:Typed scalar variablesState and events
events:event = handler routing declarationsState 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 = value entries — 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, align and background, 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_field where text_field holds a string fails at the binding with Property '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 writeRejected 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 keyssame 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 is Expected 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(), no show(), no set_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/flush on 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 string
    • bool — true/false
    • int — whole number
    • dec — number with a dot, exact scale (2.50 keeps scale 2)
    • uni — inferred when the initial value is none; a uni variable accepts any later value
  • Duplicate declarations fail: Duplicate state 'visits' (first at 3:5).
  • Assignments never silently convert: int does not implicitly become dec. Storing Value::Int in a dec variable fails Expected dec, found int for state …. (Luca Code's explicit-conversion change is available in your .lucc logic.)
  • 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, text obtains the committed value of title.
  • 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 title were an int, visible = title would fail with Property '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
  • set stages an update. Type-checks happen immediately at the declaration site, so errors are caught at the change site; nothing is committed yet.
  • flush commits 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).
  • set of 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 tap with 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:

MistakeMessage
No such component idNo component with id 'missing'
Component with no events: blockComponent 'greeting' declares no events
Event not declared on that componentComponent '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:

  1. Dispatch the event on the component id → obtain the handler name.
  2. Run the handler logic through the Luca Code seam (luca_ui::seam::run_logic — see below).
  3. Apply results with State::set, then State::flush (batched, coalesced).
  4. 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.rs does 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 (LifecycleDiff lists 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