forked from intellij-solidity/intellij-solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solidity.bnf
699 lines (621 loc) · 33.4 KB
/
solidity.bnf
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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
{
parserClass="me.serce.solidity.SolidityParser"
psiClassPrefix="Sol"
psiImplClassSuffix="Impl"
psiPackage="me.serce.solidity.lang.psi"
psiImplPackage="me.serce.solidity.lang.psi.impl"
implements="me.serce.solidity.lang.psi.SolElement"
elementTypeHolderClass="me.serce.solidity.lang.core.SolidityTokenTypes"
elementTypePrefix=""
elementTypeClass="me.serce.solidity.lang.core.SolElementType"
tokenTypeClass="me.serce.solidity.lang.core.SolElementType"
tokenTypeClass="me.serce.solidity.lang.core.SolidityTokenTypes"
tokens = [
comment='regexp:(//.*)|(/\\*(?:.|[\\n\\r])*?\\*/)'
hexLiteral='regexp:hex"([0-9a-fA-F]+)"'
stringLiteral='regexp:("([^"\r\n\\]|\\.)*")|unicode("([^"])*")'
decimalNumber='regexp:([0-9][_0-9]*)'
fixedNumber='regexp:(([0-9][_0-9]*)+\.[_0-9]*|([0-9][_0-9]*)*\.([0-9][_0-9]*))'
scientificNumber='regexp:((([0-9][_0-9]*)+|([0-9][_0-9]*)+\.[_0-9]*|([0-9][_0-9]*|[0-9])*\.[_0-9]+)[Ee][+-]?[_0-9]+)'
hexNumber='regexp:(0[xX][_0-9a-fA-F]+)'
numberUnit='regexp:(wei|szabo|finney|ether|seconds|minutes|hours|days|weeks|years)'
intNumType='regexp:int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?'
uIntNumType='regexp:uint(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?'
byteNumType='regexp:byte(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)?'
bytesNumType='regexp:bytes(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)?'
fixedNumType='regexp:fixed(0x8|0x16|0x24|0x32|0x40|0x48|0x56|0x64|0x72|0x80|0x88|0x96|0x104|0x112|0x120|0x128|0x136|0x144|0x152|0x160|0x168|0x176|0x184|0x192|0x200|0x208|0x216|0x224|0x232|0x240|0x248|0x256|8x8|8x16|8x24|8x32|8x40|8x48|8x56|8x64|8x72|8x80|8x88|8x96|8x104|8x112|8x120|8x128|8x136|8x144|8x152|8x160|8x168|8x176|8x184|8x192|8x200|8x208|8x216|8x224|8x232|8x240|8x248|16x8|16x16|16x24|16x32|16x40|16x48|16x56|16x64|16x72|16x80|16x88|16x96|16x104|16x112|16x120|16x128|16x136|16x144|16x152|16x160|16x168|16x176|16x184|16x192|16x200|16x208|16x216|16x224|16x232|16x240|24x8|24x16|24x24|24x32|24x40|24x48|24x56|24x64|24x72|24x80|24x88|24x96|24x104|24x112|24x120|24x128|24x136|24x144|24x152|24x160|24x168|24x176|24x184|24x192|24x200|24x208|24x216|24x224|24x232|32x8|32x16|32x24|32x32|32x40|32x48|32x56|32x64|32x72|32x80|32x88|32x96|32x104|32x112|32x120|32x128|32x136|32x144|32x152|32x160|32x168|32x176|32x184|32x192|32x200|32x208|32x216|32x224|40x8|40x16|40x24|40x32|40x40|40x48|40x56|40x64|40x72|40x80|40x88|40x96|40x104|40x112|40x120|40x128|40x136|40x144|40x152|40x160|40x168|40x176|40x184|40x192|40x200|40x208|40x216|48x8|48x16|48x24|48x32|48x40|48x48|48x56|48x64|48x72|48x80|48x88|48x96|48x104|48x112|48x120|48x128|48x136|48x144|48x152|48x160|48x168|48x176|48x184|48x192|48x200|48x208|56x8|56x16|56x24|56x32|56x40|56x48|56x56|56x64|56x72|56x80|56x88|56x96|56x104|56x112|56x120|56x128|56x136|56x144|56x152|56x160|56x168|56x176|56x184|56x192|56x200|64x8|64x16|64x24|64x32|64x40|64x48|64x56|64x64|64x72|64x80|64x88|64x96|64x104|64x112|64x120|64x128|64x136|64x144|64x152|64x160|64x168|64x176|64x184|64x192|72x8|72x16|72x24|72x32|72x40|72x48|72x56|72x64|72x72|72x80|72x88|72x96|72x104|72x112|72x120|72x128|72x136|72x144|72x152|72x160|72x168|72x176|72x184|80x8|80x16|80x24|80x32|80x40|80x48|80x56|80x64|80x72|80x80|80x88|80x96|80x104|80x112|80x120|80x128|80x136|80x144|80x152|80x160|80x168|80x176|88x8|88x16|88x24|88x32|88x40|88x48|88x56|88x64|88x72|88x80|88x88|88x96|88x104|88x112|88x120|88x128|88x136|88x144|88x152|88x160|88x168|96x8|96x16|96x24|96x32|96x40|96x48|96x56|96x64|96x72|96x80|96x88|96x96|96x104|96x112|96x120|96x128|96x136|96x144|96x152|96x160|104x8|104x16|104x24|104x32|104x40|104x48|104x56|104x64|104x72|104x80|104x88|104x96|104x104|104x112|104x120|104x128|104x136|104x144|104x152|112x8|112x16|112x24|112x32|112x40|112x48|112x56|112x64|112x72|112x80|112x88|112x96|112x104|112x112|112x120|112x128|112x136|112x144|120x8|120x16|120x24|120x32|120x40|120x48|120x56|120x64|120x72|120x80|120x88|120x96|120x104|120x112|120x120|120x128|120x136|128x8|128x16|128x24|128x32|128x40|128x48|128x56|128x64|128x72|128x80|128x88|128x96|128x104|128x112|128x120|128x128|136x8|136x16|136x24|136x32|136x40|136x48|136x56|136x64|136x72|136x80|136x88|136x96|136x104|136x112|136x120|144x8|144x16|144x24|144x32|144x40|144x48|144x56|144x64|144x72|144x80|144x88|144x96|144x104|144x112|152x8|152x16|152x24|152x32|152x40|152x48|152x56|152x64|152x72|152x80|152x88|152x96|152x104|160x8|160x16|160x24|160x32|160x40|160x48|160x56|160x64|160x72|160x80|160x88|160x96|168x8|168x16|168x24|168x32|168x40|168x48|168x56|168x64|168x72|168x80|168x88|176x8|176x16|176x24|176x32|176x40|176x48|176x56|176x64|176x72|176x80|184x8|184x16|184x24|184x32|184x40|184x48|184x56|184x64|184x72|192x8|192x16|192x24|192x32|192x40|192x48|192x56|192x64|200x8|200x16|200x24|200x32|200x40|200x48|200x56|208x8|208x16|208x24|208x32|208x40|208x48|216x8|216x16|216x24|216x32|216x40|224x8|224x16|224x24|224x32|232x8|232x16|232x24|240x8|240x16|248x8)?'
uFixedNumType='regexp:ufixed(0x8|0x16|0x24|0x32|0x40|0x48|0x56|0x64|0x72|0x80|0x88|0x96|0x104|0x112|0x120|0x128|0x136|0x144|0x152|0x160|0x168|0x176|0x184|0x192|0x200|0x208|0x216|0x224|0x232|0x240|0x248|0x256|8x8|8x16|8x24|8x32|8x40|8x48|8x56|8x64|8x72|8x80|8x88|8x96|8x104|8x112|8x120|8x128|8x136|8x144|8x152|8x160|8x168|8x176|8x184|8x192|8x200|8x208|8x216|8x224|8x232|8x240|8x248|16x8|16x16|16x24|16x32|16x40|16x48|16x56|16x64|16x72|16x80|16x88|16x96|16x104|16x112|16x120|16x128|16x136|16x144|16x152|16x160|16x168|16x176|16x184|16x192|16x200|16x208|16x216|16x224|16x232|16x240|24x8|24x16|24x24|24x32|24x40|24x48|24x56|24x64|24x72|24x80|24x88|24x96|24x104|24x112|24x120|24x128|24x136|24x144|24x152|24x160|24x168|24x176|24x184|24x192|24x200|24x208|24x216|24x224|24x232|32x8|32x16|32x24|32x32|32x40|32x48|32x56|32x64|32x72|32x80|32x88|32x96|32x104|32x112|32x120|32x128|32x136|32x144|32x152|32x160|32x168|32x176|32x184|32x192|32x200|32x208|32x216|32x224|40x8|40x16|40x24|40x32|40x40|40x48|40x56|40x64|40x72|40x80|40x88|40x96|40x104|40x112|40x120|40x128|40x136|40x144|40x152|40x160|40x168|40x176|40x184|40x192|40x200|40x208|40x216|48x8|48x16|48x24|48x32|48x40|48x48|48x56|48x64|48x72|48x80|48x88|48x96|48x104|48x112|48x120|48x128|48x136|48x144|48x152|48x160|48x168|48x176|48x184|48x192|48x200|48x208|56x8|56x16|56x24|56x32|56x40|56x48|56x56|56x64|56x72|56x80|56x88|56x96|56x104|56x112|56x120|56x128|56x136|56x144|56x152|56x160|56x168|56x176|56x184|56x192|56x200|64x8|64x16|64x24|64x32|64x40|64x48|64x56|64x64|64x72|64x80|64x88|64x96|64x104|64x112|64x120|64x128|64x136|64x144|64x152|64x160|64x168|64x176|64x184|64x192|72x8|72x16|72x24|72x32|72x40|72x48|72x56|72x64|72x72|72x80|72x88|72x96|72x104|72x112|72x120|72x128|72x136|72x144|72x152|72x160|72x168|72x176|72x184|80x8|80x16|80x24|80x32|80x40|80x48|80x56|80x64|80x72|80x80|80x88|80x96|80x104|80x112|80x120|80x128|80x136|80x144|80x152|80x160|80x168|80x176|88x8|88x16|88x24|88x32|88x40|88x48|88x56|88x64|88x72|88x80|88x88|88x96|88x104|88x112|88x120|88x128|88x136|88x144|88x152|88x160|88x168|96x8|96x16|96x24|96x32|96x40|96x48|96x56|96x64|96x72|96x80|96x88|96x96|96x104|96x112|96x120|96x128|96x136|96x144|96x152|96x160|104x8|104x16|104x24|104x32|104x40|104x48|104x56|104x64|104x72|104x80|104x88|104x96|104x104|104x112|104x120|104x128|104x136|104x144|104x152|112x8|112x16|112x24|112x32|112x40|112x48|112x56|112x64|112x72|112x80|112x88|112x96|112x104|112x112|112x120|112x128|112x136|112x144|120x8|120x16|120x24|120x32|120x40|120x48|120x56|120x64|120x72|120x80|120x88|120x96|120x104|120x112|120x120|120x128|120x136|128x8|128x16|128x24|128x32|128x40|128x48|128x56|128x64|128x72|128x80|128x88|128x96|128x104|128x112|128x120|128x128|136x8|136x16|136x24|136x32|136x40|136x48|136x56|136x64|136x72|136x80|136x88|136x96|136x104|136x112|136x120|144x8|144x16|144x24|144x32|144x40|144x48|144x56|144x64|144x72|144x80|144x88|144x96|144x104|144x112|152x8|152x16|152x24|152x32|152x40|152x48|152x56|152x64|152x72|152x80|152x88|152x96|152x104|160x8|160x16|160x24|160x32|160x40|160x48|160x56|160x64|160x72|160x80|160x88|160x96|168x8|168x16|168x24|168x32|168x40|168x48|168x56|168x64|168x72|168x80|168x88|176x8|176x16|176x24|176x32|176x40|176x48|176x56|176x64|176x72|176x80|184x8|184x16|184x24|184x32|184x40|184x48|184x56|184x64|184x72|192x8|192x16|192x24|192x32|192x40|192x48|192x56|192x64|200x8|200x16|200x24|200x32|200x40|200x48|200x56|208x8|208x16|208x24|208x32|208x40|208x48|216x8|216x16|216x24|216x32|216x40|224x8|224x16|224x24|224x32|232x8|232x16|232x24|240x8|240x16|248x8)?'
booleanLiteral='regexp:true|false'
space='regexp:\s+'
Identifier='regexp:[a-zA-Z_$][a-zA-Z_$0-9]*'
DOT='.'
COLON=':'
SEMICOLON=';'
COMMA=','
PLUS='+'
MINUS='-'
MULT='*'
DIV='/'
EXPONENT='**'
NOT='!'
ASSIGN='='
TO='=>'
EQ='=='
NEQ='!='
INC='++'
DEC='--'
PLUS_ASSIGN='+='
MINUS_ASSIGN='-='
MULT_ASSIGN='*='
DIV_ASSIGN='/='
OR_ASSIGN='|='
XOR_ASSIGN='^='
AND_ASSIGN='&='
LSHIFT_ASSIGN='<<='
RSHIFT_ASSIGN='>>='
PERCENT_ASSIGN='%='
LESS='<'
LESSEQ='<='
MORE='>'
MOREEQ='>='
CARET='^'
AND='&'
ANDAND='&&'
OR='|'
OROR='||'
LBRACKET='['
RBRACKET=']'
LBRACE='{'
RBRACE='}'
LPAREN='('
RPAREN=')'
QUESTION='?'
PERCENT='%'
TILDE='~'
LSHIFT='<<'
RSHIFT='>>'
LEFT_ASSEMBLY=':='
RIGHT_ASSEMBLY='=:'
NAT_SPEC_TAG='regexp:@[a-zA-Z_0-9:]*'
// this is a special grammar for "preview only" because grammar-kit seems to not
// support whitespaces
pragmaAll='regexp:[\^a-zA-Z_0-9.<>"]*'
]
extends(".*Expression")=Expression
extends(".*TypeName")=TypeName
}
SourceUnit ::= (
PragmaDirective
| ImportDirective
| UsingForDeclaration
| ContractDefinition
| FunctionDefinition
| ConstantVariableDeclaration
| StructDefinition
| EnumDefinition
| UserDefinedValueTypeDefinition
| ErrorDefinition
| EventDefinition
| Expression
)*
private UntilSemicolonRecover ::= !(';')
private UntilBraceRecover ::= !('}')
// Pragma actually parses anything up to the trailing ';' to be fully forward-compatible.
private PragmaPart ::= pragma Identifier pragmaAll {
pin = 2
recoverWhile = UntilSemicolonRecover
}
PragmaDirective ::= PragmaPart ';'
private ClosedBracketRecover ::= !('}')
ImportAlias ::= Identifier {
implements = "me.serce.solidity.lang.psi.SolNamedElement"
mixin = "me.serce.solidity.lang.psi.impl.SolImportAliasMixin"
stubClass = "me.serce.solidity.lang.stubs.SolImportAliasDefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
ImportAliasedPair ::= UserDefinedTypeName (as ImportAlias)?
private ImportRuleSet ::= ImportAliasedPair ( ',' ImportAliasedPair )* {
recoverWhile = ClosedBracketRecover
}
ImportPath ::= stringLiteral {
implements = "me.serce.solidity.lang.psi.SolNamedElement"
mixin = "me.serce.solidity.lang.psi.impl.SolImportPathElement"
stubClass = "me.serce.solidity.lang.stubs.SolImportPathDefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
private ImportDirectivePart ::= import
( ImportPath (as ImportAlias)?
| '*' (as ImportAlias)? 'from' ImportPath
| '{' ImportRuleSet '}' 'from' ImportPath ) {
pin = 1
recoverWhile = UntilSemicolonRecover
}
ImportDirective ::= ImportDirectivePart ';'
ContractDefinition ::= abstract? ( contract | library | interface ) Identifier
( is InheritanceSpecifier (',' InheritanceSpecifier )* )?
'{' ContractPart* '}' {
pin = 2
implements = "me.serce.solidity.lang.psi.SolContractOrLibElement"
mixin = "me.serce.solidity.lang.psi.impl.SolContractOrLibMixin"
stubClass = "me.serce.solidity.lang.stubs.SolContractOrLibDefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
private ContractPart ::=
// the of StateVariableDeclaration and FunctionDefinition is important to ensure that
// function type state variables are parsed correctly.
StateVariableDeclaration
| FunctionDefinition
| UsingForDeclaration
| StructDefinition
| ModifierDefinition
| EventDefinition
| ErrorDefinition
| EnumDefinition
| UserDefinedValueTypeDefinition
| ConstructorDefinition
InheritanceSpecifier ::= UserDefinedTypeName ( '(' Expression ( ',' Expression )* ')' )?
VisibilityModifier ::= ( public | internal | private )
MutationModifier ::= (constant | immutable)
StateVariableDeclaration ::= TypeName (MutationModifier | VisibilityModifier | OverrideSpecifier)* Identifier ('=' Expression)? ';' {
implements = "me.serce.solidity.lang.psi.SolStateVarElement"
mixin = "me.serce.solidity.lang.psi.impl.SolStateVarDeclMixin"
stubClass = "me.serce.solidity.lang.stubs.SolStateVarDeclStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
/**
* The declaration of a constant variable.
*/
ConstantVariableDeclaration ::= TypeName MutationModifier Identifier ('=' Expression)? ';' {
implements = "me.serce.solidity.lang.psi.SolConstantVariable"
mixin = "me.serce.solidity.lang.psi.impl.SolConstantVariableDeclMixin"
stubClass = "me.serce.solidity.lang.stubs.SolConstantVariableDeclStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
/**
* Operators that users are allowed to implement for some types with `using for`.
*/
private UserDefinableOperator ::=
'&'
| '~'
| '|'
| '^'
| '+'
| '/'
| '%'
| '*'
| '-'
| '=='
| '>'
| '>='
| '<'
| '<='
| '!=';
UsingForDeclaration ::= using ( UserDefinedTypeName |
'{' UserDefinedTypeName (as UserDefinableOperator)? (',' UserDefinedTypeName (as UserDefinableOperator)? )* '}' ) for ('*' | TypeName) 'global'? ';' {
pin=1
implements = "me.serce.solidity.lang.psi.SolUsingForElement"
mixin = "me.serce.solidity.lang.psi.impl.SolUsingForMixin"
}
StructDefinition ::= struct Identifier '{'
( VariableDeclaration ';' (VariableDeclaration ';')* )? '}' {
pin=1
implements = "me.serce.solidity.lang.psi.SolCallableElement"
mixin = "me.serce.solidity.lang.psi.impl.SolStructDefMixin"
stubClass = "me.serce.solidity.lang.stubs.SolStructDefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
ModifierDefinition ::= modifier Identifier ParameterList? ( VirtualSpecifier | OverrideSpecifier )* Block {
pin = 1
implements = "me.serce.solidity.lang.psi.SolModifierElement"
mixin = "me.serce.solidity.lang.psi.impl.SolModifierDefMixin"
stubClass = "me.serce.solidity.lang.stubs.SolModifierDefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
VirtualSpecifier ::= virtual {pin=1}
OverrideSpecifier ::= override ( '(' UserDefinedTypeName (',' UserDefinedTypeName)* ')' )? {pin=1}
FunctionVisibilitySpecifier ::= VisibilitySpecifier | VirtualSpecifier | OverrideSpecifier
ModifierInvocation ::= VarLiteral ('(' ModifierInvocationCallArguments ')')? {
implements = "me.serce.solidity.lang.psi.SolModifierInvocationElement"
mixin = "me.serce.solidity.lang.psi.impl.SolModifierInvocationMixin"
}
private ModifierInvocationCallArguments ::= FunctionCallArguments
ConstructorDefinition ::= constructor ParameterList
( FunctionVisibilitySpecifier | StateMutabilitySpecifier | ModifierInvocation)*
Block {
pin = 1
implements = "me.serce.solidity.lang.psi.SolHasModifiersElement"
mixin = "me.serce.solidity.lang.psi.impl.SolConstructorDefMixin"
}
FunctionDefinition ::= (function Identifier? | fallback | receive )
ParameterList
( FunctionVisibilitySpecifier | StateMutabilitySpecifier | ModifierInvocation)*
( returns ParameterList )? ( ';' | Block ) {
pin = 1
implements = "me.serce.solidity.lang.psi.SolFunctionDefElement"
mixin = "me.serce.solidity.lang.psi.impl.SolFunctionDefMixin"
stubClass = "me.serce.solidity.lang.stubs.SolFunctionDefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
EventDefinition ::= event Identifier IndexedParameterList anonymous? ';' {
pin = 1
implements = "me.serce.solidity.lang.psi.SolCallableElement"
mixin = "me.serce.solidity.lang.psi.impl.SolEventDefMixin"
stubClass = "me.serce.solidity.lang.stubs.SolEventDefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
// Note, error can't be a keyword as it could be used as e.g. a variable name
ErrorDefinition ::= 'error' Identifier IndexedParameterList ';' {
pin = 2
implements = "me.serce.solidity.lang.psi.SolCallableElement"
mixin = "me.serce.solidity.lang.psi.impl.SolErrorDefMixin"
stubClass = "me.serce.solidity.lang.stubs.SolErrorDefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
EnumValue ::= Identifier {
implements = "me.serce.solidity.lang.psi.SolEnumItemElement"
mixin = "me.serce.solidity.lang.psi.impl.SolEnumValueMixin"
}
EnumDefinition ::= enum Identifier '{' EnumValue? (',' EnumValue)* '}' {
pin = 1
implements = "me.serce.solidity.lang.psi.SolEnumDefElement"
mixin = "me.serce.solidity.lang.psi.impl.SolEnumItemImplMixin"
stubClass = "me.serce.solidity.lang.stubs.SolEnumDefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
UserDefinedValueTypeDefinition ::= type Identifier is ElementaryTypeName ';' {
pin = 1
implements = "me.serce.solidity.lang.psi.SolUserDefinedValueTypeDefElement"
mixin = "me.serce.solidity.lang.psi.impl.SolUserDefinedValueTypeDefMixin"
stubClass = "me.serce.solidity.lang.stubs.SolUserDefinedValueTypeDefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
IndexedParameterList ::= '(' ( IndexedParamDef (',' IndexedParamDef )*)? ')'
IndexedParamDef ::= TypeName indexed? Identifier?
ParameterDef ::= TypeName (constant StorageLocationSpecifier? | StorageLocationSpecifier constant?)? Identifier? {
implements = "me.serce.solidity.lang.psi.SolNamedElement"
mixin = "me.serce.solidity.lang.psi.impl.SolParameterDefMixin"
}
ParameterList ::= '(' ( ParameterDef (',' ParameterDef)* )? ')'
// semantic restriction: mappings and structs (recursively) containing mappings
// are not allowed in argument lists
// TODO these 2 definitions can be private
DeclarationItem ::= Identifier ','? | ',' {
implements = "me.serce.solidity.lang.psi.SolNamedElement"
mixin = "me.serce.solidity.lang.psi.impl.SolDeclarationItemMixin"
}
DeclarationList ::= '(' DeclarationItem* ')'
TypedDeclarationItem ::= (TypeName StorageLocationSpecifier?)? Identifier ','? | ',' {
implements = "me.serce.solidity.lang.psi.SolNamedElement"
mixin = "me.serce.solidity.lang.psi.impl.SolTypedDeclarationItemMixin"
}
TypedDeclarationList ::= '(' TypedDeclarationItem* ')' ;
// TODO: remove storage declaration from all other places
VariableDeclaration ::=
TypedDeclarationList |
var DeclarationList |
DeclarationList |
TypeName StorageLocationSpecifier? Identifier {
implements = "me.serce.solidity.lang.psi.SolNamedElement"
mixin = "me.serce.solidity.lang.psi.impl.SolVariableDeclarationMixin"
}
TypeName ::= MappingTypeName
| UserDefinedLocationTypeName
| BytesArrayTypeName
| ArrayTypeName
| ElementaryTypeName
| FunctionTypeName {
stubClass = "me.serce.solidity.lang.stubs.SolTypeRefStub"
extends = "me.serce.solidity.lang.psi.impl.SolStubbedElementImpl<?>"
}
BytesArrayTypeName ::= bytesNumType StorageLocationSpecifier? {
stubClass = "me.serce.solidity.lang.stubs.SolTypeRefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
ArrayTypeName ::= TypeName '[' Expression? ']' StorageLocationSpecifier? {
stubClass = "me.serce.solidity.lang.stubs.SolTypeRefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
UserDefinedLocationTypeName ::= UserDefinedWithLocationTypeName | UserDefinedWithoutLocationTypeName {
stubClass = "me.serce.solidity.lang.stubs.SolTypeRefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
private UserDefinedWithLocationTypeName ::= UserDefinedTypeName StorageLocationSpecifier
private UserDefinedWithoutLocationTypeName ::= UserDefinedTypeName
UserDefinedTypeName ::= Identifier ( '.' Identifier )* {
implements = "me.serce.solidity.lang.psi.SolUserDefinedTypeNameElement"
mixin = "me.serce.solidity.lang.psi.impl.SolUserDefinedTypeNameImplMixin"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
private MappingKey ::= (BytesArrayTypeName | ElementaryTypeName | UserDefinedTypeName ) Identifier?
private MappingValue ::= TypeName Identifier?
MappingTypeName ::= mapping '(' MappingKey '=>' MappingValue ')' {
pin = 1
stubClass = "me.serce.solidity.lang.stubs.SolTypeRefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
// According to grammar.txt, it should be only TypeNameList after function, but according to reality ...
FunctionTypeName ::= function ParameterList ( VisibilitySpecifier | StateMutabilitySpecifier )*
( returns ParameterList )? {
pin = 1
stubClass = "me.serce.solidity.lang.stubs.SolTypeRefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
mixin = "me.serce.solidity.lang.psi.impl.SolFunctionTypeMixin"
implements = "me.serce.solidity.lang.psi.SolFunctionTypeElement"
}
StorageLocationSpecifier ::= memory | storage | calldata
StateMutabilitySpecifier ::= pure | view | 'payable'
VisibilitySpecifier ::= private | internal | external | public
private UnfinishedUncheckedBlock ::= unchecked '{' Statement* {
pin = 1
recoverWhile = UntilBraceRecover
}
UncheckedBlock ::= UnfinishedUncheckedBlock '}'
private UnfinishedBlock ::= '{' (UncheckedBlock | Statement)* {
pin = 1
recoverWhile = UntilBraceRecover
}
Block ::= UnfinishedBlock '}'
private FinishedStatement ::=
DoWhileStatement
| PlaceholderStatement
| ContinueSt
| BreakSt
| ReturnSt
| ThrowSt
| EmitStatement
| RevertStatement
| SimpleStatement {
recoverWhile = UntilSemicolonRecover
}
Statement ::= IfStatement | TryStatement | WhileStatement | ForStatement | Block | InlineAssemblyStatement | TupleStatement | ReturnTupleStatement | FinishedStatement ';'
// intentionally not pinned
TupleStatement ::= VariableDeclaration '=' SeqExpression ';'
| SeqExpression '=' SeqExpression ';'
| SeqExpression '=' Expression ';'
// intentionally not pinned
ReturnTupleStatement ::= return SeqExpression ';'
private ExpressionStatement ::= Expression
IfStatement ::= if '(' Expression ')' Statement ( else Statement )? {pin = 1}
TryStatement ::= try Expression ( returns ParameterList )? Block CatchClause* {pin = 1}
CatchClause ::= catch ( Identifier? ParameterList )? Block {pin = 1}
WhileStatement ::= while '(' Expression ')' Statement {pin = 1}
PlaceholderStatement ::= '_'
private SimpleStatement ::= VariableDefinition | ExpressionStatement
ForStatement ::= for '(' (SimpleStatement)? ';' (Expression)? ';' (ExpressionStatement)? ')' Statement {pin=1}
InlineAssemblyStatement ::= assembly AssemblyDialect? AssemblyFlags? YulBlock {pin=1}
private AssemblyDialect ::= StringLiteral // "evmasm"
AssemblyFlags ::= '(' StringLiteral (',' StringLiteral)* ')'
DoWhileStatement ::= do Statement while '(' Expression ')' {pin=1}
ContinueSt ::= continue
BreakSt ::= break
ReturnSt ::= return Expression? {pin=1}
ThrowSt ::= throw
/* An emit statement. The contained expression needs to refer to an event. */
EmitStatement ::= emit FunctionCallExpression {pin=1}
/* A revert statement. The contained expression needs to refer to an error. */
// Note, revert can't be a keyword as it could be used as e.g. a function name
RevertStatement ::= 'revert' FunctionCallExpression
SeqExpression ::= '(' ((Expression ',') | ',')* Expression? ')' {pin=1}
VariableDefinition ::= VariableDeclaration ( '=' Expression )?
// see https://solidity.readthedocs.io/en/v0.4.21/miscellaneous.html#order-of-precedence-of-operators
Expression ::=
AssignmentExpression
| TernaryExpression
| OrExpression
| AndExpression
| EqExpression
| CompExpression
| OrOpExpression
| XorOpExpression
| AndOpExpression
| ShiftExpression
| PlusMinExpression
| MultDivExpression
| ExponentExpression
| MetaTypeExpression
| UnaryExpression
| HighestPriorityGroup
| InlineArrayExpression
| PrimaryExpression
private HighestPriorityGroup ::= IncrementExpression
| NewExpression
| IndexAccessExpression
| MemberAccessExpression
| FunctionCallExpression
| SeqExpression
AssignmentExpression ::= Expression ('=' | '|=' | '^=' | '&=' | '<<=' | '>>=' | '+=' | '-=' | '*=' | '/=' | '%=') Expression { rightAssociative=true }
InlineArrayExpression ::= '[' Expression (',' Expression)* ']'
TernaryExpression ::= Expression '?' RightTernaryExpression
private RightTernaryExpression ::= Expression ':' Expression
OrExpression ::= Expression '||' Expression
AndExpression ::= Expression '&&' Expression
EqExpression ::= Expression ('==' | '!=') Expression
CompExpression ::= Expression ('<' | '>' | '<=' | '>=') Expression
OrOpExpression ::= Expression '|' Expression
XorOpExpression ::= Expression '^' Expression
AndOpExpression ::= Expression '&' Expression
ShiftExpression ::= Expression ('<<' | '>>') Expression
PlusMinExpression ::= Expression ('+' | '-') Expression
MultDivExpression ::= Expression ('*' | '/' | '%') Expression
ExponentExpression ::= Expression '**' Expression
UnaryExpression ::= ('!' | '~' | delete | '++' | '--' | '+' | '-') Expression {pin=1}
IncrementExpression ::= Expression ('++' | '--')
// see https://docs.soliditylang.org/en/v0.8.8/units-and-global-variables.html#type-information
MetaTypeExpression ::= type '(' TypeName ')'
PrimaryExpression ::= VarLiteral
| BooleanLiteral
| NumberLiteral
| HexLiteral
| StringLiteral
| ElementaryTypeNameExpression
VarLiteral ::= Identifier {
implements = "me.serce.solidity.lang.psi.SolReferenceElement"
mixin = "me.serce.solidity.lang.psi.impl.SolVarLiteralMixin"
}
FunctionCallExpression ::= Expression FunctionInvocation {
implements = "me.serce.solidity.lang.psi.SolFunctionCallElement"
mixin = "me.serce.solidity.lang.psi.impl.SolFunctionCallMixin"
}
FunctionInvocation ::= MapExpression? '(' FunctionCallArguments? ')'
FunctionCallArguments ::= MapExpression | Expression? ( ',' Expression )*
MapExpressionClause ::= Identifier ':' (Expression | MapExpression) {pin=2}
private UnfinishedMapExpression ::= '{' MapExpressionClause (',' MapExpressionClause )* {
pin=1
recoverWhile = UntilBraceRecover
}
MapExpression ::= UnfinishedMapExpression '}'
NewExpression ::= new TypeName {
implements = "me.serce.solidity.lang.psi.SolReferenceElement"
mixin = "me.serce.solidity.lang.psi.impl.SolNewExpressionElement"
pin = 1
}
MemberAccessExpression ::= Expression '.' Identifier {
pin = 2
implements = "me.serce.solidity.lang.psi.SolReferenceElement"
mixin = "me.serce.solidity.lang.psi.impl.SolMemberAccessElement"
}
IndexAccessExpression ::= Expression '[' ( Expression? ':' Expression? | Expression? ) ']' {pin=2}
BooleanLiteral ::= booleanLiteral
NumberLiteral ::= ( HexNumber | DecimalNumber | FixedNumber | ScientificNumber) NumberUnit?
NumberUnit ::= wei | gwei | szabo | finney | ether
| seconds | minutes | hours | days | weeks | years
// https://github.com/ethereum/solidity/pull/832
// A full hex string literal that consists of either one or several consecutive hex strings.
HexLiteral ::= hexLiteral+
// A full string literal consists of either one or several consecutive quoted strings.
// A full unicode string literal that consists of either one or several consecutive unicode strings.
StringLiteral ::= stringLiteral+
private HexNumber ::= hexNumber
private FixedNumber ::= fixedNumber
private DecimalNumber ::= decimalNumber
private ScientificNumber ::= scientificNumber
private PrimitiveLiteral ::= intNumType | uIntNumType | byteNumType | bytesNumType | fixedNumType | uFixedNumType | booleanLiteral | ( address 'payable' ) | address | payable | string | bool
private ElementaryTypeNameExpression ::= ElementaryTypeName
ElementaryTypeName ::= ( address 'payable' ) | payable | address | bool | string | var | NumberType {
stubClass = "me.serce.solidity.lang.stubs.SolTypeRefStub"
elementTypeFactory = "me.serce.solidity.lang.stubs.ImplKt.factory"
}
NumberType ::= intNumType | uIntNumType | byteNumType | bytesNumType | fixedNumType | uFixedNumType
// Yul Assembly
//
YulLeave ::= 'leave'
YulBreak ::= 'break'
YulContinue ::= 'continue'
private YulLBrace ::= '{'
private YulRBrace ::= '}'
private YulLet ::= 'let'
private YulAssign ::= ':='
private YulComma ::= ','
private YulIf ::= 'if'
private YulFor ::= 'for'
private YulCase ::= 'case'
private YulSwitch ::= 'switch'
YulDefault ::= 'default'
private YulLParen ::= '('
private YulRParen ::= ')'
private YulArrow ::= '->'
private YulIdentifier ::= Identifier
// Keep in sync with
// https://github.com/ethereum/solidity/blob/develop/docs/grammar/SolidityLexer.g4#L274-L288
private YulEVMBuiltin ::=
'stop' | 'add' | 'sub' | 'mul' | 'div' | 'sdiv' | 'mod' | 'smod' | 'exp' | 'not'
| 'lt' | 'gt' | 'slt' | 'sgt' | 'eq' | 'iszero' | 'and' | 'or' | 'xor' | 'byte'
| 'shl' | 'shr' | 'sar' | 'addmod' | 'mulmod' | 'signextend' | 'keccak256'
| 'pop' | 'mload' | 'mstore' | 'mstore8' | 'sload' | 'sstore' | 'tload' | 'tstore' | 'msize' | 'gas'
| 'address' | 'balance' | 'selfbalance' | 'caller' | 'callvalue' | 'calldataload'
| 'calldatasize' | 'calldatacopy' | 'extcodesize' | 'extcodecopy' | 'returndatasize'
| 'returndatacopy' | 'mcopy' | 'extcodehash' | 'create' | 'create2' | 'call' | 'callcode'
| 'delegatecall' | 'staticcall' | 'return' | 'revert' | 'selfdestruct' | 'invalid'
| 'log0' | 'log1' | 'log2' | 'log3' | 'log4' | 'chainid' | 'origin' | 'gasprice'
| 'blockhash' | 'blobhash' | 'coinbase' | 'timestamp' | 'number' | 'difficulty' | 'prevrandao' | 'gaslimit'
| 'basefee' | 'blobbasefee';
private YulFunction ::= 'function'
private YulPeriod ::= '.'
YulTrue ::= 'true'
YulFalse ::= 'false'
private YulDecimalNumber ::= DecimalNumber
private YulStringLiteral ::= StringLiteral
private YulHexNumber ::= HexNumber
private YulHexStringLiteral ::= HexLiteral
// exempt from Solidity.bnf
// replace:
// 'yul' with 'Yul'
// ':' with ' ::=', and ';' with ''
// (cond\=|init\=|body\=|arguments\+\=|variables\+\=|post\=|returnParameters\+\=|\;) with ''
// add pins everywhere, and reorder the expression priority
// http://solidity.readthedocs.io/en/develop/assembly.html#parsing-grammar
/**
* A Yul statement within an inline assembly block.
* continue and break statements are only valid within for loops.
* leave statements are only valid within function bodies.
*/
YulStatement ::=
YulBlock
| YulVariableDeclaration
| YulAssignment
| YulFunctionCall
| YulIfStatement
| YulForStatement
| YulSwitchStatement
| YulLeave
| YulBreak
| YulContinue
| YulFunctionDefinition
// Only support for backwards compatibility
| YulLabel
YulBlock ::= YulLBrace YulStatement* YulRBrace { pin=1 }
/**
* The declaration of one or more Yul variables with optional initial value.
* If multiple variables are declared, only a function call is a valid initial value.
*/
YulVariableDeclaration ::= YulLet YulIdentifier
(YulAssign YulExpression
| (YulComma YulIdentifier)* (YulAssign YulFunctionCall))? { pin=1 }
/**
* Any expression can be assigned to a single Yul variable, whereas
* multi-assignments require a function call on the right-hand side.
*/
YulAssignment ::=
YulPath YulAssign YulExpression
| (YulPath (YulComma YulPath)+) YulAssign YulFunctionCall
// Only support =: for backwards compatibility
| '=:' YulIdentifier
YulIfStatement ::= YulIf YulExpression YulBlock { pin=1 }
YulForStatement ::= YulFor YulBlock YulExpression YulBlock YulBlock { pin=1 }
//@doc ::=inline
YulSwitchCase ::= YulCase YulLiteral YulBlock { pin=1 }
/**
* A Yul switch statement can consist of only a default-case (deprecated) or
* one or more non-default cases optionally followed by a default-case.
*/
YulSwitchStatement ::=
YulSwitch YulExpression
(
(YulSwitchCase+ (YulDefault YulBlock)?)
| (YulDefault YulBlock)
) { pin=1 }
YulFunctionDefinition ::=
YulFunction YulIdentifier
YulLParen (YulIdentifier (YulComma YulIdentifier)*)? YulRParen
(YulArrow YulIdentifier (YulComma YulIdentifier)*)?
YulBlock { pin=1 }
// TODO: remove as lables have been deprecated, and removed, see
// https://docs.soliditylang.org/en/v0.5.6/assembly.html#labels
YulLabel ::= Identifier ':'
/**
* While only identifiers without dots can be declared within inline assembly,
* paths containing dots can refer to declarations outside the inline assembly block.
*/
YulPath ::= YulIdentifier (YulPeriod (YulIdentifier | YulEVMBuiltin))* {
implements = "me.serce.solidity.lang.psi.SolReferenceElement"
mixin = "me.serce.solidity.lang.psi.impl.SolYulPathElement"
}
/**
* A call to a function with return values can only occur as right-hand side of an assignment or
* a variable declaration.
*/
YulFunctionCall ::= (YulIdentifier | YulEVMBuiltin) YulLParen (YulExpression (YulComma YulExpression)*)? YulRParen { pin=2 }
YulBoolean ::= YulTrue | YulFalse
YulLiteral ::= YulDecimalNumber | YulStringLiteral | YulHexNumber | YulBoolean | YulHexStringLiteral
// note the parsing order YulPath will match anything
YulExpression ::= YulFunctionCall | YulLiteral | YulPath