-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathleo.abnf
549 lines (394 loc) · 15.8 KB
/
leo.abnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
; Copyright (C) 2019-2023 Aleo Systems Inc.
; Copyright (C) 2024 Provable Inc.
; This file is part of the Leo library.
; The Leo library is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
; The Leo library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
; You should have received a copy of the GNU General Public License
; along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This file specifies the grammar of Leo in the ABNF notation,
; which is defined in:
; - RFC 5234 (https://www.rfc-editor.org/rfc/rfc5234)
; - RFC 7405 (https://www.rfc-editor.org/rfc/rfc7405)
; Leo files are written in Unicode, encoded in UTF-8.
; The grammar in this file applies to the Unicode scalar values
; that result from the UTF-8 decoding of the files.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Lexical Grammar
; ---------------
ascii = %x00-7F
safe-nonascii = %x80-2029 / %x202F-2065 / %x206A-D7FF / %xE000-10FFFF
; excludes bidi embeddings/overrides/isolates
; (i.e. %x202A-202E and %x2066-2069)
; and excludes high/low surrogates
; (i.e. %xD800-DFFF )
character = ascii / safe-nonascii
line-terminator = line-feed / carriage-return line-feed
line-feed = %x0A
carriage-return = %x0D
whitespace = space
/ horizontal-tab
/ form-feed
/ line-terminator
/ carriage-return ; not followed by line feed
space = %x20
horizontal-tab = %x09
form-feed = %x0C
comment = block-comment / line-comment
block-comment = "/*" rest-of-block-comment
rest-of-block-comment =
"*" rest-of-block-comment-after-star
/ not-star-or-line-feed rest-of-block-comment
/ line-terminator rest-of-block-comment
rest-of-block-comment-after-star =
"/"
/ "*" rest-of-block-comment-after-star
/ not-star-or-slash-or-line-feed rest-of-block-comment
/ line-terminator rest-of-block-comment
not-star-or-line-feed = %x00-09
; no line feed (%x0A)
/ %x0B-29
; no * (%x2A)
/ %x2B-7E
/ safe-nonascii
not-star-or-slash-or-line-feed = %x00-09
; no line feed (%x0A)
/ %x0B-29
; no * (%x2A)
/ %x2B-2E
; no / (%x2F)
/ %x30-7E
/ safe-nonascii
line-comment = "//" *not-line-feed line-terminator
not-line-feed = %x00-09
; no line feed (%x0A)
/ %x0B-7F
/ safe-nonascii
keyword = %s"address"
/ %s"aleo"
/ %s"as"
/ %s"assert"
/ %s"assert_eq"
/ %s"assert_neq"
/ %s"async"
/ %s"block"
/ %s"bool"
/ %s"const"
/ %s"constant"
/ %s"else"
/ %s"field"
/ %s"Fn"
/ %s"for"
/ %s"function"
/ %s"Future"
/ %s"group"
/ %s"i8"
/ %s"i16"
/ %s"i32"
/ %s"i64"
/ %s"i128"
/ %s"if"
/ %s"import"
/ %s"in"
/ %s"inline"
/ %s"let"
/ %s"mapping"
/ %s"network"
/ %s"private"
/ %s"program"
/ %s"public"
/ %s"record"
/ %s"return"
/ %s"scalar"
/ %s"self"
/ %s"signature"
/ %s"string"
/ %s"struct"
/ %s"transition"
/ %s"u8"
/ %s"u16"
/ %s"u32"
/ %s"u64"
/ %s"u128"
uppercase-letter = %x41-5A ; A-Z
lowercase-letter = %x61-7A ; a-z
letter = uppercase-letter / lowercase-letter
binary-digit = %x30-31 ; 0-1
octal-digit = %x30-37 ; 0-7
decimal-digit = %x30-39 ; 0-9
nonzero-decimal-digit = %x31-39 ; 1-9
hexadecimal-digit = decimal-digit
/ %x41-46 ; A-F (uppercase)
; no a-f (lowercase)
identifier = letter *( letter / decimal-digit / "_" )
; but not a keyword or a boolean literal or aleo1...
binary-numeral = %s"0b" 1*( binary-digit *"_" )
octal-numeral = %s"0o" 1*( octal-digit *"_" )
decimal-numeral = 1*( decimal-digit *"_" )
hexadecimal-numeral = %s"0x" 1*( hexadecimal-digit *"_" )
numeral = binary-numeral
/ octal-numeral
/ decimal-numeral
/ hexadecimal-numeral
tuple-index = "0" / nonzero-decimal-digit *( decimal-digit )
; i.e. decimal-numeral without extra leading zeros
unsigned-literal = numeral ( %s"u8" / %s"u16" / %s"u32" / %s"u64" / %s"u128" )
signed-literal = numeral ( %s"i8" / %s"i16" / %s"i32" / %s"i64" / %s"i128" )
integer-literal = unsigned-literal
/ signed-literal
field-literal = decimal-numeral %s"field"
product-group-literal = decimal-numeral %s"group"
scalar-literal = decimal-numeral %s"scalar"
numeric-literal = integer-literal
/ field-literal
/ product-group-literal
/ scalar-literal
boolean-literal = %s"true" / %s"false"
explicit-address-literal = %s"aleo1" 58( lowercase-letter / decimal-digit )
string-literal = double-quote *string-character double-quote
double-quote = %x22
string-character = not-double-quote-or-line-feed
/ line-terminator
not-double-quote-or-line-feed = %x00-09
; no line feed (%x0A)
/ %x0B-21
; no double quote (%x22)
/ %x23-7F
/ safe-nonascii
atomic-literal = numeric-literal
/ boolean-literal
/ explicit-address-literal
/ string-literal
annotation = "@" identifier
symbol = "!"
/ "&&" / "||"
/ "==" / "!="
/ "<" / "<=" / ">" / ">="
/ "&" / "|" / "^"
/ "<<" / ">>"
/ "+" / "-" / "*" / "/" / "%" / "**"
/ "="
/ "+=" / "-=" / "*=" / "/=" / "%=" / "**="
/ "<<=" / ">>="
/ "&=" / "|=" / "^="
/ "&&=" / "||="
/ "(" / ")"
/ "[" / "]"
/ "{" / "}"
/ "," / "." / ".." / ";" / ":" / "::" / "?"
/ "->" / "=>" / "_"
/ %s")group"
token = keyword
/ identifier
/ atomic-literal
/ decimal-numeral
/ annotation
/ symbol
lexeme = token / comment / whitespace
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Syntactic Grammar
; -----------------
program-id = identifier "." network
network = %s"aleo"
locator = program-id "/" identifier
unsigned-type = %s"u8" / %s"u16" / %s"u32" / %s"u64" / %s"u128"
signed-type = %s"i8" / %s"i16" / %s"i32" / %s"i64" / %s"i128"
integer-type = unsigned-type / signed-type
field-type = %s"field"
group-type = %s"group"
scalar-type = %s"scalar"
arithmetic-type = integer-type / field-type / group-type / scalar-type
boolean-type = %s"bool"
address-type = %s"address"
signature-type = %s"signature"
string-type = %s"string"
named-primitive-type = boolean-type
/ arithmetic-type
/ address-type
/ signature-type
/ string-type
unit-type = "(" ")"
primitive-type = named-primitive-type / unit-type
untyped-future-type = %s"Future"
typed-future-type =
%s"Future" "<" %s"Fn" "(" [ type 1*( "," type ) [ "," ] ] ")" ">"
future-type = untyped-future-type / typed-future-type
tuple-type = "(" type 1*( "," type ) [ "," ] ")"
array-type = "[" type ";" decimal-numeral "]"
type = primitive-type
/ future-type
/ tuple-type
/ array-type
named-type = named-primitive-type
/ untyped-future-type
/ identifier
group-coordinate = ( [ "-" ] decimal-numeral ) / "+" / "-" / "_"
affine-group-literal = "(" group-coordinate "," group-coordinate %s")group"
program-address-literal = program-id
literal = atomic-literal
/ affine-group-literal
/ program-address-literal
group-literal = product-group-literal / affine-group-literal
address-literal = explicit-address-literal / program-address-literal
primary-expression = literal
/ variable
/ locator
/ associated-constant
/ "(" expression ")"
/ free-function-call
/ associated-function-call
/ unit-expression
/ tuple-expression
/ array-expression
/ struct-expression
/ self-expression
/ block-expression
/ network-expression
variable = identifier
associated-constant = named-type "::" identifier
free-function-call = identifier function-arguments
/ locator function-arguments
associated-function-call = named-type "::" identifier function-arguments
function-arguments = "(" [ expression *( "," expression ) [ "," ] ] ")"
unit-expression = "(" ")"
tuple-expression = "(" expression 1*( "," expression ) [ "," ] ")"
array-expression = "[" expression 1*( "," expression ) [ "," ] "]"
struct-expression = identifier "{" struct-component-initializer
*( "," struct-component-initializer )
[ "," ] "}"
struct-component-initializer = identifier
/ identifier ":" expression
self-expression = %s"self" "." %s"address"
/ %s"self" "." %s"caller"
/ %s"self" "." %s"signer"
block-expression = %s"block" "." %s"height"
network-expression = %s"network" "." %s"id"
postfix-expression = primary-expression
/ tuple-component-expression
/ array-component-expression
/ struct-component-expression
/ method-call
tuple-component-expression = postfix-expression "." tuple-index
array-component-expression = postfix-expression "[" expression "]"
struct-component-expression = postfix-expression "." identifier
method-call = postfix-expression "." identifier function-arguments
unary-expression = postfix-expression
/ "!" unary-expression
/ "-" unary-expression
cast-expression = unary-expression
/ unary-expression %s"as" named-primitive-type
exponential-expression = cast-expression
/ cast-expression "**" exponential-expression
multiplicative-expression = exponential-expression
/ multiplicative-expression "*" exponential-expression
/ multiplicative-expression "/" exponential-expression
/ multiplicative-expression "%" exponential-expression
additive-expression = multiplicative-expression
/ additive-expression "+" multiplicative-expression
/ additive-expression "-" multiplicative-expression
shift-expression = additive-expression
/ shift-expression "<<" additive-expression
/ shift-expression ">>" additive-expression
conjunctive-expression = shift-expression
/ conjunctive-expression "&" shift-expression
inclusive-disjunctive-expression =
conjunctive-expression
/ inclusive-disjunctive-expression "|" conjunctive-expression
exclusive-disjunctive-expression =
inclusive-disjunctive-expression
/ exclusive-disjunctive-expression "^" inclusive-disjunctive-expression
ordering-expression =
exclusive-disjunctive-expression
/ exclusive-disjunctive-expression "<" exclusive-disjunctive-expression
/ exclusive-disjunctive-expression ">" exclusive-disjunctive-expression
/ exclusive-disjunctive-expression "<=" exclusive-disjunctive-expression
/ exclusive-disjunctive-expression ">=" exclusive-disjunctive-expression
equality-expression = ordering-expression
/ ordering-expression "==" ordering-expression
/ ordering-expression "!=" ordering-expression
conditional-conjunctive-expression =
equality-expression
/ conditional-conjunctive-expression "&&" equality-expression
conditional-disjunctive-expression =
conditional-conjunctive-expression
/ conditional-disjunctive-expression "||" conditional-conjunctive-expression
binary-expression = conditional-disjunctive-expression
conditional-ternary-expression = binary-expression
/ binary-expression "?" expression ":" expression
expression = conditional-ternary-expression
statement = expression-statement
/ return-statement
/ variable-declaration
/ constant-declaration
/ conditional-statement
/ loop-statement
/ assignment-statement
/ block
expression-statement = expression ";"
block = "{" *statement "}"
return-statement = %s"return" [ expression ] ";"
variable-declaration = %s"let" identifier-or-identifiers ":" type
"=" expression ";"
constant-declaration = %s"const" identifier ":" type "=" expression ";"
identifier-or-identifiers = identifier
/ "(" identifier 1*( "," identifier ) [ "," ] ")"
branch = %s"if" conditional-ternary-expression block
conditional-statement = branch
/ branch %s"else" block
/ branch %s"else" conditional-statement
loop-statement = %s"for" identifier ":" type
%s"in" expression ".." expression
block
assignment-operator = "="
/ "+="
/ "-="
/ "*="
/ "/="
/ "%="
/ "**="
/ "<<="
/ ">>="
/ "&="
/ "|="
/ "^="
/ "&&="
/ "||="
assignment-statement = expression assignment-operator expression ";"
assert-statement = %s"assert" "(" expression ")" ";"
/ %s"assert_eq" "(" expression "," expression ")" ";"
/ %s"assert_neq" "(" expression "," expression ")" ";"
function-declaration = *annotation [ %s"async" ] function-kind identifier
"(" [ function-inputs ] ")"
[ "->" function-outputs ]
( block / ";" )
function-kind = %s"function" / %s"transition" / %s"inline"
function-inputs = function-input *( "," function-input ) [ "," ]
function-input = [ %s"public" / %s"private" / %s"constant" ]
identifier ":" type
function-outputs = function-output
/ "(" [ function-output *( "," function-output ) [ "," ] ] ")"
function-output = [ %s"public" / %s"private" / %s"constant" ] type
struct-declaration = %s"struct" identifier
"{" struct-component-declarations "}"
struct-component-declarations = struct-component-declaration
*( "," struct-component-declaration )
[ "," ]
struct-component-declaration =
[ %s"public" / %s"private" / %s"constant" ] identifier ":" type
record-declaration = %s"record" identifier
"{" struct-component-declarations "}"
mapping-declaration = %s"mapping" identifier ":" type "=>" type ";"
program-item = function-declaration
/ struct-declaration
/ record-declaration
/ mapping-declaration
/ constant-declaration
program-declaration = %s"program" program-id "{" *program-item "}"
import-declaration = %s"import" program-id ";"
file = *import-declaration program-declaration