-
Notifications
You must be signed in to change notification settings - Fork 97
/
GraphQLParser.bnf
324 lines (211 loc) · 16.2 KB
/
GraphQLParser.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
/**
* Copyright (c) 2018-present, Jim Kynde Meyer
* All rights reserved.
* <p>
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
{
generate=[names="long" tokenAccessors="no"]
parserClass="com.intellij.lang.jsgraphql.GraphQLParser"
implements="com.intellij.lang.jsgraphql.psi.GraphQLElement"
extends="com.intellij.lang.jsgraphql.psi.impl.GraphQLElementImpl"
psiClassPrefix="GraphQL"
psiImplClassSuffix="Impl"
psiPackage="com.intellij.lang.jsgraphql.psi"
psiImplPackage="com.intellij.lang.jsgraphql.psi.impl"
elementTypeHolderClass="com.intellij.lang.jsgraphql.psi.GraphQLElementTypes"
elementTypeClass="com.intellij.lang.jsgraphql.psi.GraphQLCompositeElementType"
tokenTypeClass="com.intellij.lang.jsgraphql.psi.GraphQLTokenType"
implements("argument|directive|enumValue|field|fieldDefinition|fragmentDefinition|fragmentSpread|inputValueDefinition|objectField|operationDefinition|typeName|typeNameDefinition")="com.intellij.lang.jsgraphql.psi.GraphQLNamedElement"
mixin( "argument|directive|enumValue|field|fieldDefinition|fragmentDefinition|fragmentSpread|inputValueDefinition|objectField|operationDefinition|typeName|typeNameDefinition")="com.intellij.lang.jsgraphql.psi.impl.GraphQLNamedElementImpl"
tokens = [
// punctuation
BANG="!"
DOLLAR="$"
PAREN_L="("
PAREN_R=")"
SPREAD="..."
COLON=":"
EQUALS="="
AT="@"
BRACKET_L="["
BRACKET_R="]"
BRACE_L="{"
PIPE="|"
BRACE_R="}"
AMP="&"
// keywords
QUERY_KEYWORD="query"
MUTATION_KEYWORD="mutation"
SUBSCRIPTION_KEYWORD="subscription"
FRAGMENT_KEYWORD="fragment"
ON_KEYWORD="on"
SCHEMA_KEYWORD="schema"
TYPE_KEYWORD="type"
SCALAR_KEYWORD="scalar"
INTERFACE_KEYWORD="interface"
IMPLEMENTS_KEYWORD="implements"
ENUM_KEYWORD="enum"
UNION_KEYWORD="union"
EXTEND_KEYWORD="extend"
INPUT_KEYWORD="input"
DIRECTIVE_KEYWORD="directive"
WHITE_SPACE='regexp:[,\s]+'
COMMENT='regexp:#.*'
// identifiers and literals
VARIABLE_NAME='regexp:\$[_A-Za-z][_0-9A-Za-z]*'
NAME='regexp:[_A-Za-z][_0-9A-Za-z]*'
NUMBER='regexp:\d+(\.\d*)?((e|E)-?[0-9+])?'
BLOCK_STRING="regexp:('([^'\\]|\\.)*'|\"\"\"([^\"\\]|\\.)*\"\"\")"
REGULAR_STRING_PART='regexp:.*'
// language injection
TEMPLATE_CHAR='regexp:.*'
TEMPLATE_START='${'
]
}
document ::= definition*
definition ::=
operationDefinition |
fragmentDefinition |
typeSystemDefinition |
templateDefinition
{
recoverWhile=definition_recover
}
private definition_recover ::= !(root_tokens | NAME) /* NAME since incomplete keywords show up as such */
private root_tokens ::= definition_keywords | '{' /* anon query */ | OPEN_QUOTE /* schema description */ | (DOLLAR BRACE_L) /* placeholder */
private definition_keywords ::= operationType | 'fragment' | 'schema' | 'type' | 'interface' | 'input' | 'enum' | 'union' | 'scalar' | 'directive' | 'extend'
templateDefinition ::= templatePlaceholder {extends=definition}
// common
operationType ::= 'query' | 'mutation' | 'subscription'
private description ::= quotedString
enumValue ::= identifier {methods=[nameIdentifier="identifier"] extends=value}
arrayValue::= '[' arrayValueElement* ']' {pin=1 extends=value}
private arrayValueElement ::= value {pin=1 recoverWhile=arrayValueElement_recover}
private arrayValueElement_recover ::= !(']'| value)
objectValue::= '{' objectField* '}' {pin=1 extends=value mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLObjectValuePsiElement"}
objectField ::= identifier ':' value {pin=1 methods=[nameIdentifier="identifier"] recoverWhile=objectField_recover mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLObjectFieldPsiElement"}
private objectField_recover ::= !('}' | value)
private directives ::= directive+
directive ::='@' identifier arguments? {pin=1 methods=[nameIdentifier="identifier"]}
arguments ::= '(' argument+ ')' {pin=1}
argument ::= identifier ':' value {pin=1 methods=[nameIdentifier="identifier"] recoverWhile=argument_recover mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLArgumentPsiElement"}
private argument_recover ::= !(')' | argument)
identifier ::= NAME | 'fragment' | 'query' | 'mutation' | 'subscription' | 'schema' | 'scalar' | 'type' | 'interface' | 'implements' | 'enum' | 'union' | 'input' | 'extend' | 'directive' | 'on' {mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLReferencePsiElement"}
private templatePlaceholder ::= DOLLAR BRACE_L TEMPLATE_CHAR* BRACE_R
value ::=
templateVariable |
variable |
stringValue |
intValue |
floatValue |
booleanValue |
nullValue |
enumValue |
arrayValue |
objectValue
templateVariable ::= templatePlaceholder {extends=value}
variable ::= VARIABLE_NAME {pin=1 extends=value implements="com.intellij.psi.PsiNamedElement" mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLRenameAwareVariableElementImpl"}
defaultValue ::= '=' value {pin=1}
stringValue ::= quotedString {extends=value}
type ::= nonNullType | listType | typeName
typeName ::= !(definition_keywords) identifier {extends=type methods=[nameIdentifier="identifier"] mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNamePsiElement"}
listType ::= '[' type ']' {extends=type}
nonNullType ::= typeName BANG | listType BANG {extends=type}
typeNameDefinition ::= !(definition_keywords) identifier {extends=type methods=[nameIdentifier="identifier"]}
booleanValue ::= 'true' | 'false' {extends=value}
nullValue ::= 'null' {extends=value}
quotedString ::= OPEN_QUOTE quotedStringBody? CLOSING_QUOTE {pin=1}
private quotedStringBody ::= REGULAR_STRING_PART+
intValue ::= NUMBER {extends=value}
floatValue ::= NUMBER {extends=value}
// operations
operationDefinition ::= selectionSetOperationDefinition | typedOperationDefinition {extends=definition}
selectionSetOperationDefinition ::= selectionSet {extends=operationDefinition mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLSelectionSetOperationDefinitionPsiElement"}
typedOperationDefinition ::= operationType identifier? variableDefinitions? directives? selectionSet { pin=1 extends=operationDefinition methods=[directives="directive" nameIdentifier="identifier"] implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware" mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLTypedOperationDefinitionPsiElement"}
variableDefinitions ::= '(' variableDefinition+ ')' {pin=1 methods=[variableDefinitions="variableDefinition"]}
variableDefinition ::= variable ':' type defaultValue? directives? {pin=1 recoverWhile=variableDefinition_recover methods=[directives="directive"] implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware"}
private variableDefinition_recover ::= !(')' | root_tokens | variableDefinition)
selectionSet ::= '{' selection+ '}' {pin=1}
selection ::=
field |
fragmentSelection |
templateSelection
{
pin=1 recoverWhile=selection_recover
}
private selection_recover ::= !('}' | root_tokens | selection)
field ::= alias? identifier arguments? directives? selectionSet? {methods=[directives="directive" nameIdentifier="identifier"] implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware" mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLFieldPsiElement"}
alias ::= identifier ':'
fragmentSelection ::= '...' (fragmentSpread | inlineFragment) {pin=1}
templateSelection ::= templatePlaceholder
fragmentSpread ::= fragmentName directives? {pin=1 implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware" methods=[directives="directive" nameIdentifier="identifier"]}
inlineFragment ::= typeCondition? directives? selectionSet {pin=1 methods=[directives="directive"] implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware" mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLInlineFragmentPsiElement"}
fragmentDefinition ::= 'fragment' fragmentName typeCondition directives? selectionSet {pin=1 extends=definition implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware" methods=[directives="directive" nameIdentifier="identifier"] mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLFragmentDefinitionPsiElement"}
private fragmentName ::= !'on' identifier
typeCondition ::= 'on' typeName {pin=1}
// SDL
typeSystemDefinition ::=
schemaDefinition |
typeDefinition |
typeExtension |
directiveDefinition
{
extends=definition
}
schemaDefinition ::= 'schema' directives? operationTypeDefinitions {pin=1 extends=typeSystemDefinition implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware" methods=[directives="directive"]}
operationTypeDefinitions ::= '{' operationTypeDefinition+ '}' {pin=1}
operationTypeDefinition ::= (operationType | NAME) ':' typeName {pin=1 recoverWhile=operationTypeDefinition_recover}
private operationTypeDefinition_recover ::= !('}' | root_tokens | operationTypeDefinition)
typeDefinition::=
scalarTypeDefinition |
objectTypeDefinition |
interfaceTypeDefinition |
unionTypeDefinition |
enumTypeDefinition |
inputObjectTypeDefinition
{
extends=typeSystemDefinition
}
typeExtension ::=
objectTypeExtensionDefinition |
interfaceTypeExtensionDefinition |
unionTypeExtensionDefinition |
scalarTypeExtensionDefinition |
enumTypeExtensionDefinition |
inputObjectTypeExtensionDefinition
{
extends=typeSystemDefinition
}
scalarTypeDefinition ::= description? 'scalar' typeNameDefinition directives? {pin=2 extends=typeDefinition implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLDescriptionAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNameDefinitionOwnerPsiElement" methods=[description="quotedString" directives="directive"]}
scalarTypeExtensionDefinition ::= 'extend' 'scalar' typeName directives? {pin=2 extends=typeExtension implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNameExtensionOwnerPsiElement" methods=[directives="directive"]}
objectTypeDefinition ::= description? 'type' typeNameDefinition implementsInterfaces? directives? fieldsDefinition? {pin=2 extends=typeDefinition implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLDescriptionAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNameDefinitionOwnerPsiElement" methods=[description="quotedString" directives="directive"]}
objectTypeExtensionDefinition ::= 'extend' 'type' typeName implementsInterfaces? directives? fieldsDefinition? {pin=2 extends=typeExtension implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNameExtensionOwnerPsiElement" methods=[directives="directive"]}
implementsInterfaces ::= 'implements' ampTypeName ampTypeName* {pin=1}
private ampTypeName ::= '&'? typeName
fieldsDefinition ::= '{' fieldDefinition* '}' {pin=1}
fieldDefinition ::= description? identifier argumentsDefinition? ':' type directives? {pin=2 implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLDescriptionAware" methods=[description="quotedString" directives="directive" nameIdentifier="identifier"] recoverWhile=fieldDefinition_recover}
private fieldDefinition_recover ::= !('}' | root_tokens | fieldDefinition)
argumentsDefinition ::= '(' inputValueDefinition+ ')' {pin=1}
inputValueDefinition ::= description? identifier ':' type defaultValue? directives? {pin=2 implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLDescriptionAware" methods=[description="quotedString" directives="directive" nameIdentifier="identifier"] recoverWhile=inputValueDefinition_recover mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLInputValueDefinitionPsiElement"}
private inputValueDefinition_recover ::= !(')' | '}' | inputValueDefinition)
interfaceTypeDefinition ::= description? 'interface' typeNameDefinition implementsInterfaces? directives? fieldsDefinition? {pin=2 extends=typeDefinition implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLDescriptionAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNameDefinitionOwnerPsiElement" methods=[description="quotedString" directives="directive"]}
interfaceTypeExtensionDefinition ::= 'extend' 'interface' typeName implementsInterfaces? directives? fieldsDefinition? {pin=2 extends=typeExtension implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNameExtensionOwnerPsiElement" methods=[directives="directive"]}
unionTypeDefinition ::= description? 'union' typeNameDefinition directives? unionMembership? {pin=2 extends=typeDefinition implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLDescriptionAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNameDefinitionOwnerPsiElement" methods=[description="quotedString" directives="directive"]}
unionTypeExtensionDefinition ::= 'extend' 'union' typeName directives? unionMembership? {pin=2 extends=typeExtension implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNameExtensionOwnerPsiElement" methods=[directives="directive"]}
unionMembership ::= '=' unionMembers {pin=1}
unionMembers::= '|'? typeName pipeUnionMember*
private pipeUnionMember ::= '|' typeName {pin=1}
enumTypeDefinition ::= description? 'enum' typeNameDefinition directives? enumValueDefinitions? {pin=2 extends=typeDefinition implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLDescriptionAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNameDefinitionOwnerPsiElement" methods=[description="quotedString" directives="directive"]}
enumTypeExtensionDefinition ::= 'extend' 'enum' typeName directives? enumValueDefinitions? {pin=2 extends=typeExtension implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNameExtensionOwnerPsiElement" methods=[directives="directive"]}
enumValueDefinitions ::= '{' enumValueDefinition+ '}' {pin=1}
enumValueDefinition ::= description? enumValue directives? {pin=2 implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLDescriptionAware" methods=[description="quotedString" directives="directive"] recoverWhile=enumValueDefinition_recover}
private enumValueDefinition_recover ::= !('}' | enumValueDefinition | root_tokens)
inputObjectTypeDefinition ::= description? 'input' typeNameDefinition directives? inputObjectValueDefinitions? {pin=2 extends=typeDefinition implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLDescriptionAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNameDefinitionOwnerPsiElement" methods=[description="quotedString" directives="directive"]}
inputObjectTypeExtensionDefinition ::= 'extend' 'input' typeName directives? inputObjectValueDefinitions? {pin=2 extends=typeExtension implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware, com.intellij.lang.jsgraphql.psi.impl.GraphQLTypeNameExtensionOwnerPsiElement" methods=[directives="directive"]}
inputObjectValueDefinitions ::= '{' inputValueDefinition+ '}' {pin=1}
directiveDefinition ::= description? 'directive' '@' identifier argumentsDefinition? 'on' directiveLocations {pin=2 extends=typeSystemDefinition implements="com.intellij.lang.jsgraphql.psi.impl.GraphQLDescriptionAware" methods=[description="quotedString" nameIdentifier="identifier"]}
directiveLocation ::= 'QUERY' | 'MUTATION' | 'SUBSCRIPTION' | 'FIELD' | 'FRAGMENT_DEFINITION' | 'FRAGMENT_SPREAD' | 'INLINE_FRAGMENT' | 'SCHEMA' | 'SCALAR' | 'OBJECT' | 'FIELD_DEFINITION' | 'ARGUMENT_DEFINITION' | 'INTERFACE' | 'UNION' | 'ENUM' | 'ENUM_VALUE' | 'INPUT_OBJECT' | 'INPUT_FIELD_DEFINITION' | NAME {mixin="com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectiveLocationPsiElement"}
directiveLocations ::= '|'? directiveLocation pipeDirectiveLocation*
private pipeDirectiveLocation ::= '|' directiveLocation