Compact language version 0.21.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 , ... , X, where X is a grammar symbol and , is a separator, represents zero or more occurrences of X separated by ,. 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 ,opt, 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. There are two separators: comma and semicolon.
end-of-file (eof)
end of file
identifier (id, module-name, function-name, struct-name, enum-name, contract-name, tvar-name, type-name)
identifiers have the same syntax as Typescript identifiers
field-literal (nat)
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
string-literal (str, file)
a string literal has the same syntax as a Typescript string
version-literal (version)
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
Compact (program)
| | |
|---|
| program | → | pelt … pelt eof |
Program-element (pelt)
| | |
|---|
| pelt | → | pragma-form |
| | → | module-definition |
| | → | import-form |
| | → | export-form |
| | → | include-form |
| | → | struct-declaration |
| | → | enum-declaration |
| | → | contract-declaration |
| | → | type-alias-declaration |
| | → | ledger-declaration |
| | → | witness-declaration |
| | → | constructor-definition |
| | → | circuit-definition |
| | |
|---|
| pragma-form | → | pragma id version-expr ; |
Version-expression (version-expr)
| | |
|---|
| version-expr | → | version-expr || version-expr0 |
| | → | version-expr0 |
Version-expression0 (version-expr0)
| | |
|---|
| version-expr0 | → | version-expr0 && version-term |
| | → | version-term |
Version-Term (version-term)
| | |
|---|
| version-term | → | version-atom |
| | → | ! version-atom |
| | → | < version-atom |
| | → | <= version-atom |
| | → | >= version-atom |
| | → | > version-atom |
| | → | ( version-expr ) |
Version-atom (version-atom)
| | |
|---|
| version-atom | → | nat |
| | → | version |
| | |
|---|
| include-form | → | include file ; |
Module-definition (module-definition)
| | |
|---|
| module-definition | → | exportopt module module-name gparamsopt { pelt … pelt } |
Generic-parameter-list (gparams)
| | |
|---|
| gparams | → | < generic-param , … , generic-param ,opt > |
Generic-parameter (generic-param)
| | |
|---|
| generic-param | → | # tvar-name |
| | → | tvar-name |
| | |
|---|
| import-form | → | import import-selectionopt import-name gargsopt import-prefixopt ; |
Import-selection (import-selection)
| | |
|---|
| import-selection | → | { import-element , … , import-element ,opt } from |
Import-element (import-element)
| | |
|---|
| import-element | → | id |
| | → | id as id |
Import-name (import-name)
Import-prefix (import-prefix)
| | |
|---|
| import-prefix | → | prefix id |
Generic-argument-list (gargs)
| | |
|---|
| gargs | → | < garg , … , garg ,opt > |
Generic-argument (garg)
| | |
|---|
| export-form | → | export { id , … , id ,opt } ;opt |
Ledger-declaration (ledger-declaration)
| | |
|---|
| ledger-declaration | → | exportopt sealedopt ledger id : type ; |
Witness-declaration (witness-declaration)
| | |
|---|
| witness-declaration | → | exportopt witness id gparamsopt simple-parameter-list : type ; |
Constructor (constructor-definition)
| | |
|---|
| constructor-definition | → | constructor pattern-parameter-list block |
Circuit-definition (circuit-definition)
| | |
|---|
| circuit-definition | → | exportopt pureopt circuit function-name gparamsopt pattern-parameter-list : type block |
Structure-declaration (struct-declaration)
| | |
|---|
| struct-declaration | → | exportopt struct struct-name gparamsopt { typed-identifier ; … ; typed-identifier ;opt } ;opt |
| | → | exportopt struct struct-name gparamsopt { typed-identifier , … , typed-identifier ,opt } ;opt |
Enum-declaration (enum-declaration)
| | |
|---|
| enum-declaration | → | exportopt enum enum-name { id , …¹ , id ,opt } ;opt |
External-contract-declaration (contract-declaration)
| | |
|---|
| contract-declaration | → | exportopt contract contract-name { circuit-declaration ; … ; circuit-declaration ;opt } ;opt |
| | → | exportopt contract contract-name { circuit-declaration , … , circuit-declaration ,opt } ;opt |
External-contract-circuit (circuit-declaration)
| | |
|---|
| circuit-declaration | → | pureopt circuit id simple-parameter-list : type |
Type-declaration (type-alias-declaration)
| | |
|---|
| type-alias-declaration | → | exportopt newopt type type-name gparamsopt = type ; |
Typed-identifier (typed-identifier)
| | |
|---|
| typed-identifier | → | id : type |
Simple-parameter-list (simple-parameter-list)
| | |
|---|
| simple-parameter-list | → | ( typed-identifier , … , typed-identifier ,opt ) |
Typed-pattern (typed-pattern)
| | |
|---|
| typed-pattern | → | pattern : type |
Pattern-parameter-list (pattern-parameter-list)
| | |
|---|
| pattern-parameter-list | → | ( typed-pattern , … , typed-pattern ,opt ) |
Type (type)
| | |
|---|
| type | → | tref |
| | → | Boolean |
| | → | Field |
| | → | Uint < tsize > |
| | → | Uint < tsize .. tsize > |
| | → | Bytes < tsize > |
| | → | Opaque < str > |
| | → | Vector < tsize , type > |
| | → | [ type , … , type ,opt ] |
Type-reference (tref)
Type-size (tsize)
Block (block)
Statement (stmt)
| | |
|---|
| stmt | → | if ( expr-seq ) stmt |
| | → | stmt0 |
Statement0 (stmt0)
| | |
|---|
| stmt0 | → | expr-seq ; |
| | → | const cbinding , …¹ , cbinding ; |
| | → | if ( expr-seq ) stmt0 else stmt |
| | → | for ( const id of nat .. nat ) stmt |
| | → | for ( const id of expr-seq ) stmt |
| | → | return expr-seq ; |
| | → | return ; |
| | → | block |
Pattern (pattern)
| | |
|---|
| pattern | → | id |
| | → | [ patternopt , … , patternopt ,opt ] |
| | → | |