Skip to main content

Compact grammar

Compact language version 0.22.0.

Notational note: In the grammar below, keywords and punctuation are in monospaced font. Terminal and nonterminal names 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 XX, 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, idid 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)

programpeltpelt eof

Program-element (pelt)

Pragma (pragma-form)

pragma-formpragma id version-expr ;

Version-expression (version-expr)

Version-expression0 (version-expr0)

Version-Term (version-term)

Version-atom (version-atom)

version-atomnat
|version

Include (include-form)

include-forminclude file ;

Module-definition (module-definition)

module-definitionexportopt module module-name gparamsopt { peltpelt }

Generic-parameter-list (gparams)

gparams< generic-param ,, generic-param ,opt >

Generic-parameter (generic-param)

generic-param# tvar-name
|tvar-name

Import-declaration (import-form)

import-formimport import-selectionopt import-name gargsopt import-prefixopt ;

Import-selection (import-selection)

import-selection{ import-element ,, import-element ,opt } from

Import-element (import-element)

import-elementid
|id as id

Import-name (import-name)

import-nameid
|file

Import-prefix (import-prefix)

import-prefixprefix id

Generic-argument-list (gargs)

gargs< garg ,, garg ,opt >

Generic-argument (garg)

gargnat
|type

Export-declaration (export-form)

export-formexport { id ,, id ,opt } ;opt

Ledger-declaration (ledger-declaration)

ledger-declarationexportopt sealedopt ledger id : type ;

Witness-declaration (witness-declaration)

witness-declarationexportopt witness id gparamsopt simple-parameter-list : type ;

Constructor (constructor-definition)

constructor-definitionconstructor pattern-parameter-list block

Circuit-definition (circuit-definition)

circuit-definitionexportopt pureopt circuit function-name gparamsopt pattern-parameter-list : type block

Structure-declaration (struct-declaration)

struct-declarationexportopt 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-declarationexportopt enum enum-name { id , ⋯¹ , id ,opt } ;opt

External-contract-declaration (contract-declaration)

contract-declarationexportopt 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-declarationpureopt circuit id simple-parameter-list : type

Type-declaration (type-alias-declaration)

type-alias-declarationexportopt newopt type type-name gparamsopt = type ;

Typed-identifier (typed-identifier)

typed-identifierid : type

Simple-parameter-list (simple-parameter-list)

simple-parameter-list( typed-identifier ,, typed-identifier ,opt )

Typed-pattern (typed-pattern)

typed-patternpattern : type

Pattern-parameter-list (pattern-parameter-list)

pattern-parameter-list( typed-pattern ,, typed-pattern ,opt )

Type (type)

typetref
|Boolean
|Field
|Uint < tsize >
|Uint < tsize .. tsize >
|Bytes < tsize >
|Opaque < str >
|Vector < tsize , type >
|[ type ,, type ,opt ]

Type-reference (tref)

trefid gargsopt

Type-size (tsize)

tsizenat
|id

Block (block)

block{ stmtstmt }

Statement (stmt)

stmtif ( expr-seq ) stmt
|stmt0

Statement0 (stmt0)

stmt0expr-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)

patternid
|[ patternopt ,, patternopt ,opt ]
|{ pattern-struct-elt ,, pattern-struct-elt ,opt }

Pattern-struct-element (pattern-struct-elt)

pattern-struct-eltid
|id : pattern

Expression-sequence (expr-seq)

expr-seqexpr
|expr , ⋯¹ , expr , expr

Expression (expr)

Expression0 (expr0)

expr0expr0 || expr1
|expr1

Expression1 (expr1)

expr1expr1 && expr2
|expr2

Expression2 (expr2)

expr2expr2 == expr3
|expr2 != expr3
|expr3

Expression3 (expr3)

Expression4 (expr4)

expr4expr4 as type
|expr5

Expression5 (expr5)

Expression6 (expr6)

expr6expr6 * expr7
|expr7

Expression7 (expr7)

expr7! expr7
|expr8

Expression8 (expr8)

expr8expr8 [ expr ]
|expr8 . id
|expr8 . id ( expr ,, expr ,opt )
|expr9

Expression9 (expr9)

expr9fun ( 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)

termid
|true
|false
|nat
|str
|pad ( nat , str )
|default < type >
|( expr-seq )

Tuple-argument (tuple-arg, bytes-arg)

tuple-argexpr
|... expr
bytes-argtuple-arg

Structure-argument (struct-arg)

struct-argexpr
|id : expr
|... expr

Function (fun)

Return-type (return-type)

return-type: type

Optionally-typed-pattern (optionally-typed-pattern)

optionally-typed-patternpattern
|typed-pattern

Const-Binding (cbinding)

Arrow-parameter-list (arrow-parameter-list)

arrow-parameter-list( optionally-typed-pattern ,, optionally-typed-pattern ,opt )