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

Grammar (Informal EBNF)

Informal sketch of the public surface. The authoritative grammar is cambrian-transpiler/src/cambrian.lalrpop.

Program        ::= TopLevel*

TopLevel       ::= ImportFile
                 | UseDecl
                 | PureFn
                 | TypeAlias
                 | RecordDecl
                 | EnumDecl
                 | Entity
                 | ExternEntity
                 | EventDecl
                 | ErrorDecl
                 | LibraryDecl
                 | UsingDecl
                 | TestDecl
                 | PropertyDecl
                 | InvariantDecl

ImportFile     ::= "import" StringLit
UseDecl        ::= "use" Ident
Entity         ::= "entity" Ident "{" EntityItem* "}"
ExternEntity   ::= SolidityImport? "extern" "entity" Ident "{" ExternRoute* "}"
SolidityImport ::= "@solidity_import" "(" StringLit ")"

EntityItem     ::= Const | Macro | RecordDecl | EnumDecl | EventDecl | ErrorDecl
                 | RoutesBlock | Member

RoutesBlock    ::= "routes" "{" Route* "}"
Route          ::= RouteKind Ident "(" Params ")" ReturnType? From? Where? "=>" Body
RouteKind      ::= /* empty */ | "view" | "pure" | "init" | "private" | "accept"
ReceiveRoute   ::= "accept" "receive" "(" ")" "=>" Body
FallbackRoute  ::= "fallback" "(" ")" "=>" Body
Body           ::= "[" Action* "]" | PhasedBody

Action         ::= Send | Deploy | Emit | Throw | Return | Let | IfActions
                 | VarCall | CallRoute | ForActions | …

Send           ::= Message? "~>" Expr SendOpts?
VarCall        ::= "var" Ident "=" Message "~>" Expr
CallRoute      ::= "call" Ident "(" Args ")"
ForActions     ::= "for" Pattern "in" Iter "=>" "[" Action* "]"
Emit           ::= "emit" Ident "(" Args ")"
Deploy         ::= "deploy" Ident DeployArgs? SendOpts?

Member         ::= Ident ":" Type "{" Transform* "}"
Transform      ::= "in" Ident "(" Pats ")" "=>" Expr
                 | PhaseTag ":" Expr

Expr           ::= … | "for" Pat "in" Iter "{" Expr "}" | "if" … | "match" …

PropertyDecl   ::= "property" StringLit "(" Params ")" "for" Ident With? Ctx? "{" PropBody "}"
TestDecl       ::= "test" StringLit "for" Ident ("skip" "from")? With? "{" TestStep* "}"
Expect         ::= "expect" "state" "{" Field ":" Expr,* "}"
                 | "expect" "return" Expr                 // equality (`E` or `== E`)
                 | "expect" "return" "." Path "==" Expr   // equality lens
                 | "expect" Expr                          // boolean predicate
InvariantDecl  ::= "invariant" StringLit "for" InvariantTarget Attr* "{" InvBody "}"

Phased routes, match arms, collection literals, and iterator chains follow the forms shown in the Language Guide. TVM-only constructs (gosh::, rescue / recover, …) are not part of the public documentation surface.

See also Keywords and Operator Precedence.