---
title: "Lexical rules"
description: "The notation uses = for a production, | for alternatives, [ … ] for optional syntax, { … } for repetition, and quoted text for literal tokens."
modificationDate: "2026-11-30"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Lexical rules

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/reference/contract-grammar/lexical-rules: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

The notation uses `=` for a production, `|` for alternatives, `[ … ]` for optional
syntax, `{ … }` for repetition, and quoted text for literal tokens. `NL`, `INDENT`,
and `DEDENT` describe logical line boundaries. `block(X)` means an indented run of
`X` entries, `NL [ INDENT { X } DEDENT ]`; blank and comment-only lines do not
count as entries. Most bodies may be empty (a shape, a style, `props`, an action,
a `for` body, a `case` arm, a test). The bodies of `if`/`else`,
a `keyframes` or `font` block, and a component need at least one entry.

- A UTF-8 file may begin with one byte order mark (U+FEFF). Formatting preserves
  it; source spans count its three bytes in the first line's columns.
- A name starts with `[A-Za-z_]`, followed by ASCII alphanumerics/underscores or
  a hyphen immediately followed by an ASCII letter. Thus `font-size` is a name,
  `a-b` is a name, and `a - b` is subtraction.
- Number tokens begin with a digit. A dot is part of the number only when a
  digit follows (`12`, `12.5`), so `rows.0.steps` is a list index and then a
  field. An exponent is part of the number only when digits follow its `e` or
  `E` and optional sign (`1e300`, `2.5E-3`, `4e+2`), so `2em` is a number and a
  unit; one past the largest double is refused. A number right after `.` is a
  list index, digits only, so `rows.1.0` is two indexes. Numeric parsing
  rejects invalid spellings. Negative values are unary minus applied to a number; as an
  attribute's whole value (`min=-40`, `step=-0.5`, `margin-top=-8`,
  `min=-1e300`) it is the negative literal, the number it is, as `40` is, and
  a text field's `min`, `max` and `step` take a number of either sign as a
  range's do. Separators, leading-dot numbers, and a trailing dot are not
  supported forms. Units belong in quoted strings.
- Strings use `"…"`. Their escapes are `\n`, `\t`, `\"`, `\\`, ``\` ``, `\$`,
  and a Unicode code point in hex, as JavaScript and Swift write it: `\u{2011}`
  (one to six digits; `\u{1F600}`, never a surrogate pair) or `\u2011` (four).
  Any other is refused, naming these. Single quotes are not delimiters.
- Templates use backticks and `${expression}`. Spaces around the expression are
  optional: `${ a }` and `${a}` mean the same. Interpolation scanning balances
  nested braces, strings, and templates. A template is one physical source line.
  An attribute template made of literal strings and constant numbers is checked as
  the resulting string. Write `line-height=(28 / 17)` for a multiplier. For a
  length, write `width=n` in pixels or give the template a unit, as in
  `` width=`${n}rem` ``. A template containing only number holes still produces text.
  Template text takes a string's escapes (`` `${a}\t${b}` `` is a tab), and
  `\${` is literal text, not an interpolation.
- A hex color may be written bare, as CSS writes it: `#` and 3, 4, 6 or 8 hex
  digits (`color=#1f9d62`, a keyframe's `background-color=#1f9d6244`) is the
  string `"#1f9d62"`, and the formatter prints it quoted. Any other `#` is
  refused, saying so.
- `//` starts a line comment outside a string/template. No block comments;
  `#` is not a comment.
- Indentation uses spaces; a tab in indentation is refused. At bracket depth zero, indentation emits
  block tokens. Inside `()`, `[]`, and `{}`, newlines and indentation continue
  the logical expression instead.
- No statement semicolons, single-quoted literals, JSX, or arbitrary braces for
  value interpolation. `{}` belongs to inline option-match syntax, not objects.

The lexer reserves no separate keyword token kind. Sixteen words are reserved,
and only where a name is bound ([`names.rs`](https://github.com/expo/exact/blob/41ded8c5ede0b2959ef0daa83b1ff78545dd4428/contract/syntax/src/parser/names.rs),
LLP 1088 D5): `when`, `if`, `else`, `for`, `in`, `match`, `case`, `as`, `fn`,
`and`, `or`, `not`, `true`, `false`, `none`, `some`. A binder is a component's
props, injects and provided names; states, derives, resources, mutations and actions; action and
`fn` parameters and `fn` names; `let`, a `for` item and index, `case some(x)`,
an arrow parameter; and a shape name (a shape name builds the shape, so
`shape none` is refused). There a reserved word is refused as "`in` is reserved
in Contract (it shapes an expression); choose another name", and is never a value.

Every other keyword is contextual: a keyword only where its construct starts, a
name at every binder and in every expression. They are `component`, `font`,
`shape`, `style`, `from`, `state`, `derive`, `resource`, `mutation`, `action`,
`task`, `mount`, `view`, `props`, `provide`, `inject`, `slot`, `children`, `key`,
`queue`, `refresh`, `writes`, `test` and `expect`. `refresh`, like `send` and `let`, begins
a statement only before a name, so `action refresh`, `press=refresh` and
`refresh feed` each have one parse. Shape fields, named arguments
(`Flags(none=1)`), members after `.` and attribute names (SVG's `in`) admit every
word.
