Operator Precedence
Expression operators bind as in cambrian-transpiler/src/cambrian.lalrpop
(lowest to highest). All listed binary operators are left-associative.
| Level | Operators | Notes |
|---|---|---|
| 0 | |params| body / lo..hi | Closure / 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 |
| 11 | as Type | Cast (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) |
| 14 | Primary | Literals, ^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
| Form | Where |
|---|---|
lo..hi | Exclusive range: for i in 0..n, fuzz bindings p in lo..hi, bound p in lo..hi |
lo..=hi | Inclusive 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:
| Form | Role |
|---|---|
=> | 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 2 | Chains where clauses, each with its own : throw |
: in c : throw N | Attaches 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).