-
Notifications
You must be signed in to change notification settings - Fork 1
/
sparql12-grammar.ebnf
408 lines (407 loc) · 15.6 KB
/
sparql12-grammar.ebnf
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
/* SPARQL 1.2 Query Language
* version https://www.w3.org/TR/2024/WD-sparql12-query-20240921/
* extracted from https://www.w3.org/TR/sparql12-query/ on Wed Oct 9, 2024, 16:18 (UTC+03)
*/
QueryUnit
::= Query
Query ::= Prologue
( SelectQuery | ConstructQuery | DescribeQuery | AskQuery )
ValuesClause
UpdateUnit
::= Update
Prologue ::= ( BaseDecl | PrefixDecl )*
BaseDecl ::= 'BASE' IRIREF
PrefixDecl
::= 'PREFIX' PNAME_NS IRIREF
SelectQuery
::= SelectClause DatasetClause* WhereClause SolutionModifier
SubSelect
::= SelectClause WhereClause SolutionModifier ValuesClause
SelectClause
::= 'SELECT' ( 'DISTINCT' | 'REDUCED' )? ( ( Var | ( '(' Expression 'AS' Var ')' ) )+ | '*' )
ConstructQuery
::= 'CONSTRUCT' ( ConstructTemplate DatasetClause* WhereClause SolutionModifier | DatasetClause* 'WHERE' '{' TriplesTemplate? '}' SolutionModifier )
DescribeQuery
::= 'DESCRIBE' ( VarOrIri+ | '*' ) DatasetClause* WhereClause? SolutionModifier
AskQuery ::= 'ASK' DatasetClause* WhereClause SolutionModifier
DatasetClause
::= 'FROM' ( DefaultGraphClause | NamedGraphClause )
DefaultGraphClause
::= SourceSelector
NamedGraphClause
::= 'NAMED' SourceSelector
SourceSelector
::= iri
WhereClause
::= 'WHERE'? GroupGraphPattern
SolutionModifier
::= GroupClause? HavingClause? OrderClause? LimitOffsetClauses?
GroupClause
::= 'GROUP' 'BY' GroupCondition+
GroupCondition
::= BuiltInCall | FunctionCall | '(' Expression ( 'AS' Var )? ')' | Var
HavingClause
::= 'HAVING' HavingCondition+
HavingCondition
::= Constraint
OrderClause
::= 'ORDER' 'BY' OrderCondition+
OrderCondition
::= ( ( 'ASC' | 'DESC' ) BrackettedExpression )
| ( Constraint | Var )
LimitOffsetClauses
::= LimitClause OffsetClause? | OffsetClause LimitClause?
LimitClause
::= 'LIMIT' INTEGER
OffsetClause
::= 'OFFSET' INTEGER
ValuesClause
::= ( 'VALUES' DataBlock )?
Update ::= Prologue ( Update1 ( ';' Update )? )?
Update1 ::= Load | Clear | Drop | Add | Move | Copy | Create | DeleteWhere | Modify | InsertData | DeleteData
Load ::= 'LOAD' 'SILENT'? iri ( 'INTO' GraphRef )?
Clear ::= 'CLEAR' 'SILENT'? GraphRefAll
Drop ::= 'DROP' 'SILENT'? GraphRefAll
Create ::= 'CREATE' 'SILENT'? GraphRef
Add ::= 'ADD' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault
Move ::= 'MOVE' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault
Copy ::= 'COPY' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault
InsertData
::= 'INSERT DATA' QuadData
DeleteData
::= 'DELETE DATA' QuadData
DeleteWhere
::= 'DELETE WHERE' QuadPattern
Modify ::= ( 'WITH' iri )? ( DeleteClause InsertClause? | InsertClause ) UsingClause* 'WHERE' GroupGraphPattern
DeleteClause
::= 'DELETE' QuadPattern
InsertClause
::= 'INSERT' QuadPattern
UsingClause
::= 'USING' ( iri | 'NAMED' iri )
GraphOrDefault
::= 'DEFAULT' | 'GRAPH'? iri
GraphRef ::= 'GRAPH' iri
GraphRefAll
::= GraphRef | 'DEFAULT' | 'NAMED' | 'ALL'
QuadPattern
::= '{' Quads '}'
QuadData ::= '{' Quads '}'
Quads ::= TriplesTemplate? ( QuadsNotTriples '.'? TriplesTemplate? )*
QuadsNotTriples
::= 'GRAPH' VarOrIri '{' TriplesTemplate? '}'
TriplesTemplate
::= TriplesSameSubject ( '.' TriplesTemplate? )?
GroupGraphPattern
::= '{' ( SubSelect | GroupGraphPatternSub ) '}'
GroupGraphPatternSub
::= TriplesBlock? ( GraphPatternNotTriples '.'? TriplesBlock? )*
TriplesBlock
::= TriplesSameSubjectPath ( '.' TriplesBlock? )?
ReifiedTripleBlock
::= ReifiedTriple PropertyList
ReifiedTripleBlockPath
::= ReifiedTriple PropertyListPath
GraphPatternNotTriples
::= GroupOrUnionGraphPattern | OptionalGraphPattern | MinusGraphPattern | GraphGraphPattern | ServiceGraphPattern | Filter | Bind | InlineData
OptionalGraphPattern
::= 'OPTIONAL' GroupGraphPattern
GraphGraphPattern
::= 'GRAPH' VarOrIri GroupGraphPattern
ServiceGraphPattern
::= 'SERVICE' 'SILENT'? VarOrIri GroupGraphPattern
Bind ::= 'BIND' '(' Expression 'AS' Var ')'
InlineData
::= 'VALUES' DataBlock
DataBlock
::= InlineDataOneVar | InlineDataFull
InlineDataOneVar
::= Var '{' DataBlockValue* '}'
InlineDataFull
::= ( NIL | '(' Var* ')' ) '{' ( '(' DataBlockValue* ')' | NIL )* '}'
DataBlockValue
::= iri | RDFLiteral | NumericLiteral | BooleanLiteral | 'UNDEF' | TripleTermData
Reifier ::= '~' VarOrReifierId?
ReifierData
::= '~' ReifierId?
ReifierId
::= iri | BlankNode
VarOrReifierId
::= Var | ReifierId
MinusGraphPattern
::= 'MINUS' GroupGraphPattern
GroupOrUnionGraphPattern
::= GroupGraphPattern ( 'UNION' GroupGraphPattern )*
Filter ::= 'FILTER' Constraint
Constraint
::= BrackettedExpression | BuiltInCall | FunctionCall
FunctionCall
::= iri ArgList
ArgList ::= NIL | '(' 'DISTINCT'? Expression ( ',' Expression )* ')'
ExpressionList
::= NIL | '(' Expression ( ',' Expression )* ')'
ConstructTemplate
::= '{' ConstructTriples? '}'
ConstructTriples
::= TriplesSameSubject ( '.' ConstructTriples? )?
TriplesSameSubject
::= VarOrTerm PropertyListNotEmpty | TriplesNode PropertyList | ReifiedTripleBlock
PropertyList
::= PropertyListNotEmpty?
PropertyListNotEmpty
::= Verb ObjectList ( ';' ( Verb ObjectList )? )*
Verb ::= VarOrIri | 'a'
ObjectList
::= Object ( ',' Object )*
Object ::= GraphNode Annotation
TriplesSameSubjectPath
::= VarOrTerm PropertyListPathNotEmpty | TriplesNodePath PropertyListPath | ReifiedTripleBlockPath
PropertyListPath
::= PropertyListPathNotEmpty?
PropertyListPathNotEmpty
::= ( VerbPath | VerbSimple ) ObjectListPath ( ';' ( ( VerbPath | VerbSimple ) ObjectListPath )? )*
VerbPath ::= Path
VerbSimple
::= Var
ObjectListPath
::= ObjectPath ( ',' ObjectPath )*
ObjectPath
::= GraphNodePath AnnotationPath
Path ::= PathAlternative
PathAlternative
::= PathSequence ( '|' PathSequence )*
PathSequence
::= PathEltOrInverse ( '/' PathEltOrInverse )*
PathElt ::= PathPrimary PathMod?
PathEltOrInverse
::= PathElt | '^' PathElt
PathMod ::= '?' | '*' | '+'
PathPrimary
::= iri | 'a' | '!' PathNegatedPropertySet | '(' Path ')'
PathNegatedPropertySet
::= PathOneInPropertySet | '(' ( PathOneInPropertySet ( '|' PathOneInPropertySet )* )? ')'
PathOneInPropertySet
::= iri | 'a' | '^' ( iri | 'a' )
Integer ::= INTEGER
TriplesNode
::= Collection | BlankNodePropertyList
BlankNodePropertyList
::= '[' PropertyListNotEmpty ']'
TriplesNodePath
::= CollectionPath | BlankNodePropertyListPath
BlankNodePropertyListPath
::= '[' PropertyListPathNotEmpty ']'
Collection
::= '(' GraphNode+ ')'
CollectionPath
::= '(' GraphNodePath+ ')'
AnnotationPath
::= ( Reifier | AnnotationBlockPath )*
AnnotationBlockPath
::= '{|' PropertyListPathNotEmpty '|}'
Annotation
::= ( Reifier | AnnotationBlock )*
AnnotationBlock
::= '{|' PropertyListNotEmpty '|}'
GraphNode
::= VarOrTerm | TriplesNode | ReifiedTriple
GraphNodePath
::= VarOrTerm | TriplesNodePath | ReifiedTriple
VarOrTerm
::= Var | iri | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | NIL | TripleTerm
ReifiedTriple
::= '<<' ReifiedTripleSubject Verb ReifiedTripleObject Reifier? '>>'
ReifiedTripleSubject
::= Var | iri | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | ReifiedTriple | NIL
ReifiedTripleObject
::= Var | iri | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | ReifiedTriple | NIL
TripleTerm
::= '<<(' VarOrTerm Verb VarOrTerm ')>>'
TripleTermData
::= '<<(' DataValueTerm ( iri | 'a' ) DataValueTerm ')>>'
DataValueTerm
::= iri | RDFLiteral | NumericLiteral | BooleanLiteral | TripleTermData
VarOrIri ::= Var | iri
Var ::= VAR1 | VAR2
Expression
::= ConditionalOrExpression
ConditionalOrExpression
::= ConditionalAndExpression ( '||' ConditionalAndExpression )*
ConditionalAndExpression
::= ValueLogical ( '&&' ValueLogical )*
ValueLogical
::= RelationalExpression
RelationalExpression
::= NumericExpression ( '=' NumericExpression | '!=' NumericExpression | '<' NumericExpression | '>' NumericExpression | '<=' NumericExpression | '>=' NumericExpression | 'IN' ExpressionList | 'NOT' 'IN' ExpressionList )?
NumericExpression
::= AdditiveExpression
AdditiveExpression
::= MultiplicativeExpression ( '+' MultiplicativeExpression | '-' MultiplicativeExpression | ( NumericLiteralPositive | NumericLiteralNegative ) ( ( '*' UnaryExpression ) | ( '/' UnaryExpression ) )* )*
MultiplicativeExpression
::= UnaryExpression ( '*' UnaryExpression | '/' UnaryExpression )*
UnaryExpression
::= '!' PrimaryExpression
| '+' PrimaryExpression
| '-' PrimaryExpression
| PrimaryExpression
PrimaryExpression
::= BrackettedExpression | BuiltInCall | iriOrFunction | RDFLiteral | NumericLiteral | BooleanLiteral | Var | ExprTripleTerm
ExprVarOrTerm
::= iri | RDFLiteral | NumericLiteral | BooleanLiteral | Var | ExprTripleTerm
ExprTripleTerm
::= '<<(' ExprVarOrTerm Verb ExprVarOrTerm ')>>'
BrackettedExpression
::= '(' Expression ')'
BuiltInCall
::= Aggregate
| 'STR' '(' Expression ')'
| 'LANG' '(' Expression ')'
| 'LANGMATCHES' '(' Expression ',' Expression ')'
| 'LANGDIR' '(' Expression ')'
| 'DATATYPE' '(' Expression ')'
| 'BOUND' '(' Var ')'
| 'IRI' '(' Expression ')'
| 'URI' '(' Expression ')'
| 'BNODE' ( '(' Expression ')' | NIL )
| 'RAND' NIL
| 'ABS' '(' Expression ')'
| 'CEIL' '(' Expression ')'
| 'FLOOR' '(' Expression ')'
| 'ROUND' '(' Expression ')'
| 'CONCAT' ExpressionList
| SubstringExpression
| 'STRLEN' '(' Expression ')'
| StrReplaceExpression
| 'UCASE' '(' Expression ')'
| 'LCASE' '(' Expression ')'
| 'ENCODE_FOR_URI' '(' Expression ')'
| 'CONTAINS' '(' Expression ',' Expression ')'
| 'STRSTARTS' '(' Expression ',' Expression ')'
| 'STRENDS' '(' Expression ',' Expression ')'
| 'STRBEFORE' '(' Expression ',' Expression ')'
| 'STRAFTER' '(' Expression ',' Expression ')'
| 'YEAR' '(' Expression ')'
| 'MONTH' '(' Expression ')'
| 'DAY' '(' Expression ')'
| 'HOURS' '(' Expression ')'
| 'MINUTES' '(' Expression ')'
| 'SECONDS' '(' Expression ')'
| 'TIMEZONE' '(' Expression ')'
| 'TZ' '(' Expression ')'
| 'NOW' NIL
| 'UUID' NIL
| 'STRUUID' NIL
| 'MD5' '(' Expression ')'
| 'SHA1' '(' Expression ')'
| 'SHA256' '(' Expression ')'
| 'SHA384' '(' Expression ')'
| 'SHA512' '(' Expression ')'
| 'COALESCE' ExpressionList
| 'IF' '(' Expression ',' Expression ',' Expression ')'
| 'STRLANG' '(' Expression ',' Expression ')'
| 'STRLANGDIR' '(' Expression ',' Expression ',' Expression ')'
| 'STRDT' '(' Expression ',' Expression ')'
| 'sameTerm' '(' Expression ',' Expression ')'
| 'isIRI' '(' Expression ')'
| 'isURI' '(' Expression ')'
| 'isBLANK' '(' Expression ')'
| 'isLITERAL' '(' Expression ')'
| 'isNUMERIC' '(' Expression ')'
| 'hasLANG' '(' Expression ')'
| 'hasLANGDIR' '(' Expression ')'
| RegexExpression
| ExistsFunc
| NotExistsFunc
| 'isTRIPLE' '(' Expression ')'
| 'TRIPLE' '(' Expression ',' Expression ',' Expression ')'
| 'SUBJECT' '(' Expression ')'
| 'PREDICATE' '(' Expression ')'
| 'OBJECT' '(' Expression ')'
RegexExpression
::= 'REGEX' '(' Expression ',' Expression ( ',' Expression )? ')'
SubstringExpression
::= 'SUBSTR' '(' Expression ',' Expression ( ',' Expression )? ')'
StrReplaceExpression
::= 'REPLACE' '(' Expression ',' Expression ',' Expression ( ',' Expression )? ')'
ExistsFunc
::= 'EXISTS' GroupGraphPattern
NotExistsFunc
::= 'NOT' 'EXISTS' GroupGraphPattern
Aggregate
::= 'COUNT' '(' 'DISTINCT'? ( '*' | Expression ) ')'
| 'SUM' '(' 'DISTINCT'? Expression ')'
| 'MIN' '(' 'DISTINCT'? Expression ')'
| 'MAX' '(' 'DISTINCT'? Expression ')'
| 'AVG' '(' 'DISTINCT'? Expression ')'
| 'SAMPLE' '(' 'DISTINCT'? Expression ')'
| 'GROUP_CONCAT' '(' 'DISTINCT'? Expression ( ';' 'SEPARATOR' '=' String )? ')'
iriOrFunction
::= iri ArgList?
RDFLiteral
::= String ( LANG_DIR | '^^' iri )?
NumericLiteral
::= NumericLiteralUnsigned | NumericLiteralPositive | NumericLiteralNegative
NumericLiteralUnsigned
::= INTEGER | DECIMAL | DOUBLE
NumericLiteralPositive
::= INTEGER_POSITIVE | DECIMAL_POSITIVE | DOUBLE_POSITIVE
NumericLiteralNegative
::= INTEGER_NEGATIVE | DECIMAL_NEGATIVE | DOUBLE_NEGATIVE
BooleanLiteral
::= 'true' | 'false'
String ::= STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2
iri ::= IRIREF | PrefixedName
PrefixedName
::= PNAME_LN | PNAME_NS
BlankNode
::= BLANK_NODE_LABEL | ANON
IRIREF ::= '<' ([^<>"{}|^`\]-[#x00-#x20])* '>'
PNAME_NS ::= PN_PREFIX? ':'
PNAME_LN ::= PNAME_NS PN_LOCAL
BLANK_NODE_LABEL
::= '_:' ( PN_CHARS_U | [0-9] ) ((PN_CHARS|'.')* PN_CHARS)?
VAR1 ::= '?' VARNAME
VAR2 ::= '$' VARNAME
LANG_DIR ::= '@' [a-zA-Z]+ ('-' [a-zA-Z0-9]+)* ('--' [a-zA-Z]+)?
INTEGER ::= [0-9]+
DECIMAL ::= [0-9]* '.' [0-9]+
DOUBLE ::= [0-9]+ '.' [0-9]* EXPONENT | '.' ([0-9])+ EXPONENT | ([0-9])+ EXPONENT
INTEGER_POSITIVE
::= '+' INTEGER
DECIMAL_POSITIVE
::= '+' DECIMAL
DOUBLE_POSITIVE
::= '+' DOUBLE
INTEGER_NEGATIVE
::= '-' INTEGER
DECIMAL_NEGATIVE
::= '-' DECIMAL
DOUBLE_NEGATIVE
::= '-' DOUBLE
EXPONENT ::= [eE] [+-]? [0-9]+
STRING_LITERAL1
::= "'" ( ([^#x27#x5C#xA#xD]) | ECHAR )* "'"
STRING_LITERAL2
::= '"' ( ([^#x22#x5C#xA#xD]) | ECHAR )* '"'
STRING_LITERAL_LONG1
::= "'''" ( ( "'" | "''" )? ( [^'\] | ECHAR ) )* "'''"
STRING_LITERAL_LONG2
::= '"""' ( ( '"' | '""' )? ( [^"\] | ECHAR ) )* '"""'
ECHAR ::= '\' [tbnrf\"']
NIL ::= '(' WS* ')'
WS ::= #x20 | #x9 | #xD | #xA
ANON ::= '[' WS* ']'
PN_CHARS_BASE
::= [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
PN_CHARS_U
::= PN_CHARS_BASE | '_'
VARNAME ::= ( PN_CHARS_U | [0-9] ) ( PN_CHARS_U | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] )*
PN_CHARS ::= PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
PN_PREFIX
::= PN_CHARS_BASE ((PN_CHARS|'.')* PN_CHARS)?
PN_LOCAL ::= (PN_CHARS_U | ':' | [0-9] | PLX ) ((PN_CHARS | '.' | ':' | PLX)* (PN_CHARS | ':' | PLX) )?
PLX ::= PERCENT | PN_LOCAL_ESC
PERCENT ::= '%' HEX HEX
HEX ::= [0-9] | [A-F] | [a-f]
PN_LOCAL_ESC
::= '\' ( '_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%' )