@traqula/rules-sparql-1-2 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/grammar.js CHANGED
@@ -1,12 +1,6 @@
1
- /**
2
- * This module will define patch rules that should be used in combination with the sparql11 grammar to create
3
- * a sparql12 grammar.
4
- * Rules in this module redefine the return type of core grammar rules.
5
- * It is therefore essential that the parser retypes the rules from the core grammar.
6
- */
7
- import { funcExpr1, funcExpr3, gram as S11, lex as l11, CommonIRIs, } from '@traqula/rules-sparql-1-1';
1
+ import { CommonIRIs, funcExpr1, funcExpr3, gram as S11, lex as l11 } from '@traqula/rules-sparql-1-1';
8
2
  import * as l12 from './lexer';
9
- import { langTagHasCorrectDomain } from './validator';
3
+ import { langTagHasCorrectRange } from './validator';
10
4
  /**
11
5
  *[[7]](https://www.w3.org/TR/sparql12-query/#rVersionDecl)
12
6
  */
@@ -14,7 +8,7 @@ export const versionDecl = {
14
8
  name: 'versionDecl',
15
9
  impl: ({ ACTION, SUBRULE, CONSUME }) => (C) => {
16
10
  const versionToken = CONSUME(l12.version);
17
- const identifier = SUBRULE(versionSpecifier, undefined);
11
+ const identifier = SUBRULE(versionSpecifier);
18
12
  return ACTION(() => C.factory.contextDefinitionVersion(identifier.val, C.factory.sourceLocation(versionToken, identifier)));
19
13
  },
20
14
  gImpl: ({ PRINT_WORDS }) => (ast, { factory: F }) => {
@@ -38,31 +32,31 @@ export const versionSpecifier = {
38
32
  };
39
33
  /**
40
34
  * OVERRIDING RULE {@link S11.prologue}
41
- * [[8]](https://www.w3.org/TR/sparql12-query/#rVersionSpecifier)
35
+ * [[4]](https://www.w3.org/TR/sparql12-query/#rPrologue)
42
36
  */
43
37
  export const prologue = {
44
38
  name: 'prologue',
45
39
  impl: ({ SUBRULE, MANY, OR }) => () => {
46
40
  const result = [];
47
41
  MANY(() => OR([
48
- { ALT: () => result.push(SUBRULE(S11.baseDecl, undefined)) },
42
+ { ALT: () => result.push(SUBRULE(S11.baseDecl)) },
49
43
  // TODO: the [spec](https://www.w3.org/TR/sparql11-query/#iriRefs) says you cannot redefine prefixes.
50
44
  // We might need to check this.
51
- { ALT: () => result.push(SUBRULE(S11.prefixDecl, undefined)) },
52
- { ALT: () => result.push(SUBRULE(versionDecl, undefined)) },
45
+ { ALT: () => result.push(SUBRULE(S11.prefixDecl)) },
46
+ { ALT: () => result.push(SUBRULE(versionDecl)) },
53
47
  ]));
54
48
  return result;
55
49
  },
56
50
  gImpl: ({ SUBRULE }) => (ast, { factory: F }) => {
57
51
  for (const context of ast) {
58
52
  if (F.isContextDefinitionBase(context)) {
59
- SUBRULE(S11.baseDecl, context, undefined);
53
+ SUBRULE(S11.baseDecl, context);
60
54
  }
61
55
  else if (F.isContextDefinitionPrefix(context)) {
62
- SUBRULE(S11.prefixDecl, context, undefined);
56
+ SUBRULE(S11.prefixDecl, context);
63
57
  }
64
58
  else if (F.isContextDefinitionVersion(context)) {
65
- SUBRULE(versionDecl, context, undefined);
59
+ SUBRULE(versionDecl, context);
66
60
  }
67
61
  }
68
62
  },
@@ -71,8 +65,8 @@ function reifiedTripleBlockImpl(name, allowPath) {
71
65
  return {
72
66
  name,
73
67
  impl: ({ ACTION, SUBRULE }) => (C) => {
74
- const triple = SUBRULE(reifiedTriple, undefined);
75
- const properties = SUBRULE(allowPath ? S11.propertyListPath : S11.propertyList, { subject: ACTION(() => C.factory.dematerialized(triple.identifier)) });
68
+ const triple = SUBRULE(reifiedTriple);
69
+ const properties = SUBRULE(allowPath ? S11.propertyListPath : S11.propertyList, ACTION(() => C.factory.dematerialized(triple.identifier)));
76
70
  return ACTION(() => [triple, ...properties]);
77
71
  },
78
72
  };
@@ -92,8 +86,8 @@ export const reifiedTripleBlockPath = reifiedTripleBlockImpl('reifiedTripleBlock
92
86
  export const dataBlockValue = {
93
87
  name: 'dataBlockValue',
94
88
  impl: $ => C => $.OR2([
95
- { ALT: () => S11.dataBlockValue.impl($)(C, undefined) },
96
- { ALT: () => $.SUBRULE(tripleTermData, undefined) },
89
+ { ALT: () => S11.dataBlockValue.impl($)(C) },
90
+ { ALT: () => $.SUBRULE(tripleTermData) },
97
91
  ]),
98
92
  };
99
93
  /**
@@ -102,13 +96,13 @@ export const dataBlockValue = {
102
96
  export const reifier = {
103
97
  name: 'reifier',
104
98
  impl: ({ ACTION, CONSUME, SUBRULE, OPTION }) => (C) => {
105
- CONSUME(l12.tilde);
106
- const reifier = OPTION(() => SUBRULE(varOrReifierId, undefined));
99
+ const tildeToken = CONSUME(l12.tilde);
100
+ const reifier = OPTION(() => SUBRULE(varOrReifierId));
107
101
  return ACTION(() => {
108
102
  if (reifier === undefined && !C.parseMode.has('canCreateBlankNodes')) {
109
103
  throw new Error('Cannot create blanknodes in current parse mode');
110
104
  }
111
- return reifier ?? C.factory.blankNode(undefined, C.factory.sourceLocation());
105
+ return C.factory.wrap(reifier ?? C.factory.blankNode(undefined, C.factory.sourceLocation()), C.factory.sourceLocation(tildeToken, reifier));
112
106
  });
113
107
  },
114
108
  };
@@ -118,9 +112,9 @@ export const reifier = {
118
112
  export const varOrReifierId = {
119
113
  name: 'varOrReifierId',
120
114
  impl: ({ SUBRULE, OR }) => C => OR([
121
- { GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(S11.var_, undefined) },
122
- { ALT: () => SUBRULE(S11.iri, undefined) },
123
- { ALT: () => SUBRULE(S11.blankNode, undefined) },
115
+ { GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(S11.var_) },
116
+ { ALT: () => SUBRULE(S11.iri) },
117
+ { ALT: () => SUBRULE(S11.blankNode) },
124
118
  ]),
125
119
  };
126
120
  function triplesSameSubjectImpl(name, allowPaths) {
@@ -128,9 +122,9 @@ function triplesSameSubjectImpl(name, allowPaths) {
128
122
  name,
129
123
  impl: $ => C => $.OR2([
130
124
  { ALT: () => allowPaths ?
131
- S11.triplesSameSubjectPath.impl($)(C, undefined) :
132
- S11.triplesSameSubject.impl($)(C, undefined) },
133
- { ALT: () => $.SUBRULE(allowPaths ? reifiedTripleBlockPath : reifiedTripleBlock, undefined) },
125
+ S11.triplesSameSubjectPath.impl($)(C) :
126
+ S11.triplesSameSubject.impl($)(C) },
127
+ { ALT: () => $.SUBRULE(allowPaths ? reifiedTripleBlockPath : reifiedTripleBlock) },
134
128
  ]),
135
129
  };
136
130
  }
@@ -147,11 +141,10 @@ export const triplesSameSubjectPath = triplesSameSubjectImpl('triplesSameSubject
147
141
  function objectImpl(name, allowPaths) {
148
142
  return {
149
143
  name,
150
- impl: ({ ACTION, SUBRULE }) => (C, arg) => {
151
- const objectVal = SUBRULE(allowPaths ? graphNodePath : graphNode, undefined);
152
- const annotationVal = SUBRULE(allowPaths ? annotationPath : annotation, undefined);
144
+ impl: ({ ACTION, SUBRULE }) => (C, subject, predicate) => {
145
+ const objectVal = SUBRULE(allowPaths ? graphNodePath : graphNode);
146
+ const annotationVal = SUBRULE(allowPaths ? annotationPath : annotation);
153
147
  return ACTION(() => {
154
- const { subject, predicate } = arg;
155
148
  const F = C.factory;
156
149
  if (F.isPathPure(predicate) && annotationVal.length > 0) {
157
150
  throw new Error('Note 17 violation');
@@ -163,12 +156,12 @@ function objectImpl(name, allowPaths) {
163
156
  }
164
157
  /**
165
158
  * OVERRIDING RULE: {@link S11.object}.
166
- * [[84]](https://www.w3.org/TR/sparql12-query/#rObject) Used by ObjectList
159
+ * [[86]](https://www.w3.org/TR/sparql12-query/#rObject) Used by ObjectList
167
160
  */
168
161
  export const object = objectImpl('object', false);
169
162
  /**
170
163
  * OVERRIDING RULE: {@link S11.objectPath}.
171
- * [[91]](https://www.w3.org/TR/sparql12-query/#rTriplesSameSubjectPath) Used by ObjectListPath
164
+ * [[87]](https://www.w3.org/TR/sparql12-query/#rTriplesSameSubjectPath) Used by ObjectListPath
172
165
  */
173
166
  export const objectPath = objectImpl('objectPath', true);
174
167
  function annotationImpl(name, allowPaths) {
@@ -180,9 +173,9 @@ function annotationImpl(name, allowPaths) {
180
173
  MANY(() => {
181
174
  OR([
182
175
  { ALT: () => {
183
- const node = SUBRULE(reifier, undefined);
176
+ const node = SUBRULE(reifier);
184
177
  annotations.push(node);
185
- currentReifier = node;
178
+ currentReifier = node.val;
186
179
  } },
187
180
  { ALT: () => {
188
181
  ACTION(() => {
@@ -203,19 +196,19 @@ function annotationImpl(name, allowPaths) {
203
196
  },
204
197
  gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { factory: F }) => {
205
198
  for (const annotation of ast) {
206
- if (F.isTerm(annotation)) {
207
- F.printFilter(annotation, () => PRINT_WORD('~'));
208
- SUBRULE(graphNodePath, annotation, undefined);
199
+ if (F.isTripleCollectionBlankNodeProperties(annotation)) {
200
+ SUBRULE(annotationBlockPath, annotation);
209
201
  }
210
202
  else {
211
- SUBRULE(annotationBlockPath, annotation, undefined);
203
+ F.printFilter(annotation, () => PRINT_WORD('~'));
204
+ SUBRULE(graphNodePath, annotation.val);
212
205
  }
213
206
  }
214
207
  },
215
208
  };
216
209
  }
217
210
  /**
218
- * [[107]](https://www.w3.org/TR/sparql12-query/#rAnnotationPath)
211
+ * [[109]](https://www.w3.org/TR/sparql12-query/#rAnnotationPath)
219
212
  */
220
213
  export const annotationPath = annotationImpl('annotationPath', true);
221
214
  /**
@@ -227,7 +220,7 @@ function annotationBlockImpl(name, allowPaths) {
227
220
  name,
228
221
  impl: ({ ACTION, SUBRULE, CONSUME }) => (C, arg) => {
229
222
  const open = CONSUME(l12.annotationOpen);
230
- const res = SUBRULE(allowPaths ? S11.propertyListPathNotEmpty : S11.propertyListNotEmpty, { subject: arg });
223
+ const res = SUBRULE(allowPaths ? S11.propertyListPathNotEmpty : S11.propertyListNotEmpty, arg);
231
224
  const close = CONSUME(l12.annotationClose);
232
225
  return ACTION(() => C.factory.tripleCollectionBlankNodeProperties(arg, res, C.factory.sourceLocation(open, close)));
233
226
  },
@@ -236,12 +229,12 @@ function annotationBlockImpl(name, allowPaths) {
236
229
  for (const triple of ast.triples) {
237
230
  HANDLE_LOC(triple, () => {
238
231
  if (F.isTerm(triple.predicate)) {
239
- SUBRULE(graphNodePath, triple.predicate, undefined);
232
+ SUBRULE(graphNodePath, triple.predicate);
240
233
  }
241
234
  else {
242
235
  SUBRULE(S11.pathGenerator, triple.predicate, undefined);
243
236
  }
244
- SUBRULE(graphNodePath, triple.object, undefined);
237
+ SUBRULE(graphNodePath, triple.object);
245
238
  F.printFilter(ast, () => PRINT_WORD(';'));
246
239
  });
247
240
  }
@@ -259,13 +252,13 @@ export const annotationBlockPath = annotationBlockImpl('annotationBlockPath', tr
259
252
  export const annotationBlock = annotationBlockImpl('annotationBlock', false);
260
253
  /**
261
254
  * OVERRIDING RULE: {@link S11.graphNode}.
262
- * [[111]](https://www.w3.org/TR/sparql12-query/#rGraphNode)
255
+ * [[113]](https://www.w3.org/TR/sparql12-query/#rGraphNode)
263
256
  */
264
257
  export const graphNode = {
265
258
  name: 'graphNode',
266
259
  impl: $ => C => $.OR2([
267
- { ALT: () => S11.graphNode.impl($)(C, undefined) },
268
- { ALT: () => $.SUBRULE(reifiedTriple, undefined) },
260
+ { ALT: () => S11.graphNode.impl($)(C) },
261
+ { ALT: () => $.SUBRULE(reifiedTriple) },
269
262
  ]),
270
263
  };
271
264
  /**
@@ -275,15 +268,15 @@ export const graphNode = {
275
268
  export const graphNodePath = {
276
269
  name: 'graphNodePath',
277
270
  impl: $ => C => $.OR2([
278
- { ALT: () => S11.graphNodePath.impl($)(C, undefined) },
279
- { ALT: () => $.SUBRULE(reifiedTriple, undefined) },
271
+ { ALT: () => S11.graphNodePath.impl($)(C) },
272
+ { ALT: () => $.SUBRULE(reifiedTriple) },
280
273
  ]),
281
- gImpl: $ => (ast, C, params) => {
274
+ gImpl: $ => (ast, C) => {
282
275
  if (C.factory.isTripleCollectionReifiedTriple(ast)) {
283
- $.SUBRULE(reifiedTriple, ast, undefined);
276
+ $.SUBRULE(reifiedTriple, ast);
284
277
  }
285
278
  else {
286
- S11.graphNodePath.gImpl($)(ast, C, params);
279
+ S11.graphNodePath.gImpl($)(ast, C);
287
280
  }
288
281
  },
289
282
  };
@@ -294,96 +287,96 @@ export const graphNodePath = {
294
287
  export const varOrTerm = {
295
288
  name: 'varOrTerm',
296
289
  impl: ({ ACTION, SUBRULE, OR, CONSUME }) => C => OR([
297
- { GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(S11.var_, undefined) },
298
- { ALT: () => SUBRULE(S11.iri, undefined) },
299
- { ALT: () => SUBRULE(rdfLiteral, undefined) },
300
- { ALT: () => SUBRULE(S11.numericLiteral, undefined) },
301
- { ALT: () => SUBRULE(S11.booleanLiteral, undefined) },
302
- { ALT: () => SUBRULE(S11.blankNode, undefined) },
290
+ { GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(S11.var_) },
291
+ { ALT: () => SUBRULE(S11.iri) },
292
+ { ALT: () => SUBRULE(rdfLiteral) },
293
+ { ALT: () => SUBRULE(S11.numericLiteral) },
294
+ { ALT: () => SUBRULE(S11.booleanLiteral) },
295
+ { ALT: () => SUBRULE(S11.blankNode) },
303
296
  { ALT: () => {
304
297
  const token = CONSUME(l11.terminals.nil);
305
298
  return ACTION(() => C.factory.namedNode(C.factory.sourceLocation(token), CommonIRIs.NIL));
306
299
  } },
307
- { ALT: () => SUBRULE(tripleTerm, undefined) },
300
+ { ALT: () => SUBRULE(tripleTerm) },
308
301
  ]),
309
302
  // Generation remains untouched - go through graphTerm
310
303
  };
311
304
  /**
312
- * [[114]](https://www.w3.org/TR/sparql12-query/#rReifiedTriple)
305
+ * [[116]](https://www.w3.org/TR/sparql12-query/#rReifiedTriple)
313
306
  */
314
307
  export const reifiedTriple = {
315
308
  name: 'reifiedTriple',
316
309
  impl: ({ ACTION, CONSUME, SUBRULE, OPTION }) => (C) => {
317
310
  const open = CONSUME(l12.reificationOpen);
318
- const subject = SUBRULE(reifiedTripleSubject, undefined);
319
- const predicate = SUBRULE(S11.verb, undefined);
320
- const object = SUBRULE(reifiedTripleObject, undefined);
321
- const reifierVal = OPTION(() => SUBRULE(reifier, undefined));
311
+ const subject = SUBRULE(reifiedTripleSubject);
312
+ const predicate = SUBRULE(S11.verb);
313
+ const object = SUBRULE(reifiedTripleObject);
314
+ const reifierVal = OPTION(() => SUBRULE(reifier));
322
315
  const close = CONSUME(l12.reificationClose);
323
316
  return ACTION(() => {
324
317
  // A reifier would be auto generated in this case, but we are not allowed to use them.
325
318
  if (reifierVal === undefined && !C.parseMode.has('canCreateBlankNodes')) {
326
319
  throw new Error('Cannot create blanknodes in current parse mode');
327
320
  }
328
- return C.factory.tripleCollectionReifiedTriple(C.factory.sourceLocation(open, close), subject, predicate, object, reifierVal);
321
+ return C.factory.tripleCollectionReifiedTriple(C.factory.sourceLocation(open, close), subject, predicate, object, reifierVal?.val);
329
322
  });
330
323
  },
331
324
  gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { factory: F }) => {
332
325
  F.printFilter(ast, () => PRINT_WORD('<<'));
333
326
  const triple = ast.triples[0];
334
- SUBRULE(graphNodePath, triple.subject, undefined);
327
+ SUBRULE(graphNodePath, triple.subject);
335
328
  if (F.isPathPure(triple.predicate)) {
336
329
  SUBRULE(S11.pathGenerator, triple.predicate, undefined);
337
330
  }
338
331
  else {
339
- SUBRULE(graphNodePath, triple.predicate, undefined);
332
+ SUBRULE(graphNodePath, triple.predicate);
340
333
  }
341
- SUBRULE(graphNodePath, triple.object, undefined);
342
- SUBRULE(annotationPath, [ast.identifier], undefined);
334
+ SUBRULE(graphNodePath, triple.object);
335
+ SUBRULE(annotationPath, [F.wrap(ast.identifier, ast.identifier.loc)]);
343
336
  F.printFilter(ast, () => PRINT_WORD('>>'));
344
337
  },
345
338
  };
346
339
  /**
347
- * [[115]](https://www.w3.org/TR/sparql12-query/#rReifiedTripleSubject)
340
+ * [[117]](https://www.w3.org/TR/sparql12-query/#rReifiedTripleSubject)
348
341
  */
349
342
  export const reifiedTripleSubject = {
350
343
  name: 'reifiedTripleSubject',
351
344
  impl: ({ OR, SUBRULE }) => C => OR([
352
- { GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(S11.var_, undefined) },
353
- { ALT: () => SUBRULE(S11.iri, undefined) },
354
- { ALT: () => SUBRULE(rdfLiteral, undefined) },
355
- { ALT: () => SUBRULE(S11.numericLiteral, undefined) },
356
- { ALT: () => SUBRULE(S11.booleanLiteral, undefined) },
357
- { ALT: () => SUBRULE(S11.blankNode, undefined) },
358
- { ALT: () => SUBRULE(reifiedTriple, undefined) },
359
- { ALT: () => SUBRULE(tripleTerm, undefined) },
345
+ { GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(S11.var_) },
346
+ { ALT: () => SUBRULE(S11.iri) },
347
+ { ALT: () => SUBRULE(rdfLiteral) },
348
+ { ALT: () => SUBRULE(S11.numericLiteral) },
349
+ { ALT: () => SUBRULE(S11.booleanLiteral) },
350
+ { ALT: () => SUBRULE(S11.blankNode) },
351
+ { ALT: () => SUBRULE(reifiedTriple) },
352
+ { ALT: () => SUBRULE(tripleTerm) },
360
353
  ]),
361
354
  };
362
355
  /**
363
- * [[116]](https://www.w3.org/TR/sparql12-query/#rReifiedTripleObject)
356
+ * [[118]](https://www.w3.org/TR/sparql12-query/#rReifiedTripleObject)
364
357
  */
365
358
  export const reifiedTripleObject = {
366
359
  name: 'reifiedTripleObject',
367
360
  impl: reifiedTripleSubject.impl,
368
361
  };
369
362
  /**
370
- * [[117]](https://www.w3.org/TR/sparql12-query/#rTripleTerm)
363
+ * [[119]](https://www.w3.org/TR/sparql12-query/#rTripleTerm)
371
364
  */
372
365
  export const tripleTerm = {
373
366
  name: 'tripleTerm',
374
367
  impl: ({ ACTION, CONSUME, SUBRULE }) => (C) => {
375
368
  const open = CONSUME(l12.tripleTermOpen);
376
- const subject = SUBRULE(tripleTermSubject, undefined);
377
- const predicate = SUBRULE(S11.verb, undefined);
378
- const object = SUBRULE(tripleTermObject, undefined);
369
+ const subject = SUBRULE(tripleTermSubject);
370
+ const predicate = SUBRULE(S11.verb);
371
+ const object = SUBRULE(tripleTermObject);
379
372
  const close = CONSUME(l12.tripleTermClose);
380
373
  return ACTION(() => C.factory.termTriple(subject, predicate, object, C.factory.sourceLocation(open, close)));
381
374
  },
382
375
  gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { factory: F }) => {
383
376
  F.printFilter(ast, () => PRINT_WORD('<<('));
384
- SUBRULE(graphNodePath, ast.subject, undefined);
385
- SUBRULE(graphNodePath, ast.predicate, undefined);
386
- SUBRULE(graphNodePath, ast.object, undefined);
377
+ SUBRULE(graphNodePath, ast.subject);
378
+ SUBRULE(graphNodePath, ast.predicate);
379
+ SUBRULE(graphNodePath, ast.object);
387
380
  F.printFilter(ast, () => PRINT_WORD(')>>'));
388
381
  },
389
382
  };
@@ -393,13 +386,13 @@ export const tripleTerm = {
393
386
  export const tripleTermSubject = {
394
387
  name: 'tripleTermSubject',
395
388
  impl: ({ SUBRULE, OR }) => C => OR([
396
- { GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(S11.var_, undefined) },
397
- { ALT: () => SUBRULE(S11.iri, undefined) },
398
- { ALT: () => SUBRULE(rdfLiteral, undefined) },
399
- { ALT: () => SUBRULE(S11.numericLiteral, undefined) },
400
- { ALT: () => SUBRULE(S11.booleanLiteral, undefined) },
401
- { ALT: () => SUBRULE(S11.blankNode, undefined) },
402
- { ALT: () => SUBRULE(tripleTerm, undefined) },
389
+ { GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(S11.var_) },
390
+ { ALT: () => SUBRULE(S11.iri) },
391
+ { ALT: () => SUBRULE(rdfLiteral) },
392
+ { ALT: () => SUBRULE(S11.numericLiteral) },
393
+ { ALT: () => SUBRULE(S11.booleanLiteral) },
394
+ { ALT: () => SUBRULE(S11.blankNode) },
395
+ { ALT: () => SUBRULE(tripleTerm) },
403
396
  ]),
404
397
  };
405
398
  /**
@@ -416,15 +409,15 @@ export const tripleTermData = {
416
409
  name: 'tripleTermData',
417
410
  impl: ({ ACTION, CONSUME, OR, SUBRULE }) => (C) => {
418
411
  const open = CONSUME(l12.tripleTermOpen);
419
- const subject = SUBRULE(tripleTermDataSubject, undefined);
412
+ const subject = SUBRULE(tripleTermDataSubject);
420
413
  const predicate = OR([
421
- { ALT: () => SUBRULE(S11.iri, undefined) },
414
+ { ALT: () => SUBRULE(S11.iri) },
422
415
  { ALT: () => {
423
416
  const token = CONSUME(l11.a);
424
417
  return ACTION(() => C.factory.namedNode(C.factory.sourceLocation(token), CommonIRIs.TYPE));
425
418
  } },
426
419
  ]);
427
- const object = SUBRULE(tripleTermDataObject, undefined);
420
+ const object = SUBRULE(tripleTermDataObject);
428
421
  const close = CONSUME(l12.tripleTermClose);
429
422
  return ACTION(() => C.factory.termTriple(subject, predicate, object, C.factory.sourceLocation(open, close)));
430
423
  },
@@ -435,11 +428,11 @@ export const tripleTermData = {
435
428
  export const tripleTermDataSubject = {
436
429
  name: 'tripleTermDataSubject',
437
430
  impl: ({ OR, SUBRULE }) => () => OR([
438
- { ALT: () => SUBRULE(S11.iri, undefined) },
439
- { ALT: () => SUBRULE(rdfLiteral, undefined) },
440
- { ALT: () => SUBRULE(S11.numericLiteral, undefined) },
441
- { ALT: () => SUBRULE(S11.booleanLiteral, undefined) },
442
- { ALT: () => SUBRULE(tripleTermData, undefined) },
431
+ { ALT: () => SUBRULE(S11.iri) },
432
+ { ALT: () => SUBRULE(rdfLiteral) },
433
+ { ALT: () => SUBRULE(S11.numericLiteral) },
434
+ { ALT: () => SUBRULE(S11.booleanLiteral) },
435
+ { ALT: () => SUBRULE(tripleTermData) },
443
436
  ]),
444
437
  };
445
438
  /**
@@ -456,20 +449,20 @@ export const tripleTermDataObject = {
456
449
  export const primaryExpression = {
457
450
  name: 'primaryExpression',
458
451
  impl: $ => C => $.OR2([
459
- { ALT: () => S11.primaryExpression.impl($)(C, undefined) },
460
- { ALT: () => $.SUBRULE(exprTripleTerm, undefined) },
452
+ { ALT: () => S11.primaryExpression.impl($)(C) },
453
+ { ALT: () => $.SUBRULE(exprTripleTerm) },
461
454
  ]),
462
455
  };
463
456
  /**
464
- * [[135]](https://www.w3.org/TR/sparql12-query/#rExprTripleTerm)
457
+ * [[137]](https://www.w3.org/TR/sparql12-query/#rExprTripleTerm)
465
458
  */
466
459
  export const exprTripleTerm = {
467
460
  name: 'exprTripleTerm',
468
461
  impl: ({ ACTION, CONSUME, SUBRULE }) => (C) => {
469
462
  const open = CONSUME(l12.tripleTermOpen);
470
- const subject = SUBRULE(exprTripleTermSubject, undefined);
471
- const predicate = SUBRULE(S11.verb, undefined);
472
- const object = SUBRULE(exprTripleTermObject, undefined);
463
+ const subject = SUBRULE(exprTripleTermSubject);
464
+ const predicate = SUBRULE(S11.verb);
465
+ const object = SUBRULE(exprTripleTermObject);
473
466
  const close = CONSUME(l12.tripleTermClose);
474
467
  return ACTION(() => C.factory.termTriple(subject, predicate, object, C.factory.sourceLocation(open, close)));
475
468
  },
@@ -480,12 +473,12 @@ export const exprTripleTerm = {
480
473
  export const exprTripleTermSubject = {
481
474
  name: 'exprTripleTermSubject',
482
475
  impl: ({ OR, SUBRULE }) => C => OR([
483
- { ALT: () => SUBRULE(S11.iri, undefined) },
484
- { ALT: () => SUBRULE(rdfLiteral, undefined) },
485
- { ALT: () => SUBRULE(S11.numericLiteral, undefined) },
486
- { ALT: () => SUBRULE(S11.booleanLiteral, undefined) },
487
- { GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(S11.var_, undefined) },
488
- { ALT: () => SUBRULE(exprTripleTerm, undefined) },
476
+ { ALT: () => SUBRULE(S11.iri) },
477
+ { ALT: () => SUBRULE(rdfLiteral) },
478
+ { ALT: () => SUBRULE(S11.numericLiteral) },
479
+ { ALT: () => SUBRULE(S11.booleanLiteral) },
480
+ { GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(S11.var_) },
481
+ { ALT: () => SUBRULE(exprTripleTerm) },
489
482
  ]),
490
483
  };
491
484
  /**
@@ -495,15 +488,15 @@ export const exprTripleTermObject = {
495
488
  name: 'exprTripleTermObject',
496
489
  impl: exprTripleTermSubject.impl,
497
490
  };
498
- export const builtinLangDir = funcExpr1(l12.builtinLangDir);
499
- export const builtinLangStrDir = funcExpr3(l12.builtinStrLangDir);
500
- export const builtinHasLang = funcExpr1(l12.builtinHasLang);
501
- export const builtinHasLangDir = funcExpr1(l12.builtinHasLangDir);
502
- export const builtinIsTriple = funcExpr1(l12.builtinIsTRIPLE);
503
- export const builtinTriple = funcExpr3(l12.builtinTRIPLE);
504
- export const builtinSubject = funcExpr1(l12.builtinSUBJECT);
505
- export const builtinPredicate = funcExpr1(l12.builtinPREDICATE);
506
- export const builtinObject = funcExpr1(l12.builtinOBJECT);
491
+ export const buildInLangDir = funcExpr1(l12.buildInLangDir);
492
+ export const buildInLangStrDir = funcExpr3(l12.buildInStrLangDir);
493
+ export const buildInHasLang = funcExpr1(l12.buildInHasLang);
494
+ export const buildInHasLangDir = funcExpr1(l12.buildInHasLangDir);
495
+ export const buildInIsTriple = funcExpr1(l12.buildInIsTRIPLE);
496
+ export const buildInTriple = funcExpr3(l12.buildInTRIPLE);
497
+ export const buildInSubject = funcExpr1(l12.buildInSUBJECT);
498
+ export const buildInPredicate = funcExpr1(l12.buildInPREDICATE);
499
+ export const buildInObject = funcExpr1(l12.buildInOBJECT);
507
500
  /**
508
501
  * OVERRIDING RULE: {@link S11.builtInCall}.
509
502
  * [[141]](https://www.w3.org/TR/sparql12-query/#rBuiltInCall)
@@ -511,16 +504,16 @@ export const builtinObject = funcExpr1(l12.builtinOBJECT);
511
504
  export const builtInCall = {
512
505
  name: 'builtInCall',
513
506
  impl: $ => C => $.OR2([
514
- { ALT: () => S11.builtInCall.impl($)(C, undefined) },
515
- { ALT: () => $.SUBRULE(builtinLangDir, undefined) },
516
- { ALT: () => $.SUBRULE(builtinLangStrDir, undefined) },
517
- { ALT: () => $.SUBRULE(builtinHasLang, undefined) },
518
- { ALT: () => $.SUBRULE(builtinHasLangDir, undefined) },
519
- { ALT: () => $.SUBRULE(builtinIsTriple, undefined) },
520
- { ALT: () => $.SUBRULE(builtinTriple, undefined) },
521
- { ALT: () => $.SUBRULE(builtinSubject, undefined) },
522
- { ALT: () => $.SUBRULE(builtinPredicate, undefined) },
523
- { ALT: () => $.SUBRULE(builtinObject, undefined) },
507
+ { ALT: () => S11.builtInCall.impl($)(C) },
508
+ { ALT: () => $.SUBRULE(buildInLangDir) },
509
+ { ALT: () => $.SUBRULE(buildInLangStrDir) },
510
+ { ALT: () => $.SUBRULE(buildInHasLang) },
511
+ { ALT: () => $.SUBRULE(buildInHasLangDir) },
512
+ { ALT: () => $.SUBRULE(buildInIsTriple) },
513
+ { ALT: () => $.SUBRULE(buildInTriple) },
514
+ { ALT: () => $.SUBRULE(buildInSubject) },
515
+ { ALT: () => $.SUBRULE(buildInPredicate) },
516
+ { ALT: () => $.SUBRULE(buildInObject) },
524
517
  ]),
525
518
  };
526
519
  /**
@@ -531,19 +524,19 @@ export const builtInCall = {
531
524
  export const rdfLiteral = {
532
525
  name: 'rdfLiteral',
533
526
  impl: ({ ACTION, SUBRULE, OPTION, CONSUME, OR }) => (C) => {
534
- const value = SUBRULE(S11.string, undefined);
527
+ const value = SUBRULE(S11.string);
535
528
  return OPTION(() => OR([
536
529
  { ALT: () => {
537
530
  const langTag = CONSUME(l12.LANG_DIR);
538
531
  return ACTION(() => {
539
532
  const literal = C.factory.literalTerm(C.factory.sourceLocation(value, langTag), value.value, langTag.image.slice(1).toLowerCase());
540
- langTagHasCorrectDomain(literal);
533
+ langTagHasCorrectRange(literal);
541
534
  return literal;
542
535
  });
543
536
  } },
544
537
  { ALT: () => {
545
538
  CONSUME(l11.symbols.hathat);
546
- const iriVal = SUBRULE(S11.iri, undefined);
539
+ const iriVal = SUBRULE(S11.iri);
547
540
  return ACTION(() => C.factory.literalTerm(C.factory.sourceLocation(value, iriVal), value.value, iriVal));
548
541
  } },
549
542
  ])) ?? value;
@@ -559,23 +552,23 @@ export const generateTriplesBlock = {
559
552
  HANDLE_LOC(triple, () => {
560
553
  const nextTriple = ast.triples.at(index);
561
554
  if (F.isTripleCollection(triple)) {
562
- SUBRULE(graphNodePath, triple, undefined);
555
+ SUBRULE(graphNodePath, triple);
563
556
  // A top level tripleCollection block means that it is not used in a triple. So you end with DOT.
564
557
  F.printFilter(triple, () => PRINT_WORD('.'));
565
558
  }
566
559
  else {
567
560
  // Subject
568
- SUBRULE(graphNodePath, triple.subject, undefined);
561
+ SUBRULE(graphNodePath, triple.subject);
569
562
  // Predicate
570
563
  if (F.isPathPure(triple.predicate)) {
571
564
  SUBRULE(S11.pathGenerator, triple.predicate, undefined);
572
565
  }
573
566
  else {
574
- SUBRULE(graphNodePath, triple.predicate, undefined);
567
+ SUBRULE(graphNodePath, triple.predicate);
575
568
  }
576
569
  // Object
577
- SUBRULE(graphNodePath, triple.object, undefined);
578
- SUBRULE(annotationPath, triple.annotations ?? [], undefined);
570
+ SUBRULE(graphNodePath, triple.object);
571
+ SUBRULE(annotationPath, triple.annotations ?? []);
579
572
  // If no more things, or a top level collection (only possible if new block was part), or new subject: add DOT
580
573
  if (nextTriple === undefined || F.isTripleCollection(nextTriple) ||
581
574
  !F.isSourceLocationNoMaterialize(nextTriple.subject.loc)) {
@@ -599,12 +592,12 @@ export const generateTriplesBlock = {
599
592
  */
600
593
  export const generateGraphTerm = {
601
594
  name: 'graphTerm',
602
- gImpl: $ => (ast, C, par) => {
595
+ gImpl: $ => (ast, C) => {
603
596
  if (C.factory.isTermTriple(ast)) {
604
- $.SUBRULE(tripleTerm, ast, undefined);
597
+ $.SUBRULE(tripleTerm, ast);
605
598
  }
606
599
  else {
607
- S11.graphTerm.gImpl($)(ast, C, par);
600
+ S11.graphTerm.gImpl($)(ast, C);
608
601
  }
609
602
  },
610
603
  };