forked from JetBrains/Grammar-Kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grammar.bnf
executable file
·122 lines (106 loc) · 4.14 KB
/
Grammar.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
{
classHeader="license.txt"
generate=[java="8" names="long" visitor-value="R"]
parserClass="org.intellij.grammar.parser.GrammarParser"
parserUtilClass="org.intellij.grammar.parser.GrammarParserUtil"
implements="org.intellij.grammar.psi.BnfComposite"
extends="org.intellij.grammar.psi.impl.BnfCompositeImpl"
psiClassPrefix="Bnf"
psiImplClassSuffix="Impl"
psiPackage="org.intellij.grammar.psi"
psiImplPackage="org.intellij.grammar.psi.impl"
psiImplUtilClass="org.intellij.grammar.psi.impl.GrammarPsiImplUtil"
elementTypeHolderClass="org.intellij.grammar.psi.BnfTypes"
elementTypePrefix="BNF_"
elementTypeClass="org.intellij.grammar.psi.BnfCompositeElementType"
tokenTypeClass="org.intellij.grammar.psi.BnfTokenType"
tokens = [
OP_EQ="="
OP_IS="::="
OP_OR="|"
OP_OPT="?"
OP_ONEMORE="+"
OP_ZEROMORE="*"
OP_AND="&"
OP_NOT="!"
SEMICOLON=";"
LEFT_BRACE="{"
RIGHT_BRACE="}"
LEFT_BRACKET="["
RIGHT_BRACKET="]"
LEFT_PAREN="("
RIGHT_PAREN=")"
EXTERNAL_START="<<"
EXTERNAL_END=">>"
space='regexp:\s+'
id="regexp:\w+"
string="regexp:('([^'\\]|\\.)*'|\"([^\"\\]|\\\"|\\\'|\\)*\")"
number="regexp:\d+"
line_comment="regexp://.*"
block_comment="regexp:/\*(.|\n)*\*/"
]
implements("rule|attr")="org.intellij.grammar.psi.BnfNamedElement"
extends("rule|attr")="org.intellij.grammar.psi.impl.BnfNamedImpl"
mixin("reference_or_token")="org.intellij.grammar.psi.impl.BnfRefOrTokenImpl"
mixin("string_literal_expression")="org.intellij.grammar.psi.impl.BnfStringImpl"
extends("paren_.*expression")=parenthesized
}
external grammar ::= parseGrammar grammar_element
//grammar ::= grammar_element * // live preview root
private grammar_element ::= !<<eof>> (attrs | rule) {
pin=1 recoverWhile=grammar_element_recover
}
private grammar_element_recover::=!('{'|rule_start)
rule ::= rule_start expression attrs? ';'? {pin=2}
private rule_start ::= modifier* id '::='
modifier ::= 'private' | 'external' | 'meta'
| 'inner' | 'left' | 'upper' | 'fake'
attrs ::= '{' attr * '}' {pin=1}
attr ::= attr_start attr_value ';'? {
pin=1 recoverWhile=attr_recover
}
private attr_start ::= id (attr_pattern '=' | '=') {
pin(".*")="attr_pattern"
}
private attr_start_simple ::= id attr_pattern? '='
private attr_recover ::= !('}' | attr_start)
private attr_value ::= attr_value_inner !'='
private attr_value_inner ::= reference_or_token
| literal_expression
| value_list
attr_pattern ::= '(' string_literal_expression ')' {
pin=1 methods=[literalExpression="string_literal_expression"]
}
value_list ::= '[' list_entry * ']' {pin=1 extends=expression}
list_entry ::= (id list_entry_tail? | string_literal_expression) ';'? {
recoverWhile=list_entry_recover
methods=[getReferences literalExpression="string_literal_expression"]
}
private list_entry_tail ::= '=' string_literal_expression {pin=1}
private list_entry_recover ::= !(']' | '}' | id | string)
expression ::= sequence choice?
sequence ::= option * {
extends=expression recoverWhile=sequence_recover
}
private sequence_recover ::=
!(';'|'|'|'('|')'|'['|']'|'{'|'}') grammar_element_recover
private option ::= predicate | paren_opt_expression | simple quantified?
left choice ::= ( '|' sequence ) + {pin(".*")=1 extends=expression}
left quantified ::= quantifier {extends=expression }
quantifier ::= '?' | '+' | '*'
predicate ::= predicate_sign simple {extends=expression}
predicate_sign ::= '&' | '!'
fake parenthesized ::= '(' expression ')' {extends=expression}
private simple ::= !(modifier* id '::=' ) reference_or_token
| literal_expression
| external_expression
| paren_expression
external_expression ::= '<<' reference_or_token option * '>>' {
pin=2 extends=expression methods=[refElement='/expression[0]' getArguments]
}
reference_or_token ::= id {extends=expression methods=[resolveRule]}
literal_expression ::= string_literal_expression | number {extends=expression }
string_literal_expression ::= string {extends=literal_expression}
paren_expression ::= '(' expression ')' | '{' alt_choice_element '}' {pin(".*")=2}
paren_opt_expression ::= '[' expression ']' {pin=2}
private alt_choice_element ::= !attr_start_simple expression