-
-
Notifications
You must be signed in to change notification settings - Fork 155
/
Elixir.bnf
2883 lines (2566 loc) · 117 KB
/
Elixir.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
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
parserClass="org.elixir_lang.parser.ElixirParser"
extends="com.intellij.extapi.psi.ASTWrapperPsiElement"
// direct children of matchedExpression
extends("matched(AccessExpression|.*Operation|((((At)?Unq)|Q)ualified(No)?(Argument|Parenthese)s|Dot)Call|Qualified(Alias|MultipleAliases))")=matchedExpression
// direct children of unmatchedExpression
extends("unmatched(AccessExpression|.*Operation|((((At)?Unq)|Q)ualified(No)?(Argument|Parenthese)s|Dot)Call|Qualified(Alias|MultipleAliases))")=unmatchedExpression
// name identifier owner calls - no argument calls are included because in a pipeline they can have effective arguments
elementTypeFactory("((un)?matched((((At)?Unq)|Q)ualified(No)?(Argument|Parenthese)s|Dot)|unqualifiedNoParenthesesManyArguments)Call")="org.elixir_lang.ElementTypeFactory.factory"
methods( "((un)?matched((At)?Unqualified(No)?(Argument|Parenthese)s|Dot)|unqualifiedNoParenthesesManyArguments)Call")=[
canonicalName
canonicalNameSet
functionName
functionNameElement
getDoBlock
hasDoBlockOrKeyword
getName
getNameIdentifier
getPresentation
getReference
getStub
getUseScope
isCalling
isCallingMacro
implementedProtocolName
moduleName
primaryArguments
primaryArity
processDeclarations
quote
resolvedFinalArity
resolvedFinalArityInterval
resolvedModuleName
resolvedPrimaryArity
resolvedSecondaryArity
secondaryArguments
secondaryArity
setName
]
// qualified calls that need to implement #qualifier()
methods("(un)?matchedQualified(No)?(Argument|Parenthese)sCall")=[
canonicalName
canonicalNameSet
functionName
functionNameElement
getDoBlock
hasDoBlockOrKeyword
getName
getNameIdentifier
getPresentation
getReference
getStub
getUseScope
implementedProtocolName
isCalling
isCallingMacro
moduleName
primaryArguments
primaryArity
processDeclarations
qualifier
quote
resolvedFinalArity
resolvedFinalArityInterval
resolvedModuleName
resolvedPrimaryArity
resolvedSecondaryArity
secondaryArguments
secondaryArity
setName
]
// in operations that works as calls
implements("(un)?matchedInOperation")=[
"org.elixir_lang.psi.call.Call"
"org.elixir_lang.psi.operation.In"
]
// methods set by infix operations below
// `not in` operations that works as calls
implements("(un)?matchedNotInOperation")=[
"org.elixir_lang.psi.call.Call"
"org.elixir_lang.psi.operation.NotIn"
]
methods("(un)?matchedNotInOperation")=[
functionName
functionNameElement
getDoBlock
getName
getNameIdentifier
hasDoBlockOrKeyword
isCalling
isCallingMacro
leftOperand
moduleName
operator
primaryArguments
primaryArity
processDeclarations
quote
resolvedFinalArity
resolvedFinalArityInterval
resolvedModuleName
resolvedPrimaryArity
resolvedSecondaryArity
rightOperand
secondaryArguments
secondaryArity
setName
]
/* infix operations that work as name identifier owner calls - specifically support getNameIdentifier so they can
return their operator, so it is easy to use a different operator when making customer operators like in Bitwise or
the free arrow operators */
implements( "(un)?matched(Comparison|Relational)Operation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Infix"
]
methods( "(un)?matched(Addition|And|Arrow|Comparison|In|InMatch|Match|Multiplication|Or|Pipe|Power|Relational|Ternary|Three|Two|Type|When)Operation")=[
functionName
functionNameElement
getDoBlock
getName
getNameIdentifier
hasDoBlockOrKeyword
isCalling
isCallingMacro
leftOperand
moduleName
operator
primaryArguments
primaryArity
processDeclarations
quote
resolvedFinalArity
resolvedFinalArityInterval
resolvedModuleName
resolvedPrimaryArity
resolvedSecondaryArity
rightOperand
secondaryArguments
secondaryArity
setName
]
implements("(un)?matchedAdditionOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Addition"
]
// methods set by infix operations above
implements("(un)?matchedAndOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.And"
]
// methods set by infix operations above
implements("(un)?matchedArrowOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Arrow"
]
implements("(un)?matchedInMatchOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.InMatch"
]
// methods set by infix operations above
implements("(un)?matchedMatchOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Match"
]
// methods set by infix operations above
implements("(un)?matchedMultiplicationOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Multiplication"
]
// methods set by infix operations above
implements("(un)?matchedPowerOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Power"
]
// methods set by infix operations above
implements("(un)?matchedOrOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Or"
]
// methods set by infix operations above
implements("(un)?matchedPipeOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Pipe"
]
// methods set by infix operations above
implements("(un)?matchedThreeOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Three"
]
// methods set by infix operations above
implements("(un)?matchedTernaryOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Ternary"
]
// methods set by infix operations above
implements("(un)?matchedTwoOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Two"
]
// methods set by infix operations above
implements("(un)?matchedTypeOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Type"
]
// methods set by infix operations above
implements("(un)?matchedWhenOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.When"
]
// methods set by infix operations above
/*
* Prefix operations
*
* Have names (their operators), but aren't stubbed because they don't define structures.
*/
implements( "(at|capture|unary)NumericOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.Prefix"
]
methods( "((at|capture|unary)Numeric|(un)?matched(UnaryNonNumeric|Unary))Operation")=[
functionName
functionNameElement
getDoBlock
getName
getNameIdentifier
hasDoBlockOrKeyword
isCalling
isCallingMacro
moduleName
operand
operator
primaryArguments
primaryArity
quote
secondaryArguments
secondaryArity
resolvedFinalArity
resolvedFinalArityInterval
resolvedModuleName
resolvedPrimaryArity
resolvedSecondaryArity
setName
]
// at operations
implements("(un)?matchedAtOperation")=[
"org.elixir_lang.psi.AtOperation"
]
methods("(un)?matchedAtOperation")=[
getReference
moduleAttributeName
operand
operator
quote
]
// captureNonNumeric operations
implements( "(un)?matched.*CaptureNonNumericOperation")=[
"org.elixir_lang.psi.call.Named"
"org.elixir_lang.psi.operation.capture.NonNumeric"
]
methods( "(un)?matched.*CaptureNonNumericOperation")=[
functionName
functionNameElement
getDoBlock
getName
getNameIdentifier
getReference
hasDoBlockOrKeyword
isCalling
isCallingMacro
moduleName
operand
operator
primaryArguments
primaryArity
quote
secondaryArguments
secondaryArity
resolvedFinalArity
resolvedFinalArityInterval
resolvedModuleName
resolvedPrimaryArity
resolvedSecondaryArity
setName
]
// unaryNonNumeric operations
implements("(un)?matchedUnaryOperation")=[
"org.elixir_lang.psi.UnaryOperation"
]
// method set by prefix operations above
// QualifiedBracketOperation
implements("(un)?matchedQualifiedBracketOperation")=[
"org.elixir_lang.psi.QualifiedBracketOperation"
]
methods( "(un)?matchedQualifiedBracketOperation")=[
qualifier
quote
]
// QualifiedMultipleAliases
implements("(un)?matchedQualifiedMultipleAliases")=[
"org.elixir_lang.psi.QualifiedMultipleAliases"
]
methods( "(un)?matchedQualifiedMultipleAliases")=[
quote
]
// Sigil Heredoc
methods("(interpolated|literal)SigilHeredoc") = [
addEscapedCharacterCodePoints
addEscapedEOL
addEscapedTerminator
addFragmentCodePoints
addHexadecimalEscapeSequenceCodePoints
createLiteralTextEscaper
getHeredocLineList
indentation
isValidHost
quote
quoteBinary
quoteEmpty
quoteInterpolation
quoteLiteral
sigilDelimiter
sigilName
updateText
]
// Sigil Line
methods("(interpolated|literal)SigilLine") = [
addEscapedCharacterCodePoints
addEscapedEOL
addEscapedTerminator
addFragmentCodePoints
addHexadecimalEscapeSequenceCodePoints
createLiteralTextEscaper
getBody
indentation
isValidHost
quote
quoteBinary
quoteEmpty
quoteInterpolation
quoteLiteral
sigilDelimiter
sigilName
terminator
updateText
]
psiClassPrefix="Elixir"
psiImplClassSuffix="Impl"
psiPackage="org.elixir_lang.psi"
psiImplPackage="org.elixir_lang.psi.impl"
psiImplUtilClass="org.elixir_lang.psi.impl.ElixirPsiImplUtil"
elementTypeHolderClass="org.elixir_lang.psi.ElixirTypes"
elementTypeClass="org.elixir_lang.psi.ElixirElementType"
tokenTypeClass="org.elixir_lang.psi.ElixirTokenType"
tokens = [
ADDITION_OPERATOR = "+"
AFTER = "after"
ALIAS_TOKEN = "Alias"
AND_SYMBOL_OPERATOR = "&&&, &&"
AND_WORD_OPERATOR = "`and`"
ARROW_OPERATOR = "<<<, <<~, <|>, <~>, >>>, ~>>, <~, |>, ~>"
ASSOCIATION_OPERATOR = "=>"
ATOM_FRAGMENT = "A-Z, a-z, _, @, 0-9. ?, !"
AT_OPERATOR = "@"
BASE_WHOLE_NUMBER_PREFIX = "0"
BINARY_WHOLE_NUMBER_BASE = "b"
BIT_STRING_OPERATOR = "<<>>"
CALL = "<zero-width-call>"
CAPTURE_OPERATOR = "&"
CATCH = "catch"
CHAR_TOKENIZER = "?"
CLOSING_BIT = ">>"
CLOSING_BRACKET = "]"
CLOSING_CURLY = "}"
// TODO remove once CLOSING_PARENTHESIS is used in emptyParentheses rule
CLOSING_PARENTHESIS = ")"
COLON = ":"
COMMA = ","
COMMENT = "#"
COMPARISON_OPERATOR = "!==, ===, !=, ==, =~"
DECIMAL_MARK = "Decimal Mark (.)"
DIVISION_OPERATOR = "/"
DO = "do"
DOT_OPERATOR = "."
EEX_CLOSING = "%>"
EEX_COMMENT = "EEx Comment"
EEX_COMMENT_MARKER = "EEx Comment Marker (#)"
EEX_DATA = "EEx Data"
EEX_EMPTY_MARKER = "EEx Empty Marker"
EEX_EQUALS_MARKER = "EEx Equals Marker (=)"
EEX_ESCAPED_OPENING = "<%%"
EEX_FORWARD_SLASH_MARKER = "EEx Forward Slash Marker (/)"
EEX_OPENING = "<%"
EEX_PIPE_MARKER = "EEx Pipe Marker (|)"
ELSE = "else"
EOL = "\\n, \\r\\n"
END = "end"
ESCAPE = "\\"
ESCAPED_CHARACTER_TOKEN = "\\<character>, \\x{<hexadecimal-digit>}, \\x<hexadecimal-digit>, \\\\n, \\\\r\\n"
EXPONENT_MARK = "E, e"
FALSE = "false"
FN = "fn"
FRAGMENT = "Fragment"
HEREDOC_LINE_WHITE_SPACE_TOKEN = "Whitespace at beginning of line of heredoc"
HEREDOC_PREFIX_WHITE_SPACE = "Whitespace at beginning of last line of heredoc before terminator"
HEREDOC_PROMOTER = "Heredoc Promoter (\"\"\", ''')"
HEREDOC_TERMINATOR = "Heredoc Terminator (\"\"\", ''')"
HEXADECIMAL_WHOLE_NUMBER_BASE = "x"
IDENTIFIER_TOKEN = "identifier"
INTERPOLATING_SIGIL_NAME = "a-z"
// Can't be just "}", because that's used for the more general CLOSING_CURLY
INTERPOLATION_END = "Interpolation End (})"
// Human-readable "Interpolation Start" to match format of INTERPOLATION_END
INTERPOLATION_START = "Interpolation Start (#{)"
INVALID_BINARY_DIGITS = "A-Z, a-z, 2-9"
INVALID_DECIMAL_DIGITS = "A-Z, a-z"
INVALID_HEXADECIMAL_DIGITS = "G-Z, g-z"
INVALID_OCTAL_DIGITS = "A-Z, a-z, 8-9"
INVALID_UNKNOWN_BASE_DIGITS = "A-Z, a-z, 0-9"
IN_MATCH_OPERATOR = "<-, \\\\"
IN_OPERATOR = "in"
KEYWORD_PAIR_COLON = "Keyword Pair Colon (:)"
LINE_PROMOTER = "{, [, <, \", /, (, |, '"
LINE_TERMINATOR = "}, ], >, \", /, ), |, '"
LITERAL_SIGIL_NAME = "A-Z"
MAP_OPERATOR = "%{}"
MATCH_OPERATOR = "="
MINUS_OPERATOR = "-"
MULTIPLICATION_OPERATOR = "*"
NEGATE_OPERATOR = "-"
NIL = "nil"
NOT_OPERATOR = "not"
NUMBER_SEPARATOR = "_"
NUMBER_OR_BADARITH_OPERATOR = "+"
OBSOLETE_BINARY_WHOLE_NUMBER_BASE = "B"
OBSOLETE_HEXADECIMAL_WHOLE_NUMBER_BASE = "X"
OCTAL_WHOLE_NUMBER_BASE = "o"
OPENING_BIT = "<<"
OPENING_BRACKET = "["
OPENING_CURLY = "{"
OPENING_PARENTHESIS = "("
OR_SYMBOL_OPERATOR = "|||, ||"
OR_WORD_OPERATOR = "`or`"
PIPE_OPERATOR = "|"
PLUS_OPERATOR = "+"
POWER_OPERATOR = "**"
RANGE_OPERATOR = ".."
RELATIONAL_OPERATOR = "<, <=, >=, >"
RESCUE = "rescue"
// TOO remove once SEMICOLON is used in endOfExpression rule
SEMICOLON = ";"
SIGIL_MODIFIER = "Sigil Modifier (A-Z, a-z)"
SIGN_OPERATOR = "Sign Operator (+, -)"
STAB_OPERATOR = "->"
// https://github.com/elixir-lang/elixir/pull/10810
TERNARY_OPERATOR = "//"
// TODO remove once containers are available for `{}` after alias for empty structs
STRUCT_OPERATOR = "%"
SUBTRACTION_OPERATOR = "-"
TILDE = "~"
TRUE = "true"
TUPLE_OPERATOR = "{}"
TWO_OPERATOR = "++, --, <>"
// https://github.com/elixir-lang/elixir/commit/3487d00ddb5e90c7cf0e65d03717903b9b27eafd
THREE_OPERATOR = "^^^"
TYPE_OPERATOR = "::"
UNARY_OPERATOR = "~~~, !, ^"
UNICODE_ESCAPE_CHARACTER = "u"
UNKNOWN_WHOLE_NUMBER_BASE = "A-Z, a, c-n, p-w, z"
VALID_BINARY_DIGITS = "0-1"
VALID_DECIMAL_DIGITS = "0-9"
VALID_HEXADECIMAL_DIGITS = "A-F, a-f, 0-9"
VALID_OCTAL_DIGITS = "0-7"
WHEN_OPERATOR = "when"
]
}
// `elixirFile` has more error recovery, so it'll match almost anything, so it needs to be after `eex`
private eexOrElixirFile ::= eex | elixirFile
// expressionList is optional to handle code-less file that contains only EOL between blank lines and order comment
// lines
private elixirFile ::= endOfExpressionMaybe (expressionList endOfExpressionMaybe)?
/*
*
*
* Expression List
*
*
*/
private eolStar ::= EOL*
// Must have at least one EOL or SEMICOLON, but at most one SEMICOLON
endOfExpression ::= SEMICOLON | EOL+ { implements = "org.elixir_lang.psi.Unquoted" }
private endOfExpressionMaybe ::= endOfExpression?
/*
*
* Expression
*
*/
private expression ::= emptyParentheses |
unmatchedExpression |
unqualifiedNoParenthesesManyArgumentsCall
{ recoverWhile = expressionRecoverWhile }
// EOL and SEMICOLON for endOfExpression
/* INTERPOLATION_END because interpolation(elixirFile(expression)) needs expression to stop of on INTERPOLATION_END for
interpolation */
// END for stabBody's usage of expression
// CLOSING_* because they are endings to subexpressions
// STAB_OPERATOR because it ends when clause for no parentheses stab guard clauses
// blockIdentifier for one-liner blockItems where there isn't a newline between block expressions and following blockIdentifier.
private expressionRecoverUntil ::= EOL | CLOSING_BIT | CLOSING_BRACKET | CLOSING_CURLY | CLOSING_PARENTHESIS | COMMA | INTERPOLATION_END | SEMICOLON | STAB_OPERATOR | END | blockIdentifier | EEX_CLOSING
private expressionRecoverWhile ::= !expressionRecoverUntil
private expressionList ::= expression (endOfExpression expression)*
/*
*
*
* Function Calls
*
*
*/
/*
*
* No Parentheses
*
*/
/*
* Many Arguments
*/
/* Have to prevent matchedExpression that is actually a keywordKey from being parsed as just a matchedExpression or
callArgumentsNoParenthesesCommaExpression COMMA EOL* callArgumentsNoParenthesesKeywords will never match. */
private noParenthesesExpression ::= emptyParentheses |
/* Must be before matchedExpression because noParenthesesExpression is
`matchedExpressionDotIdentifier callArgumentsNoParenthesesManyStrict` which is
longer than `matchedExpressionDotIdentifier` in matchedExpression. */
/* This will be marked as an error by
{@link org.elixir_lang.inspection.NoParenthesesManyStrict} */
noParenthesesManyStrictNoParenthesesExpression |
matchedExpression
/* Special class for wrapping noParenthesesCall so that
{@link: org.elixir_lang.inspection.NoParenthesesManyStrict} can just search for
ElixirNoParenthesesManyStrictNoParenthesesExpression isn't of having to differentiate between valid and invalid
ElixirNoParenthesesCall. */
noParenthesesManyStrictNoParenthesesExpression ::= unqualifiedNoParenthesesManyArgumentsCall
{ implements = "org.elixir_lang.psi.Quotable" methods = [quote] }
/* Special class for wrapping rules so that
{@link: org.elixir_lang.inspection.NoParenthesesStrict} can just search for
ElixirNoParenthesesStrict instead of having to differentiate between valid and invalid
rule classes. */
noParenthesesStrict ::= emptyParentheses |
OPENING_PARENTHESIS (
noParenthesesKeywords |
noParenthesesManyArguments
) CLOSING_PARENTHESIS
{
implements = [
"org.elixir_lang.psi.Arguments"
"org.elixir_lang.psi.QuotableArguments"
]
methods = [
arguments
quoteArguments
]
}
/* 1. (positional, keywords)
2. (positional, positional)
3. (positional, positional, keywords) */
private noParenthesesManyArguments ::= matchedExpression infixComma noParenthesesKeywords |
matchedExpression (infixComma noParenthesesExpression)+ (infixComma noParenthesesKeywords)?
private noParenthesesManyArgumentsStrict ::= noParenthesesManyArguments |
noParenthesesStrict
// A rule instead of a token so that there is a PsiElement to return from getNameIdentifier
identifier ::= IDENTIFIER_TOKEN
{
implements = "org.elixir_lang.psi.Quotable"
methods = [
getPresentation
getReference
quote
]
}
private notKeywordPairColon ::= !KEYWORD_PAIR_COLON
// @see https://github.com/elixir-lang/elixir/blob/de39bbaca277002797e52ffbde617ace06233a2b/lib/elixir/src/elixir_parser.yrl#L124-L125
unqualifiedNoParenthesesManyArgumentsCall ::= identifier notKeywordPairColon
noParenthesesManyArgumentsStrict
{
implements = [
// MUST be first so visitElement is used in ElixirVisitor
"com.intellij.psi.PsiElement"
"org.elixir_lang.psi.call.StubBased<org.elixir_lang.psi.stub.UnqualifiedNoParenthesesManyArgumentsCall>"
"org.elixir_lang.psi.call.arguments.star.NoParentheses"
"org.elixir_lang.psi.qualification.Unqualified"
"org.elixir_lang.psi.Quotable"
]
mixin = "org.elixir_lang.psi.impl.NamedStubbedPsiElementBase<org.elixir_lang.psi.stub.UnqualifiedNoParenthesesManyArgumentsCall>"
stubClass = "org.elixir_lang.psi.stub.UnqualifiedNoParenthesesManyArgumentsCall"
}
/*
* 1+ Arguments
*/
noParenthesesKeywords ::= noParenthesesKeywordPair (infixComma noParenthesesKeywordPair)*
{
implements = "org.elixir_lang.psi.QuotableKeywordList"
methods = [
quotableKeywordPairList
quote
]
}
noParenthesesKeywordPair ::= keywordKeyColon noParenthesesExpression
{
implements = "org.elixir_lang.psi.QuotableKeywordPair"
methods = [
getKeywordKey
getKeywordValue
quote
]
}
/*
* 0 Arguments
*/
variable ::= IDENTIFIER_TOKEN notKeywordPairColon
{
implements = [
"org.elixir_lang.psi.NamedElement"
"org.elixir_lang.psi.Quotable"
]
methods = [
getName
getNameIdentifier
quote
setName
]
}
/*
*
*
* Heredoc
*
*
*/
heredocLinePrefix ::= HEREDOC_LINE_WHITE_SPACE_TOKEN? { methods = [excessWhitespace] }
heredocPrefix ::= HEREDOC_PREFIX_WHITE_SPACE?
/*
*
* Quote Heredoc
*
*/
heredoc ::= HEREDOC_PROMOTER EOL
heredocLine*
heredocPrefix HEREDOC_TERMINATOR
{
implements = [
"org.elixir_lang.psi.Heredoc"
"org.elixir_lang.psi.Quote"
]
methods = [
addEscapedCharacterCodePoints
addEscapedEOL
addEscapedTerminator
addFragmentCodePoints
addHexadecimalEscapeSequenceCodePoints
createLiteralTextEscaper
getHeredocLineList
isCharList
isValidHost
quote
quoteBinary
quoteEmpty
quoteInterpolation
quoteLiteral
updateText
]
//noinspection BnfResolve
pin = HEREDOC_PROMOTER
}
// EOL is optional because when last line EOL is escaped (See https://github.com/KronicDeth/intellij-elixir/issues/1843)
heredocLine ::= heredocLinePrefix heredocLineBody heredocLineEnd
{
implements = [
"org.elixir_lang.psi.HeredocLine"
]
methods = [
getBody
quote
]
}
heredocLineBody ::= (interpolation | FRAGMENT | heredocEscapeSequence | escapedHeredocTerminator)*
{ implements = "org.elixir_lang.psi.Body" }
/*
*
* Interpolated Sigil Heredoc
*
*/
sigilModifiers ::= SIGIL_MODIFIER* { implements = "org.elixir_lang.psi.Quotable" methods = [quote] }
interpolatedSigilHeredoc ::= TILDE INTERPOLATING_SIGIL_NAME HEREDOC_PROMOTER EOL
interpolatedHeredocLine*
heredocPrefix HEREDOC_TERMINATOR sigilModifiers
{
implements = [
"org.elixir_lang.psi.SigilHeredoc"
]
//noinspection BnfResolve
pin = HEREDOC_PROMOTER
}
interpolatedHeredocLine ::= heredocLinePrefix interpolatedHeredocLineBody heredocLineEnd
{
implements = [
"org.elixir_lang.psi.HeredocLine"
]
methods = [
getBody
quote
]
}
interpolatedHeredocLineBody ::= (interpolation | FRAGMENT | sigilHeredocEscapeSequence | escapedHeredocTerminator)*
{ implements = "org.elixir_lang.psi.Body" }
/*
*
* Literal Sigil Heredoc
*
*/
literalSigilHeredoc ::= TILDE LITERAL_SIGIL_NAME HEREDOC_PROMOTER EOL
literalHeredocLine*
heredocPrefix HEREDOC_TERMINATOR sigilModifiers
{
implements = [
"org.elixir_lang.psi.Literal"
"org.elixir_lang.psi.SigilHeredoc"
]
//noinspection BnfResolve
pin = HEREDOC_PROMOTER
}
// EOL is optional because when last line EOL is escaped (See https://github.com/KronicDeth/intellij-elixir/issues/1843)
literalHeredocLine ::= heredocLinePrefix literalHeredocLineBody heredocLineEnd
{
implements = [
"org.elixir_lang.psi.HeredocLine"
]
methods = [
getBody
quote
]
}
// literals can have escape sequences for escaped terminator
literalHeredocLineBody ::= (FRAGMENT | sigilHeredocEscapeSequence | escapedHeredocTerminator)*
{ implements = "org.elixir_lang.psi.Body" }
/*
*
*
* Lines (as opposed to Heredocs)
*
*
*/
/*
*
* Quote Lines
*
*/
line ::= LINE_PROMOTER lineBody LINE_TERMINATOR
{
implements = [
"org.elixir_lang.psi.Atomable"
"org.elixir_lang.psi.Interpolated"
"org.elixir_lang.psi.Line"
"org.elixir_lang.psi.Quotable"
"org.elixir_lang.psi.Quote"
]
methods = [
addEscapedCharacterCodePoints
addEscapedEOL
addEscapedTerminator
addFragmentCodePoints
addHexadecimalEscapeSequenceCodePoints
createLiteralTextEscaper
getBody
isCharList
isValidHost
quote
quoteAsAtom
quoteBinary
quoteEmpty
quoteInterpolation
quoteLiteral
updateText
]
//noinspection BnfResolve
pin = LINE_PROMOTER
}
lineBody ::= (interpolation | FRAGMENT | lineEscapeSequence)*
{ implements = "org.elixir_lang.psi.Body" }
/*
*
* Sigil Lines
*
*/
/*
* Interpolated Sigil Lines
*/
interpolatedSigilLine ::= TILDE INTERPOLATING_SIGIL_NAME LINE_PROMOTER interpolatedSigilLineBody LINE_TERMINATOR sigilModifiers
{
implements = [
"org.elixir_lang.psi.Interpolated"
"org.elixir_lang.psi.SigilLine"
]
//noinspection BnfResolve
pin = LINE_PROMOTER
}
interpolatedSigilLineBody ::= (interpolation | FRAGMENT | sigilLineEscapeSequence)*
{ implements = "org.elixir_lang.psi.Body" }
/*
* Literal Sigils
*/
literalSigilLine ::= TILDE LITERAL_SIGIL_NAME LINE_PROMOTER literalSigilLineBody LINE_TERMINATOR sigilModifiers
{
implements = [
"org.elixir_lang.psi.Literal"
"org.elixir_lang.psi.SigilLine"
]
//noinspection BnfResolve
pin = LINE_PROMOTER
}
literalSigilLineBody ::= (FRAGMENT | sigilLineEscapeSequence)*
{ implements = "org.elixir_lang.psi.Body" }
/*
*
*
* Matched Expressions - ordered by outer-most (lowest precedence) to inner-most (highest precedence)
*
* See ELIXIR_BNF_DESIGN.md for explanation of the naming and nesting pattern used in the matchedExpression rules.
*
*
*/
matchedExpression ::= matchedInMatchOperation |
/* noParenthesesKeywords needs to be first as matchedExpression will match due to the error
handling built into the Pratt parser. */
matchedWhenNoParenthesesKeywordsOperation |
matchedWhenOperation |
matchedTypeOperation |
matchedPipeOperation |
matchedCaptureNonNumericOperation |
matchedMatchOperation |
matchedOrOperation |
matchedAndOperation |
matchedComparisonOperation |
matchedRelationalOperation |
matchedArrowOperation |
matchedInOperation |
matchedNotInOperation |
matchedThreeOperation |
matchedTernaryOperation |
matchedTwoOperation |
matchedAdditionOperation |
matchedMultiplicationOperation |
matchedPowerOperation |
matchedUnaryOperation |
matchedDotCall |
// NoParentheses before matchedBracketOperation because brackets only make sense after parentheses.
matchedQualifiedNoParenthesesCall |
matchedAtUnqualifiedNoParenthesesCall |
matchedUnqualifiedNoParenthesesCall |
matchedAtNumericBracketOperation |
matchedBracketOperation |
matchedQualifiedAlias |
matchedQualifiedMultipleAliases |
matchedQualifiedBracketOperation |
matchedQualifiedParenthesesCall |
matchedQualifiedNoArgumentsCall |
matchedAtUnqualifiedBracketOperation |
matchedAtOperation | // after matchedQualified because @ binds only before `.`
matchedUnqualifiedParenthesesCall |
matchedUnqualifiedBracketOperation |
matchedUnqualifiedNoArgumentsCall |
matchedAccessExpression
/*
* Capture Non-Numeric Operation - non-associative
*
* @see https://github.com/elixir-lang/elixir/blob/de39bbaca277002797e52ffbde617ace06233a2b/lib/elixir/src/elixir_parser.yrl#L50
*/
private nonNumeric ::= !numeric
capturePrefixOperator ::= CAPTURE_OPERATOR
{
implements = "org.elixir_lang.psi.Operator"
methods = [
operatorTokenSet
quote
]
name = "&"
}
matchedCaptureNonNumericOperation ::= capturePrefixOperator nonNumeric matchedExpression
/*
* In Match Operation - left-associative
*
* @see https://github.com/elixir-lang/elixir/blob/de39bbaca277002797e52ffbde617ace06233a2b/lib/elixir/src/elixir_parser.yrl#L51
*/
inMatchInfixOperator ::= IN_MATCH_OPERATOR
{
implements = "org.elixir_lang.psi.Operator"
methods = [
operatorTokenSet
quote
]
name = "<-, \\\\"
}
// implements and methods defined by "infix operations" section above
matchedInMatchOperation ::= matchedExpression inMatchInfixOperator matchedExpression
/*
* When Operation - right-associative
*
* @see https://github.com/elixir-lang/elixir/blob/de39bbaca277002797e52ffbde617ace06233a2b/lib/elixir/src/elixir_parser.yrl#L52
*/
whenInfixOperator ::= WHEN_OPERATOR
{
implements = "org.elixir_lang.psi.Operator"
methods = [
operatorTokenSet
quote
]
name = "when"
}
/* noParenthesesKeywords needs to be in a separate operation so that only matchedWhenNoParenthesesKeywordsOperation is a
POSTFIX operation and matchedWhenOperation can remain a BINARY operation. With
`(noParenthesesKeywords | matchedExpression)` as the right operand, matchedWhenExpression was a POSTFIX operator,
which caused the precedence for matchedInMatchOperand and matchedWhenOperation to be wrong as demonstrated in
49ffef5a33ca1102213821efb4e2140f97622ca1 by
org.elixir_lang.parser_definition.MatchedINMatchOperationParsingTestCase.testMatchedWhenOperation. */
matchedWhenNoParenthesesKeywordsOperation ::= matchedExpression whenInfixOperator noParenthesesKeywords
{ elementType = matchedWhenOperation rightAssociative = true }
// implements and methods defined by "infix operations" section above
matchedWhenOperation ::= matchedExpression whenInfixOperator matchedExpression