-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sparql11query.g
427 lines (355 loc) · 7.71 KB
/
Sparql11query.g
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
grammar Sparql11query;
options {
language = Java;
// k = 1;
// memoize = true;
}
// made according to this version
// http://www.w3.org/TR/2010/WD-sparql11-query-20100126/
import Tokens ;
fakestart : start EOF;
/* sparql 1.1 r1 */
start
: prologue (
selectQuery
| constructQuery
| describeQuery
| askQuery
)
;
/* sparql 1.1 r2 */
prologue
: baseDecl? prefixDecl*
;
/* sparql 1.1 r3 */
baseDecl
: BASE iriRef
;
/* sparql 1.1 r4 */
prefixDecl
: PREFIX PNAME_NS iriRef
;
/* sparql 1.1 r5 */
selectQuery
: SELECT ( DISTINCT | REDUCED )? ( variable+ | ASTERISK ) datasetClause* whereClause solutionModifier
;
/* sparql 1.1 r6 */
constructQuery
: CONSTRUCT constructTemplate datasetClause* whereClause solutionModifier
;
/* sparql 1.1 r7 */
describeQuery
: DESCRIBE ( varOrIRIref+ | ASTERISK ) datasetClause* whereClause? solutionModifier
;
/* sparql 1.1 r8 */
askQuery
: ASK datasetClause* whereClause
;
/* sparql 1.1 r9 */
datasetClause
: FROM ( defaultGraphClause | namedGraphClause )
;
/* sparql 1.1 r10 */
defaultGraphClause
: sourceSelector
;
/* sparql 1.1 r11 */
namedGraphClause
: NAMED sourceSelector
;
/* sparql 1.1 r12 */
sourceSelector
: iriRef
;
/* sparql 1.1 r13 */
whereClause
: WHERE? groupGraphPattern
;
/* sparql 1.1 r14 */
solutionModifier
: orderClause? limitOffsetClauses?
;
/* sparql 1.1 r15 */
limitOffsetClauses
: limitClause offsetClause?
| offsetClause limitClause?
;
/* sparql 1.1 r16 */
orderClause
: ORDER BY orderCondition+
;
/* sparql 1.1 r17 */
orderCondition
: ( ( ASC | DESC ) brackettedExpression )
| ( constraint | variable)
;
/* sparql 1.1 r18 */
limitClause
: LIMIT INTEGER
;
/* sparql 1.1 r19 */
offsetClause
: OFFSET INTEGER
;
/* sparql 1.1 update r20 */
groupGraphPattern
: OPEN_CURLY_BRACE triplesBlock? ((graphPatternNotTriples | filter) DOT? triplesBlock? )* CLOSE_CURLY_BRACE
;
/* sparql 1.1 update r21 */
triplesBlock
: triplesSameSubject ( DOT triplesBlock? )?
;
/* sparql 1.1 update r22*/
graphPatternNotTriples
: optionalGraphPattern
| groupOrUnionGraphPattern
| graphGraphPattern
;
/* sparql 1.1 update r23 */
optionalGraphPattern
: OPTIONAL groupGraphPattern
;
/* sparql 1.1 update r24 */
graphGraphPattern
: GRAPH varOrIRIref groupGraphPattern
;
/* sparql 1.1 update r25 */
groupOrUnionGraphPattern
: groupGraphPattern ( UNION groupGraphPattern )*
;
/* sparql 1.1 update r26 */
filter
: FILTER constraint
;
/* sparql 1.1 update r27 */
constraint
: brackettedExpression
| builtInCall
| functionCall
;
/* sparql 1.1 update r28 */
functionCall
: iriRef argList
;
/* sparql 1.1 update r29 */
argList
: OPEN_BRACE WS* CLOSE_BRACE | OPEN_BRACE expression ( COMMA expression )* CLOSE_BRACE
;
/* sparql 1.1 r30 */
constructTemplate
: OPEN_CURLY_BRACE constructTriples? CLOSE_CURLY_BRACE
;
/* sparql 1.1 r31 */
constructTriples
: triplesSameSubject ( DOT constructTriples? )?
;
/* sparql 1.1 r32 */
triplesSameSubject
: varOrTerm propertyListNotEmpty
| triplesNode propertyList
;
/* sparql 1.1 update r33 */
propertyListNotEmpty
: verb objectList ( SEMICOLON ( verb objectList )? )*
;
/* sparql 1.1 update r34 */
propertyList
: propertyListNotEmpty?
;
/* sparql 1.1 update r35 */
objectList
: object ( COMMA object )*
;
/* sparql 1.1 update r36 */
object
: graphNode
;
/* sparql 1.1 update r37 */
verb
: varOrIRIref
| A
;
/* sparql 1.1 update r38 */
triplesNode
: collection
| blankNodePropertyList
;
/* sparql 1.1 update r39 */
blankNodePropertyList
: OPEN_SQUARE_BRACE propertyListNotEmpty CLOSE_SQUARE_BRACE
;
/* sparql 1.1 update r40 */
collection
: OPEN_BRACE graphNode+ CLOSE_BRACE
;
/* sparql 1.1 update r41 */
graphNode
: varOrTerm
| triplesNode
;
/* sparql 1.1 update r42 */
varOrTerm
: variable
| graphTerm
;
/* sparql 1.1 update r43 */
varOrIRIref
: variable
| iriRef
;
/* sparql 1.1 update r44 */
variable
: VAR1
| VAR2
;
/* sparql 1.1 update r45 */
graphTerm
: iriRef
| rdfLiteral
| numericLiteral
| booleanLiteral
| blankNode
| OPEN_BRACE WS* CLOSE_BRACE
;
/* sparql 1.1 update r46 */
expression
: conditionalOrExpression
;
/* sparql 1.1 update r47 */
conditionalOrExpression
: conditionalAndExpression ( OR conditionalAndExpression )*
;
/* sparql 1.1 update r48 */
conditionalAndExpression
: valueLogical ( AND valueLogical )*
;
/* sparql 1.1 update r49 */
valueLogical
: relationalExpression
;
/* sparql 1.1 update r50 */
relationalExpression
: numericExpression
( EQUAL numericExpression
| NOT_EQUAL numericExpression
| LESS numericExpression
| GREATER numericExpression
| LESS_EQUAL numericExpression
| GREATER_EQUAL numericExpression
)?
;
/* sparql 1.1 update r51 */
numericExpression
: additiveExpression
;
/* sparql 1.1 update r52 */
additiveExpression
: multiplicativeExpression
( PLUS multiplicativeExpression
| MINUS multiplicativeExpression
| numericLiteralPositive
| numericLiteralNegative
)*
;
/* sparql 1.1 update r53 */
multiplicativeExpression
: unaryExpression ( ASTERISK unaryExpression | DIVIDE unaryExpression )*
;
/* sparql 1.1 update r54 */
unaryExpression
: NOT_SIGN primaryExpression
| PLUS primaryExpression
| MINUS primaryExpression
| primaryExpression
;
/* sparql 1.1 update r55 */
primaryExpression
: brackettedExpression
| builtInCall
| iriRefOrFunction
| rdfLiteral
| numericLiteral
| booleanLiteral
| variable
;
/* sparql 1.1 update r56 */
brackettedExpression
: OPEN_BRACE expression CLOSE_BRACE
;
/* sparql 1.1 update r57 */
builtInCall
: STR OPEN_BRACE expression CLOSE_BRACE
| LANG OPEN_BRACE expression CLOSE_BRACE
| LANGMATCHES OPEN_BRACE expression COMMA expression CLOSE_BRACE
| DATATYPE OPEN_BRACE expression CLOSE_BRACE
| BOUND OPEN_BRACE variable CLOSE_BRACE
| SAMETERM OPEN_BRACE expression COMMA expression CLOSE_BRACE
| ISIRI OPEN_BRACE expression CLOSE_BRACE
| ISURI OPEN_BRACE expression CLOSE_BRACE
| ISBLANK OPEN_BRACE expression CLOSE_BRACE
| ISLITERAL OPEN_BRACE expression CLOSE_BRACE
| regexExpression
;
/* sparql 1.1 update r58 */
regexExpression
: REGEX OPEN_BRACE expression COMMA expression ( COMMA expression )? CLOSE_BRACE
;
/* sparql 1.1 update r59 */
iriRefOrFunction
: iriRef argList?
;
/* sparql 1.1 update r60 */
rdfLiteral
: string ( LANGTAG | ( REFERENCE iriRef ) )?
;
/* sparql 1.1 update r61 */
numericLiteral
: numericLiteralUnsigned
| numericLiteralPositive
| numericLiteralNegative
;
/* sparql 1.1 update r62 */
numericLiteralUnsigned
: INTEGER
| DECIMAL
| DOUBLE
;
/* sparql 1.1 update r63 */
numericLiteralPositive
: INTEGER_POSITIVE
| DECIMAL_POSITIVE
| DOUBLE_POSITIVE
;
/* sparql 1.1 update r64 */
numericLiteralNegative
: INTEGER_NEGATIVE
| DECIMAL_NEGATIVE
| DOUBLE_NEGATIVE
;
/* sparql 1.1 update r65 */
booleanLiteral
: TRUE
| FALSE
;
/* sparql 1.1 update r66 */
string
: STRING_LITERAL1
| STRING_LITERAL2
| STRING_LITERAL_LONG1
| STRING_LITERAL_LONG2
;
/* sparql 1.1 update r67 */
iriRef
: IRI_REF
| prefixedName
;
/* sparql 1.1 update r68 */
prefixedName
: PNAME_LN
| PNAME_NS
;
/* sparql 1.1 update r69 */
blankNode
: BLANK_NODE_LABEL
| OPEN_SQUARE_BRACE (WS)* CLOSE_SQUARE_BRACE
;