27
27
from rdflib .compat import decodeUnicodeEscape
28
28
29
29
from . import operators as op
30
- from .parserutils import Comp , Param , ParamList
30
+ from .parserutils import Comp , Param
31
31
32
32
# from pyparsing import Keyword as CaseSensitiveKeyword
33
33
@@ -427,9 +427,9 @@ def expandCollection(terms):
427
427
)
428
428
429
429
# [45] GraphOrDefault ::= 'DEFAULT' | 'GRAPH'? iri
430
- GraphOrDefault = ParamList ( "graph" , Keyword ("DEFAULT" )) | Optional (
430
+ GraphOrDefault = Group ( Param ( "graph" , Keyword ("DEFAULT" ) )) | Optional (
431
431
Keyword ("GRAPH" )
432
- ) + ParamList ( "graph" , iri )
432
+ ) + Group ( Param ( "graph" , iri ) )
433
433
434
434
# [65] DataBlockValue ::= iri | RDFLiteral | NumericLiteral | BooleanLiteral | 'UNDEF'
435
435
DataBlockValue = iri | RDFLiteral | NumericLiteral | BooleanLiteral | Keyword ("UNDEF" )
@@ -466,11 +466,11 @@ def expandCollection(terms):
466
466
# [95] PathNegatedPropertySet ::= PathOneInPropertySet | '(' ( PathOneInPropertySet ( '|' PathOneInPropertySet )* )? ')'
467
467
PathNegatedPropertySet = Comp (
468
468
"PathNegatedPropertySet" ,
469
- ParamList ( "part" , PathOneInPropertySet )
469
+ Group ( Param ( "part" , PathOneInPropertySet ) )
470
470
| "("
471
471
+ Optional (
472
- ParamList ( "part" , PathOneInPropertySet )
473
- + ZeroOrMore ("|" + ParamList ( "part" , PathOneInPropertySet ))
472
+ Group ( Param ( "part" , PathOneInPropertySet ) )
473
+ + ZeroOrMore ("|" + Group ( Param ( "part" , PathOneInPropertySet ) ))
474
474
)
475
475
+ ")" ,
476
476
)
@@ -498,15 +498,16 @@ def expandCollection(terms):
498
498
# [90] PathSequence ::= PathEltOrInverse ( '/' PathEltOrInverse )*
499
499
PathSequence = Comp (
500
500
"PathSequence" ,
501
- ParamList ( "part" , PathEltOrInverse )
502
- + ZeroOrMore ("/" + ParamList ( "part" , PathEltOrInverse )),
501
+ Group ( Param ( "part" , PathEltOrInverse ) )
502
+ + ZeroOrMore ("/" + Group ( Param ( "part" , PathEltOrInverse ) )),
503
503
)
504
504
505
505
506
506
# [89] PathAlternative ::= PathSequence ( '|' PathSequence )*
507
507
PathAlternative = Comp (
508
508
"PathAlternative" ,
509
- ParamList ("part" , PathSequence ) + ZeroOrMore ("|" + ParamList ("part" , PathSequence )),
509
+ Group (Param ("part" , PathSequence ))
510
+ + ZeroOrMore ("|" + Group (Param ("part" , PathSequence ))),
510
511
)
511
512
512
513
# [88] Path ::= PathAlternative
@@ -583,8 +584,8 @@ def expandCollection(terms):
583
584
# To accommodate arbitrary amounts of triples this rule is rewritten to not be
584
585
# recursive:
585
586
# [52*] TriplesTemplate ::= TriplesSameSubject ( '.' TriplesSameSubject? )*
586
- TriplesTemplate = ParamList ( "triples" , TriplesSameSubject ) + ZeroOrMore (
587
- Suppress ("." ) + Optional (ParamList ( "triples" , TriplesSameSubject ))
587
+ TriplesTemplate = Group ( Param ( "triples" , TriplesSameSubject ) ) + ZeroOrMore (
588
+ Suppress ("." ) + Optional (Group ( Param ( "triples" , TriplesSameSubject ) ))
588
589
)
589
590
590
591
# [51] QuadsNotTriples ::= 'GRAPH' VarOrIri '{' Optional(TriplesTemplate) '}'
@@ -598,7 +599,7 @@ def expandCollection(terms):
598
599
"Quads" ,
599
600
Optional (TriplesTemplate )
600
601
+ ZeroOrMore (
601
- ParamList ( "quadsNotTriples" , QuadsNotTriples )
602
+ Group ( Param ( "quadsNotTriples" , QuadsNotTriples ) )
602
603
+ Optional (Suppress ("." ))
603
604
+ Optional (TriplesTemplate )
604
605
),
@@ -618,7 +619,7 @@ def expandCollection(terms):
618
619
619
620
# [55] TriplesBlock ::= TriplesSameSubjectPath ( '.' Optional(TriplesBlock) )?
620
621
TriplesBlock = Forward ()
621
- TriplesBlock <<= ParamList ( "triples" , TriplesSameSubjectPath ) + Optional (
622
+ TriplesBlock <<= Group ( Param ( "triples" , TriplesSameSubjectPath ) ) + Optional (
622
623
Suppress ("." ) + Optional (TriplesBlock )
623
624
)
624
625
@@ -631,8 +632,8 @@ def expandCollection(terms):
631
632
# [67] GroupOrUnionGraphPattern ::= GroupGraphPattern ( 'UNION' GroupGraphPattern )*
632
633
GroupOrUnionGraphPattern = Comp (
633
634
"GroupOrUnionGraphPattern" ,
634
- ParamList ( "graph" , GroupGraphPattern )
635
- + ZeroOrMore (Keyword ("UNION" ) + ParamList ( "graph" , GroupGraphPattern )),
635
+ Group ( Param ( "graph" , GroupGraphPattern ) )
636
+ + ZeroOrMore (Keyword ("UNION" ) + Group ( Param ( "graph" , GroupGraphPattern ) )),
636
637
)
637
638
638
639
@@ -1000,7 +1001,7 @@ def expandCollection(terms):
1000
1001
NIL
1001
1002
| "("
1002
1003
+ Param ("distinct" , _Distinct )
1003
- + delimitedList (ParamList ( "expr" , Expression ))
1004
+ + delimitedList (Group ( Param ( "expr" , Expression ) ))
1004
1005
+ ")"
1005
1006
)
1006
1007
@@ -1045,8 +1046,8 @@ def expandCollection(terms):
1045
1046
"MultiplicativeExpression" ,
1046
1047
Param ("expr" , UnaryExpression )
1047
1048
+ ZeroOrMore (
1048
- ParamList ( "op" , "*" ) + ParamList ( "other" , UnaryExpression )
1049
- | ParamList ( "op" , "/" ) + ParamList ( "other" , UnaryExpression )
1049
+ Group ( Param ( "op" , "*" )) + Group ( Param ( "other" , UnaryExpression ) )
1050
+ | Group ( Param ( "op" , "/" )) + Group ( Param ( "other" , UnaryExpression ) )
1050
1051
),
1051
1052
).setEvalFn (op .MultiplicativeExpression )
1052
1053
@@ -1063,8 +1064,8 @@ def expandCollection(terms):
1063
1064
"AdditiveExpression" ,
1064
1065
Param ("expr" , MultiplicativeExpression )
1065
1066
+ ZeroOrMore (
1066
- ParamList ( "op" , "+" ) + ParamList ( "other" , MultiplicativeExpression )
1067
- | ParamList ( "op" , "-" ) + ParamList ( "other" , MultiplicativeExpression )
1067
+ Group ( Param ( "op" , "+" )) + Group ( Param ( "other" , MultiplicativeExpression ) )
1068
+ | Group ( Param ( "op" , "-" )) + Group ( Param ( "other" , MultiplicativeExpression ) )
1068
1069
),
1069
1070
).setEvalFn (op .AdditiveExpression )
1070
1071
@@ -1099,14 +1100,15 @@ def expandCollection(terms):
1099
1100
# [112] ConditionalAndExpression ::= ValueLogical ( '&&' ValueLogical )*
1100
1101
ConditionalAndExpression = Comp (
1101
1102
"ConditionalAndExpression" ,
1102
- Param ("expr" , ValueLogical ) + ZeroOrMore ("&&" + ParamList ("other" , ValueLogical )),
1103
+ Param ("expr" , ValueLogical )
1104
+ + ZeroOrMore ("&&" + Group (Param ("other" , ValueLogical ))),
1103
1105
).setEvalFn (op .ConditionalAndExpression )
1104
1106
1105
1107
# [111] ConditionalOrExpression ::= ConditionalAndExpression ( '||' ConditionalAndExpression )*
1106
1108
ConditionalOrExpression = Comp (
1107
1109
"ConditionalOrExpression" ,
1108
1110
Param ("expr" , ConditionalAndExpression )
1109
- + ZeroOrMore ("||" + ParamList ( "other" , ConditionalAndExpression )),
1111
+ + ZeroOrMore ("||" + Group ( Param ( "other" , ConditionalAndExpression ) )),
1110
1112
).setEvalFn (op .ConditionalOrExpression )
1111
1113
1112
1114
# [110] Expression ::= ConditionalOrExpression
@@ -1154,7 +1156,7 @@ def expandCollection(terms):
1154
1156
"GroupClause" ,
1155
1157
Keyword ("GROUP" )
1156
1158
+ Keyword ("BY" )
1157
- + OneOrMore (ParamList ( "condition" , GroupCondition )),
1159
+ + OneOrMore (Group ( Param ( "condition" , GroupCondition ) )),
1158
1160
)
1159
1161
1160
1162
@@ -1222,7 +1224,7 @@ def expandCollection(terms):
1222
1224
Param ("delete" , DeleteClause ) + Optional (Param ("insert" , InsertClause ))
1223
1225
| Param ("insert" , InsertClause )
1224
1226
)
1225
- + ZeroOrMore (ParamList ( "using" , UsingClause ))
1227
+ + ZeroOrMore (Group ( Param ( "using" , UsingClause ) ))
1226
1228
+ Keyword ("WHERE" )
1227
1229
+ Param ("where" , GroupGraphPattern ),
1228
1230
)
@@ -1246,17 +1248,22 @@ def expandCollection(terms):
1246
1248
1247
1249
# [63] InlineDataOneVar ::= Var '{' ZeroOrMore(DataBlockValue) '}'
1248
1250
InlineDataOneVar = (
1249
- ParamList ("var" , Var ) + "{" + ZeroOrMore (ParamList ("value" , DataBlockValue )) + "}"
1251
+ Group (Param ("var" , Var ))
1252
+ + "{"
1253
+ + ZeroOrMore (Group (Param ("value" , DataBlockValue )))
1254
+ + "}"
1250
1255
)
1251
1256
1252
1257
# [64] InlineDataFull ::= ( NIL | '(' ZeroOrMore(Var) ')' ) '{' ( '(' ZeroOrMore(DataBlockValue) ')' | NIL )* '}'
1253
1258
InlineDataFull = (
1254
- (NIL | "(" + ZeroOrMore (ParamList ( "var" , Var )) + ")" )
1259
+ (NIL | "(" + ZeroOrMore (Group ( Param ( "var" , Var ) )) + ")" )
1255
1260
+ "{"
1256
1261
+ ZeroOrMore (
1257
- ParamList (
1258
- "value" ,
1259
- Group (Suppress ("(" ) + ZeroOrMore (DataBlockValue ) + Suppress (")" ) | NIL ),
1262
+ Group (
1263
+ Param (
1264
+ "value" ,
1265
+ Group (Suppress ("(" ) + ZeroOrMore (DataBlockValue ) + Suppress (")" ) | NIL ),
1266
+ )
1260
1267
)
1261
1268
)
1262
1269
+ "}"
@@ -1274,7 +1281,7 @@ def expandCollection(terms):
1274
1281
1275
1282
# [74] ConstructTriples ::= TriplesSameSubject ( '.' Optional(ConstructTriples) )?
1276
1283
ConstructTriples = Forward ()
1277
- ConstructTriples <<= ParamList ( "template" , TriplesSameSubject ) + Optional (
1284
+ ConstructTriples <<= Group ( Param ( "template" , TriplesSameSubject ) ) + Optional (
1278
1285
Suppress ("." ) + Optional (ConstructTriples )
1279
1286
)
1280
1287
@@ -1331,11 +1338,11 @@ def expandCollection(terms):
1331
1338
# [54] GroupGraphPatternSub ::= Optional(TriplesBlock) ( GraphPatternNotTriples '.'? Optional(TriplesBlock) )*
1332
1339
GroupGraphPatternSub = Comp (
1333
1340
"GroupGraphPatternSub" ,
1334
- Optional (ParamList ( "part" , Comp ("TriplesBlock" , TriplesBlock )))
1341
+ Optional (Group ( Param ( "part" , Comp ("TriplesBlock" , TriplesBlock ) )))
1335
1342
+ ZeroOrMore (
1336
- ParamList ( "part" , GraphPatternNotTriples )
1343
+ Group ( Param ( "part" , GraphPatternNotTriples ) )
1337
1344
+ Optional ("." )
1338
- + Optional (ParamList ( "part" , Comp ("TriplesBlock" , TriplesBlock )))
1345
+ + Optional (Group ( Param ( "part" , Comp ("TriplesBlock" , TriplesBlock ) )))
1339
1346
),
1340
1347
)
1341
1348
@@ -1347,7 +1354,7 @@ def expandCollection(terms):
1347
1354
# [21] HavingClause ::= 'HAVING' HavingCondition+
1348
1355
HavingClause = Comp (
1349
1356
"HavingClause" ,
1350
- Keyword ("HAVING" ) + OneOrMore (ParamList ( "condition" , HavingCondition )),
1357
+ Keyword ("HAVING" ) + OneOrMore (Group ( Param ( "condition" , HavingCondition ) )),
1351
1358
)
1352
1359
1353
1360
# [24] OrderCondition ::= ( ( 'ASC' | 'DESC' ) BrackettedExpression )
@@ -1364,7 +1371,7 @@ def expandCollection(terms):
1364
1371
"OrderClause" ,
1365
1372
Keyword ("ORDER" )
1366
1373
+ Keyword ("BY" )
1367
- + OneOrMore (ParamList ( "condition" , OrderCondition )),
1374
+ + OneOrMore (Group ( Param ( "condition" , OrderCondition ) )),
1368
1375
)
1369
1376
1370
1377
# [26] LimitClause ::= 'LIMIT' INTEGER
@@ -1394,19 +1401,21 @@ def expandCollection(terms):
1394
1401
+ Optional (Param ("modifier" , Keyword ("DISTINCT" ) | Keyword ("REDUCED" )))
1395
1402
+ (
1396
1403
OneOrMore (
1397
- ParamList (
1398
- "projection" ,
1399
- Comp (
1400
- "vars" ,
1401
- Param ("var" , Var )
1402
- | (
1403
- Literal ("(" )
1404
- + Param ("expr" , Expression )
1405
- + Keyword ("AS" )
1406
- + Param ("evar" , Var )
1407
- + ")"
1404
+ Group (
1405
+ Param (
1406
+ "projection" ,
1407
+ Comp (
1408
+ "vars" ,
1409
+ Param ("var" , Var )
1410
+ | (
1411
+ Literal ("(" )
1412
+ + Param ("expr" , Expression )
1413
+ + Keyword ("AS" )
1414
+ + Param ("evar" , Var )
1415
+ + ")"
1416
+ ),
1408
1417
),
1409
- ),
1418
+ )
1410
1419
)
1411
1420
)
1412
1421
| "*"
@@ -1428,7 +1437,7 @@ def expandCollection(terms):
1428
1437
SelectQuery = Comp (
1429
1438
"SelectQuery" ,
1430
1439
SelectClause
1431
- + ZeroOrMore (ParamList ( "datasetClause" , DatasetClause ))
1440
+ + ZeroOrMore (Group ( Param ( "datasetClause" , DatasetClause ) ))
1432
1441
+ WhereClause
1433
1442
+ SolutionModifier
1434
1443
+ ValuesClause ,
@@ -1442,19 +1451,19 @@ def expandCollection(terms):
1442
1451
Keyword ("CONSTRUCT" )
1443
1452
+ (
1444
1453
ConstructTemplate
1445
- + ZeroOrMore (ParamList ( "datasetClause" , DatasetClause ))
1454
+ + ZeroOrMore (Group ( Param ( "datasetClause" , DatasetClause ) ))
1446
1455
+ WhereClause
1447
1456
+ SolutionModifier
1448
1457
+ ValuesClause
1449
- | ZeroOrMore (ParamList ( "datasetClause" , DatasetClause ))
1458
+ | ZeroOrMore (Group ( Param ( "datasetClause" , DatasetClause ) ))
1450
1459
+ Keyword ("WHERE" )
1451
1460
+ "{"
1452
1461
+ Optional (
1453
1462
Param (
1454
1463
"where" ,
1455
1464
Comp (
1456
1465
"FakeGroupGraphPatten" ,
1457
- ParamList ( "part" , Comp ("TriplesBlock" , TriplesTemplate )),
1466
+ Group ( Param ( "part" , Comp ("TriplesBlock" , TriplesTemplate ) )),
1458
1467
),
1459
1468
)
1460
1469
)
@@ -1478,7 +1487,7 @@ def expandCollection(terms):
1478
1487
DescribeQuery = Comp (
1479
1488
"DescribeQuery" ,
1480
1489
Keyword ("DESCRIBE" )
1481
- + (OneOrMore (ParamList ( "var" , VarOrIri )) | "*" )
1490
+ + (OneOrMore (Group ( Param ( "var" , VarOrIri ) )) | "*" )
1482
1491
+ Param ("datasetClause" , ZeroOrMore (DatasetClause ))
1483
1492
+ Optional (WhereClause )
1484
1493
+ SolutionModifier
@@ -1487,8 +1496,8 @@ def expandCollection(terms):
1487
1496
1488
1497
# [29] Update ::= Prologue ( Update1 ( ';' Update )? )?
1489
1498
Update = Forward ()
1490
- Update <<= ParamList ( "prologue" , Prologue ) + Optional (
1491
- ParamList ( "request" , Update1 ) + Optional (";" + Update )
1499
+ Update <<= Group ( Param ( "prologue" , Prologue ) ) + Optional (
1500
+ Group ( Param ( "request" , Update1 ) ) + Optional (";" + Update )
1492
1501
)
1493
1502
1494
1503
0 commit comments