Syntax overview
An informal reference, not a normative grammar. When in doubt, the
parser is the source of truth (internal/parser).
Keywords
Section titled “Keywords”Reserved across all syntactic positions:
function var let use asif else while for break continue returntrue false boolean void stringi8 i16 i32 i64 u8 u16 u32 u64 usize f32 f64switch case defaultstruct enum typeimport pub constmatch whendefer arenaComments
Section titled “Comments”Line comments only, introduced by //. The formatter preserves
their original position.
// Header comment.function main(): i32 { var x: i32 = 7; // Trailing comment. return x;}Operator precedence
Section titled “Operator precedence”Highest to lowest, evaluated left-to-right within each level except where noted.
| Precedence | Operators | Associativity |
|---|---|---|
| 1 (highest) | (...) f(...) a[i] a.f e? e as T | left |
| 2 | ! - (unary) | right |
| 3 | * / % | left |
| 4 | + - | left |
| 5 | << >> | left |
| 6 | & | left |
| 7 | ^ | left |
| 8 | | | left |
| 9 | < <= > >= | left |
| 10 | == != | left |
| 11 | && | left |
| 12 | || | left |
| 13 | |> | left |
| 14 (lowest) | = += -= *= /= etc. | right |
Block forms
Section titled “Block forms”Statements end with ; and group in { ... } blocks. Whitespace
isn’t significant.
if (cond) { ... } else { ... }— statement or expression.while (cond) { ... }— pre-test loop.for (init; cond; step) { ... }— three-part loop.match (expr) { Pat(b) => { ... }, ... }— pattern dispatch.switch (expr) { case 1: ...; default: ... }— value dispatch.defer expr;— schedule expr to run on function exit (LIFO).arena { ... }— bump-allocator scope; allocations inside reclaim on exit.
String literals
Section titled “String literals”Double-quoted, escape with \\. An f prefix introduces an
f-string with {expr} interpolation:
var name: string = "world";print(f"hello, {name}");{{ and }} escape literal braces inside an f-string.