Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Operator Precedence

Expression operators bind as in cambrian-transpiler/src/cambrian.lalrpop (lowest to highest). All listed binary operators are left-associative.

LevelOperatorsNotes
0|params| body / lo..hiClosure / range — only as a whole expression (call argument, for iterator), never inside another operator
1||Logical or
2&&Logical and
3|Bitwise or
4^Bitwise xor — not temporal ^member
5&Bitwise and
6== !=Equality
7< > <= >=Ordering
8<< >>Shifts
9+ - +% -%Checked / wrapping add & sub
10* / % *%Checked / wrapping mul, div, mod
11as TypeCast (chains left: x as u64 as U256). The target must be a simple type name, not a generic like Vec<u8>
12! - *Unary not, negation, dereference
13.field .method() .0 [index]Postfix access (.0, .1 index a tuple)
14PrimaryLiterals, ^member, @macro(), msg::, sys::, calls

Comparisons bind tighter than the bitwise operators, so a & mask == 0 parses as a & (mask == 0). Parenthesise: (a & mask) == 0.

Ranges

FormWhere
lo..hiExclusive range: for i in 0..n, fuzz bindings p in lo..hi, bound p in lo..hi
lo..=hiInclusive range: only in fuzz instance bindings (fuzz { p in 1..=100 }) and bound p in lo..=hi

Closures

|x| expr, |x| { block }, |x| if c { a } else { b } and |x| Rec { … } are accepted as arguments of iterator methods (.map, .filter, .fold). A closure can’t be stored or returned as a value.

Not expression operators

These appear in routes, transforms, or actions — they do not participate in the expression precedence chain above:

FormRole
=>Route body, transform, match arm, action-level for / if
~>Send / transfer action
with { … }Send / deploy options after ~>
| in from A(…) : throw E() | B(…) : throw E()Separates from alternatives
&& in where c1 : throw 1 && c2 : throw 2Chains where clauses, each with its own : throw
: in c : throw NAttaches the failure to a where / from clause

Temporal ^member

^m_count is parsed as a primary expression (prefix on a member name). It is unrelated to bitwise xor between two ordinary expressions.

Send options use with { value: … } after ~> dest. See Send Messages.

For the full grammar, see cambrian-transpiler/src/cambrian.lalrpop (ExprOr through ExprPrimary).