Skip to content

Syntax overview

An informal reference, not a normative grammar. When in doubt, the parser is the source of truth (internal/parser).

Reserved across all syntactic positions:

function var let use as
if else while for break continue return
true false boolean void string
i8 i16 i32 i64 u8 u16 u32 u64 usize f32 f64
switch case default
struct enum type
import pub const
match when
defer arena

Line comments only, introduced by //. The formatter preserves their original position.

// Header comment.
function main(): i32 {
var x: i32 = 7; // Trailing comment.
return x;
}

Highest to lowest, evaluated left-to-right within each level except where noted.

PrecedenceOperatorsAssociativity
1 (highest)(...) f(...) a[i] a.f e? e as Tleft
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

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.

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.