Skip to main content
For the complete documentation index, see llms.txt

Compact grammar

Compact language version 0.26.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 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 ;.

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.nat representing major and minor versions or nat.nat.nat representing major, minor, and bugfix versions. Where version literals are allowed, a plain nat representing just the major version is also allowed.

Compact​

Program-element​

Pragma​

pragma-form⟶pragma id version-expr ;

Version-expression​

Version-expression0​

Version-Term​

Version-atom​

version-atom⟶nat
|version

Include​

include-form⟶include file ;

Module-definition​

module-definition⟶exportopt module module-name gparamsopt { program-element ⋯ program-element }

Generic-parameter-list​

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

Generic-parameter​

generic-param⟶# tvar-name
|tvar-name

Import-declaration​

import-form⟶import import-selectionopt import-name gargsopt import-prefixopt ;

Import-selection​

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

Import-element​

import-element⟶id
|id as id

Import-name​

import-name⟶id
|file

Import-prefix​

import-prefix⟶prefix id

Generic-argument-list​

gargs⟶< garg , ⋯ , garg ,opt >

Generic-argument​

garg⟶nat
|type

Export-declaration​

export-form⟶export { id , ⋯ , id ,opt } ;opt

Ledger-declaration​

ledger-declaration⟶exportopt sealedopt ledger id : type ;

Witness-declaration​

witness-declaration⟶exportopt witness id gparamsopt simple-parameter-list : type ;

Constructor​

constructor-definition⟶constructor pattern-parameter-list block

Circuit-definition​

circuit-definition⟶exportopt pureopt circuit function-name gparamsopt pattern-parameter-list : type block

Structure-declaration​

struct-declaration⟶exportopt struct struct-name gparamsopt { typed-id ; ⋯ ; typed-id ;opt } ;opt
|exportopt struct struct-name gparamsopt { typed-id , ⋯ , typed-id ,opt } ;opt

Enum-declaration​

enum-declaration⟶exportopt enum enum-name { id , ⋯¹ , id ,opt } ;opt

Contract-Implements-declaration​

implements-declaration⟶contract implements type ;

External-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⟶pureopt circuit id simple-parameter-list : type

Type-declaration​

type-alias-declaration⟶exportopt newopt type type-name gparamsopt = type ;

Typed-identifier​

typed-id⟶id : type

Simple-parameter-list​

simple-parameter-list⟶( typed-id , ⋯ , typed-id ,opt )

Typed-pattern​

typed-pattern⟶pattern : type

Pattern-parameter-list​

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

Type​

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

Type-reference​

tref⟶id gargsopt

Type-size​

tsize⟶nat
|id
start⟶tsize
end⟶tsize

Block​

block⟶{ stmt ⋯ stmt }

Statement​

stmt⟶if ( expr-seq ) stmt
|stmt0

Statement0​

stmt0⟶expr-seq ;
|const cbinding , ⋯¹ , cbinding ;
|if ( expr-seq ) stmt0 else stmt
|for ( const id of start .. end ) stmt
|for ( const id of expr-seq ) stmt
|return expr-seq ;
|return ;
|block

Pattern​

pattern⟶id
|[ patternopt , ⋯ , patternopt ,opt ]
|{ pattern-struct-elt , ⋯ , pattern-struct-elt ,opt }

Pattern-struct-element​

pattern-struct-elt⟶id
|id : pattern

Expression-sequence​

expr-seq⟶expr
|expr , ⋯¹ , expr , expr

Expression​

Expression0​

expr0⟶expr0 || expr1
|expr1

Expression1​

expr1⟶expr1 && expr2
|expr2

Expression2​

expr2⟶expr2 == expr3
|expr2 != expr3
|expr3

Expression3​

Expression4​

expr4⟶expr4 as type
|expr5

Expression5​

Expression6​

expr6⟶expr6 * expr7
|expr7

Expression7​

expr7⟶! expr7
|expr8

Expression8​

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

Expression9​

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 [ bytes-arg , ⋯ , bytes-arg ,opt ]
|tref { struct-arg , ⋯ , struct-arg ,opt }
|assert ( expr , str )
|emit ( expr )
|disclose ( expr )
|term

Term​

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

Tuple-argument​

tuple-arg⟶expr
|... expr
bytes-arg⟶tuple-arg

Structure-argument​

struct-arg⟶expr
|id : expr
|... expr

Function​

Return-type​

return-type⟶: type

Optionally-typed-pattern​

optionally-typed-pattern⟶pattern
|typed-pattern

Const-Binding​

Arrow-parameter-list​

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