Compact language version 0.14.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. For example, id … id represents zero or more ids, and expr , …¹ , expr represents one or more comma-separated exprs.
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-term | |
→ | < 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 > |
generic-param | → | # tvar-name |
→ | tvar-name |
idecl | → | import import-name gargsopt prefixopt ; |
import-name | → | id |
→ | file |
gargs | → | < garg , … , garg > |
prefix | → | prefix id |
export | → | export |
sealed | → | sealed |
pure | → | pure |
xdecl | → | export { id , … , id } ;opt |
ldecl | → | exportopt sealedopt ledger id : type ; |
lconstructor | → | constructor ( parg , … , parg ) block ;opt |
cdefn | → | exportopt pureopt circuit function-name gparamsopt ( parg , … , parg ) : type block |
edecl | → | exportopt circuit id gparamsopt ( arg , … , arg ) : type ; |
wdecl | → | exportopt witness id gparamsopt ( arg , … , arg ) : type ; |
ecdecl | → | exportopt contract contract-name { ecdecl-circuit … ecdecl-circuit } ;opt |
ecdecl-circuit | → | pureopt circuit id ( arg , … , arg ) : type ; |
struct | → | exportopt struct struct-name gparamsopt { arg ; … ; arg ;opt } ;opt |
→ | exportopt struct struct-name gparamsopt { arg , … , arg ,opt } ;opt |
enumdef | → | exportopt enum enum-name { id , …¹ , id ,opt } ;opt |
arg | → | id : type |
parg | → | pattern : type |
type | → | tref |
→ | Boolean | |
→ | Field | |
→ | Uint < tsize > | |
→ | Uint < tsize .. tsize > | |
→ | Bytes < tsize > | |
→ | Opaque < str > | |
→ | Vector < tsize , type > | |
→ | [ type , … , type ] |
tref | → | id gargsopt |
tsize | → | nat |
→ | id |
garg | → | nat |
→ | type |
block | → | { stmt … stmt } |
stmt | → | expr = expr ; |
→ | expr += expr ; | |
→ | expr -= expr ; | |
→ | 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 | |
→ | assert expr str ; | |
→ | const pattern = expr ; | |
→ | const pattern : type = expr ; | |
→ | block |
pattern | → | id |
→ | [ pattern-tuple-elt , … , pattern-tuple-elt ] | |
→ | { pattern-struct-elt , … , pattern-struct-elt } |
pattern-tuple-elt | → | (empty) |
→ | pattern |
pattern-struct-elt | → | id |
→ | id : pattern |
expr-seq | → | expr |
→ | expr , …¹ , expr , expr |
expr | → | expr0 ? expr : 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 ) | |
→ | term |
term | → | lit |
→ | default < type > | |
→ | map ( fun , expr , …¹ , expr ) | |
→ | fold ( fun , expr , expr , …¹ , expr ) | |
→ | fun ( expr , … , expr ) | |
→ | disclose ( expr ) | |
→ | tref { struct-arg , … , struct-arg } | |
→ | [ expr , … , expr ,opt ] | |
→ | id | |
→ | ( expr-seq ) |
lit | → | true |
→ | false | |
→ | nat | |
→ | str | |
→ | pad ( nat , str ) |
struct-arg | → | expr |
→ | id : expr | |
→ | ... expr |
fun | → | id gargsopt |
→ | ( pattern-or-parg , … , pattern-or-parg ) return-type-declopt => block | |
→ | ( pattern-or-parg , … , pattern-or-parg ) return-type-declopt => expr | |
→ | ( fun ) |
return-type-decl | → | : type |
pattern-or-parg | → | pattern |
→ | parg |