Compact grammar
Compact language version 0.21.0.
Notational note: In the grammar below, terminals are in monospaced font. Non-terminals are in emphasized font. Alternation is indicated by a vertical bar (|). Optional items are indicated by the superscript opt. Repetition is specified by ellipses. 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 literal comma, represents zero or more occurrences of X separated by commas. 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 comma 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. The rules involving commas apply equally to semicolons, i.e., apply when , is replaced by ;.
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-element (pelt)
Pragma (pragma-form)
| 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)
Include (include-form)
| 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)
Import-declaration (import-form)
| 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-name (import-name)
Import-prefix (import-prefix)
| import-prefix | ⟶ | prefix id |
Generic-argument-list (gargs)
Generic-argument (garg)
Export-declaration (export-form)
Ledger-declaration (ledger-declaration)
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)
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)
Typed-identifier (typed-identifier)
Simple-parameter-list (simple-parameter-list)
| simple-parameter-list | ⟶ | ( typed-identifier , ⋯ , typed-identifier ,opt ) |
Typed-pattern (typed-pattern)
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)
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 ] | |
| | | { pattern-struct-elt , ⋯ , pattern-struct-elt ,opt } |
Pattern-struct-element (pattern-struct-elt)
Expression-sequence (expr-seq)
Expression (expr)
Expression0 (expr0)
Expression1 (expr1)
Expression2 (expr2)
Expression3 (expr3)
Expression4 (expr4)
Expression5 (expr5)
Expression6 (expr6)
Expression7 (expr7)
Expression8 (expr8)
Expression9 (expr9)
| expr9 | ⟶ | fun ( expr , ⋯ , expr ,opt ) |
| | | map ( fun , expr , ⋯¹ , expr ,opt ) | |
| | | fold ( fun , expr , expr , ⋯¹ , expr ,opt ) | |
| | | slice < tsize > ( expr , expr ) | |
| | | [ tuple-arg , ⋯ , tuple-arg ,opt ] | |
| | | Bytes [ tuple-arg , ⋯ , tuple-arg ,opt ] | |
| | | tref { struct-arg , ⋯ , struct-arg ,opt } | |
| | | assert ( expr , str ) | |
| | | disclose ( expr ) | |
| | | term |
Term (term)
Tuple-argument (tuple-arg, bytes-arg)
Structure-argument (struct-arg)
Function (fun)
| fun | ⟶ | id gargsopt |
| | | arrow-parameter-list return-typeopt => block | |
| | | arrow-parameter-list return-typeopt => expr | |
| | | ( fun ) |
Return-type (return-type)
| return-type | ⟶ | : type |
Optionally-typed-pattern (optionally-typed-pattern)
| optionally-typed-pattern | ⟶ | pattern |
| | | typed-pattern |
Const-Binding (cbinding)
| cbinding | ⟶ | optionally-typed-pattern = expr |
Arrow-parameter-list (arrow-parameter-list)
| arrow-parameter-list | ⟶ | ( optionally-typed-pattern , ⋯ , optionally-typed-pattern ,opt ) |