Compact language version 0.16.0.
Notational note: In the grammar productions below, ellipses are used to specify repetition. The notation X ... X, where X is a grammar symbol, represents zero or more occurrences of X. The notation X s ... s X, where X is a grammar symbol and s is a separator such as a comma or or semicolon, represents zero or more occurrences of X separated by s. In either case, when the ellipsis is marked with the superscript 1, the notation represents a sequence containing at least one X. When such a sequence is followed by sopt, an optional trailing separator is allowed, but only if there is at least one X. For example, id … id represents zero or more ids, and expr , …¹ , expr ,opt represents one or more comma-separated exprs possibly followed by an extra comma.
end of file
identifiers have the same syntax as Typescript identifiers
a field literal is 0 or a natural number formed from a sequence of digits starting with 1-9, e.g. 723, whose value does not exceed the maximum field value
a string literal has the same syntax as a Typescript string
a version literal takes the form nat or nat.nat or nat.nat.nat, e.g., 1.2 or 1.2.3, representing major, minor, and bugfix versions
program | → | pelt … pelt eof |
pelt | → | pragma |
→ | incld | |
→ | mdefn | |
→ | idecl | |
→ | xdecl | |
→ | ldecl | |
→ | lconstructor | |
→ | cdefn | |
→ | edecl | |
→ | wdecl | |
→ | ecdecl | |
→ | struct | |
→ | enumdef |
pragma | → | pragma id version-expr ; |
version-expr | → | version-expr || version-expr0 |
→ | version-expr0 |
version-expr0 | → | version-expr0 && version-term |
→ | version-term |
version-term | → | version-atom |
→ | ! version-atom | |
→ | < version-atom | |
→ | <= version-atom | |
→ | >= version-atom | |
→ | > version-atom | |
→ | ( version-expr ) |
version-atom | → | nat |
→ | version |
incld | → | include file ; |
mdefn | → | exportopt module module-name gparamsopt { pelt … pelt } |
gparams | → | < generic-param , … , generic-param ,opt > |
generic-param | → | # tvar-name |
→ | tvar-name |
idecl | → | import import-name gargsopt import-prefixopt ; |
import-name | → | id |
→ | file |
import-prefix | → | prefix id |
gargs | → | < garg , … , garg ,opt > |
garg | → | nat |
→ | type |
xdecl | → | export { id , … , id ,opt } ;opt |
ldecl | → | exportopt sealedopt ledger id : type ; |
lconstructor | → | constructor pattern-parameter-list block |
cdefn | → | exportopt pureopt circuit function-name gparamsopt pattern-parameter-list : type block |
edecl | → | exportopt circuit id gparamsopt simple-parameter-list : type ; |
wdecl | → | exportopt witness id gparamsopt simple-parameter-list : type ; |
ecdecl | → | exportopt contract contract-name { ecdecl-circuit ; … ; ecdecl-circuit ;opt } ;opt |
→ | exportopt contract contract-name { ecdecl-circuit , … , ecdecl-circuit ,opt } ;opt |
ecdecl-circuit | → | pureopt circuit id simple-parameter-list : type |
struct | → | exportopt struct struct-name gparamsopt { typed-identifier ; … ; typed-identifier ;opt } ;opt |
→ | exportopt struct struct-name gparamsopt { typed-identifier , … , typed-identifier ,opt } ;opt |
enumdef | → | exportopt enum enum-name { id , …¹ , id ,opt } ;opt |
typed-identifier | → | id : type |
simple-parameter-list | → | ( typed-identifier , … , typed-identifier ,opt ) |
typed-pattern | → | pattern : type |
pattern-parameter-list | → | ( typed-pattern , … , typed-pattern ,opt ) |
type | → | tref |
→ | Boolean | |
→ | Field | |
→ | Uint < tsize > | |
→ | Uint < tsize .. tsize > | |
→ | Bytes < tsize > | |
→ | Opaque < str > | |
→ | Vector < tsize , type > | |
→ | [ type , … , type ,opt ] |
tref | → | id gargsopt |
tsize | → | nat |
→ | id |
block | → | { stmt … stmt } |
stmt | → | expr-seq ; |
→ | return expr-seq ; | |
→ | return ; | |
→ | if ( expr-seq ) stmt else stmt | |
→ | if ( expr-seq ) stmt | |
→ | for ( const id of nat .. nat ) stmt | |
→ | for ( const id of expr-seq ) stmt | |
→ | const optionally-typed-pattern = expr ; | |
→ | block |
pattern | → | id |
→ | [ patternopt , … , patternopt ,opt ] | |
→ | { pattern-struct-elt , … , pattern-struct-elt ,opt } |
pattern-tuple-elt | → | (empty) |
→ | pattern |
pattern-struct-elt | → | id |
→ | id : pattern |
expr-seq | → | expr |
→ | expr , …¹ , expr , expr |
expr | → | expr0 ? expr : expr |
→ | expr0 = expr | |
→ | expr0 += expr | |
→ | expr0 -= expr | |
→ | expr0 |
expr0 | → | expr0 || expr1 |
→ | expr1 |
expr1 | → | expr1 && expr2 |
→ | expr2 |
expr2 | → | expr2 == expr3 |
→ | expr2 != expr3 | |
→ | expr3 |
expr3 | → | expr4 < expr4 |
→ | expr4 <= expr4 | |
→ | expr4 >= expr4 | |
→ | expr4 > expr4 | |
→ | expr4 |
expr4 | → | expr4 as type |
→ | expr5 |
expr5 | → | expr5 + expr6 |
→ | expr5 - expr6 | |
→ | expr6 |
expr6 | → | expr6 * expr7 |
→ | expr7 |
expr7 | → | ! expr7 |
→ | expr8 |
expr8 | → | expr8 [ nat ] |
→ | expr8 . id | |
→ | expr8 . id ( expr , … , expr ,opt ) | |
→ | expr9 |
expr9 | → | fun ( expr , … , expr ,opt ) |
→ | map ( fun , expr , …¹ , expr ,opt ) | |
→ | fold ( fun , expr , expr , …¹ , expr ,opt ) | |
→ | [ expr , … , expr ,opt ] | |
→ | tref { struct-arg , … , struct-arg ,opt } | |
→ | assert ( expr , str ) | |
→ | disclose ( expr ) | |
→ | term |
term | → | id |
→ | true | |
→ | false | |
→ | nat | |
→ | str | |
→ | pad ( nat , str ) | |
→ | default < type > | |
→ | ( expr-seq ) |
struct-arg | → | expr |
→ | id : expr | |
→ | ... expr |
fun | → | id gargsopt |
→ | arrow-parameter-list return-typeopt => block | |
→ | arrow-parameter-list return-typeopt => expr | |
→ | ( fun ) |
return-type | → | : type |
optionally-typed-pattern | → | pattern |
→ | typed-pattern |
arrow-parameter-list | → | ( optionally-typed-pattern , … , optionally-typed-pattern ,opt ) |