@traqula/rules-sparql-1-1 0.0.23 → 0.0.24

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.
Files changed (75) hide show
  1. package/dist/cjs/lib/MinimalSparqlParser.js +35 -58
  2. package/dist/cjs/lib/MinimalSparqlParser.js.map +1 -0
  3. package/dist/cjs/lib/Sparql11types.js +2 -15
  4. package/dist/cjs/lib/Sparql11types.js.map +1 -0
  5. package/dist/cjs/lib/astFactory.js +107 -119
  6. package/dist/cjs/lib/astFactory.js.map +1 -0
  7. package/dist/cjs/lib/expressionHelpers.js +181 -191
  8. package/dist/cjs/lib/expressionHelpers.js.map +1 -0
  9. package/dist/cjs/lib/factoryMixins/ContextFactory.js +30 -52
  10. package/dist/cjs/lib/factoryMixins/ContextFactory.js.map +1 -0
  11. package/dist/cjs/lib/factoryMixins/ExpressionFactory.js +83 -102
  12. package/dist/cjs/lib/factoryMixins/ExpressionFactory.js.map +1 -0
  13. package/dist/cjs/lib/factoryMixins/GraphRefFactory.js +51 -73
  14. package/dist/cjs/lib/factoryMixins/GraphRefFactory.js.map +1 -0
  15. package/dist/cjs/lib/factoryMixins/PathFactory.js +68 -87
  16. package/dist/cjs/lib/factoryMixins/PathFactory.js.map +1 -0
  17. package/dist/cjs/lib/factoryMixins/Patternfactory.js +98 -120
  18. package/dist/cjs/lib/factoryMixins/Patternfactory.js.map +1 -0
  19. package/dist/cjs/lib/factoryMixins/QueryFactory.js +43 -65
  20. package/dist/cjs/lib/factoryMixins/QueryFactory.js.map +1 -0
  21. package/dist/cjs/lib/factoryMixins/SolutionModifiersFactory.js +55 -77
  22. package/dist/cjs/lib/factoryMixins/SolutionModifiersFactory.js.map +1 -0
  23. package/dist/cjs/lib/factoryMixins/TermFactory.js +81 -102
  24. package/dist/cjs/lib/factoryMixins/TermFactory.js.map +1 -0
  25. package/dist/cjs/lib/factoryMixins/UpdateOperationFactory.js +126 -147
  26. package/dist/cjs/lib/factoryMixins/UpdateOperationFactory.js.map +1 -0
  27. package/dist/cjs/lib/factoryMixins/mixins.js +21 -38
  28. package/dist/cjs/lib/factoryMixins/mixins.js.map +1 -0
  29. package/dist/cjs/lib/grammar/builtIn.js +277 -377
  30. package/dist/cjs/lib/grammar/builtIn.js.map +1 -0
  31. package/dist/cjs/lib/grammar/dataSetClause.js +110 -109
  32. package/dist/cjs/lib/grammar/dataSetClause.js.map +1 -0
  33. package/dist/cjs/lib/grammar/expression.js +387 -358
  34. package/dist/cjs/lib/grammar/expression.js.map +1 -0
  35. package/dist/cjs/lib/grammar/general.js +173 -158
  36. package/dist/cjs/lib/grammar/general.js.map +1 -0
  37. package/dist/cjs/lib/grammar/index.js +94 -111
  38. package/dist/cjs/lib/grammar/index.js.map +1 -0
  39. package/dist/cjs/lib/grammar/literals.js +282 -266
  40. package/dist/cjs/lib/grammar/literals.js.map +1 -0
  41. package/dist/cjs/lib/grammar/propertyPaths.js +206 -193
  42. package/dist/cjs/lib/grammar/propertyPaths.js.map +1 -0
  43. package/dist/cjs/lib/grammar/queryUnit.js +395 -372
  44. package/dist/cjs/lib/grammar/queryUnit.js.map +1 -0
  45. package/dist/cjs/lib/grammar/solutionModifier.js +281 -265
  46. package/dist/cjs/lib/grammar/solutionModifier.js.map +1 -0
  47. package/dist/cjs/lib/grammar/tripleBlock.js +390 -355
  48. package/dist/cjs/lib/grammar/tripleBlock.js.map +1 -0
  49. package/dist/cjs/lib/grammar/updateUnit.js +551 -519
  50. package/dist/cjs/lib/grammar/updateUnit.js.map +1 -0
  51. package/dist/cjs/lib/grammar/whereClause.js +486 -459
  52. package/dist/cjs/lib/grammar/whereClause.js.map +1 -0
  53. package/dist/cjs/lib/index.js +47 -54
  54. package/dist/cjs/lib/index.js.map +1 -0
  55. package/dist/cjs/lib/lexer/BuiltInCalls.js +188 -333
  56. package/dist/cjs/lib/lexer/BuiltInCalls.js.map +1 -0
  57. package/dist/cjs/lib/lexer/graph.js +10 -40
  58. package/dist/cjs/lib/lexer/graph.js.map +1 -0
  59. package/dist/cjs/lib/lexer/index.js +43 -48
  60. package/dist/cjs/lib/lexer/index.js.map +1 -0
  61. package/dist/cjs/lib/lexer/lexer.js +84 -195
  62. package/dist/cjs/lib/lexer/lexer.js.map +1 -0
  63. package/dist/cjs/lib/lexer/lexerPatterns.js +40 -132
  64. package/dist/cjs/lib/lexer/lexerPatterns.js.map +1 -0
  65. package/dist/cjs/lib/lexer/symbols.js +31 -106
  66. package/dist/cjs/lib/lexer/symbols.js.map +1 -0
  67. package/dist/cjs/lib/lexer/terminals.js +100 -102
  68. package/dist/cjs/lib/lexer/terminals.js.map +1 -0
  69. package/dist/cjs/lib/sparql11HelperTypes.js +2 -15
  70. package/dist/cjs/lib/sparql11HelperTypes.js.map +1 -0
  71. package/dist/cjs/lib/utils.js +40 -58
  72. package/dist/cjs/lib/utils.js.map +1 -0
  73. package/dist/cjs/lib/validation/validators.js +197 -186
  74. package/dist/cjs/lib/validation/validators.js.map +1 -0
  75. package/package.json +10 -10
@@ -1,384 +1,419 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var tripleBlock_exports = {};
30
- __export(tripleBlock_exports, {
31
- blankNodePropertyList: () => blankNodePropertyList,
32
- blankNodePropertyListPath: () => blankNodePropertyListPath,
33
- collection: () => collection,
34
- collectionPath: () => collectionPath,
35
- graphNode: () => graphNode,
36
- graphNodePath: () => graphNodePath,
37
- object: () => object,
38
- objectList: () => objectList,
39
- objectListPath: () => objectListPath,
40
- objectPath: () => objectPath,
41
- propertyList: () => propertyList,
42
- propertyListNotEmpty: () => propertyListNotEmpty,
43
- propertyListPath: () => propertyListPath,
44
- propertyListPathNotEmpty: () => propertyListPathNotEmpty,
45
- triplesBlock: () => triplesBlock,
46
- triplesNode: () => triplesNode,
47
- triplesNodePath: () => triplesNodePath,
48
- triplesSameSubject: () => triplesSameSubject,
49
- triplesSameSubjectPath: () => triplesSameSubjectPath,
50
- triplesTemplate: () => triplesTemplate,
51
- verbPath: () => verbPath,
52
- verbSimple: () => verbSimple
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
53
17
  });
54
- module.exports = __toCommonJS(tripleBlock_exports);
55
- var import_core = require("@traqula/core");
56
- var l = __toESM(require("../lexer/index.js"), 1);
57
- var import_utils = require("../utils.js");
58
- var import_general = require("./general.js");
59
- var import_propertyPaths = require("./propertyPaths.js");
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.graphNodePath = exports.graphNode = exports.blankNodePropertyListPath = exports.blankNodePropertyList = exports.triplesNodePath = exports.triplesNode = exports.collectionPath = exports.collection = exports.objectPath = exports.object = exports.objectListPath = exports.objectList = exports.verbSimple = exports.verbPath = exports.propertyListPathNotEmpty = exports.propertyListNotEmpty = exports.propertyListPath = exports.propertyList = exports.triplesTemplate = exports.triplesSameSubjectPath = exports.triplesSameSubject = exports.triplesBlock = void 0;
37
+ const core_1 = require("@traqula/core");
38
+ const l = __importStar(require("../lexer/index.js"));
39
+ const utils_js_1 = require("../utils.js");
40
+ const general_js_1 = require("./general.js");
41
+ const propertyPaths_js_1 = require("./propertyPaths.js");
60
42
  function triplesDotSeperated(triplesSameSubjectSubrule) {
61
- return ({ ACTION, AT_LEAST_ONE, SUBRULE, CONSUME, OPTION }) => (C) => {
62
- const triples = [];
63
- let parsedDot = true;
64
- let dotToken;
65
- AT_LEAST_ONE({
66
- GATE: () => parsedDot,
67
- DEF: () => {
68
- parsedDot = false;
69
- const template = SUBRULE(triplesSameSubjectSubrule);
70
- ACTION(() => {
71
- triples.push(...template);
72
- });
73
- OPTION(() => {
74
- dotToken = CONSUME(l.symbols.dot);
75
- parsedDot = true;
43
+ return ({ ACTION, AT_LEAST_ONE, SUBRULE, CONSUME, OPTION }) => (C) => {
44
+ const triples = [];
45
+ let parsedDot = true;
46
+ let dotToken;
47
+ AT_LEAST_ONE({
48
+ GATE: () => parsedDot,
49
+ DEF: () => {
50
+ parsedDot = false;
51
+ const template = SUBRULE(triplesSameSubjectSubrule);
52
+ ACTION(() => {
53
+ triples.push(...template);
54
+ });
55
+ OPTION(() => {
56
+ dotToken = CONSUME(l.symbols.dot);
57
+ parsedDot = true;
58
+ });
59
+ },
76
60
  });
77
- }
78
- });
79
- return ACTION(() => C.astFactory.patternBgp(triples, C.astFactory.sourceLocation(...triples, dotToken)));
80
- };
61
+ return ACTION(() => C.astFactory.patternBgp(triples, C.astFactory.sourceLocation(...triples, dotToken)));
62
+ };
81
63
  }
82
- const triplesBlock = {
83
- name: "triplesBlock",
84
- impl: (implArgs) => (C) => triplesDotSeperated(triplesSameSubjectPath)(implArgs)(C),
85
- gImpl: ({ SUBRULE, PRINT_WORD, HANDLE_LOC, NEW_LINE }) => (ast, { astFactory: F }) => {
86
- for (const [index, triple] of ast.triples.entries()) {
87
- HANDLE_LOC(triple, () => {
88
- const nextTriple = ast.triples.at(index);
89
- if (F.isTripleCollection(triple)) {
90
- SUBRULE(graphNodePath, triple);
91
- F.printFilter(triple, () => {
92
- PRINT_WORD(".");
93
- NEW_LINE();
94
- });
95
- } else {
96
- SUBRULE(graphNodePath, triple.subject);
97
- F.printFilter(triple, () => PRINT_WORD(""));
98
- if (F.isTerm(triple.predicate) && F.isTermVariable(triple.predicate)) {
99
- SUBRULE(import_general.varOrTerm, triple.predicate);
100
- } else {
101
- SUBRULE(import_propertyPaths.pathGenerator, triple.predicate, void 0);
102
- }
103
- F.printFilter(triple, () => PRINT_WORD(""));
104
- SUBRULE(graphNodePath, triple.object);
105
- if (nextTriple === void 0 || F.isTripleCollection(nextTriple) || !F.isSourceLocationNoMaterialize(nextTriple.subject.loc)) {
106
- F.printFilter(ast, () => {
107
- PRINT_WORD(".");
108
- NEW_LINE();
109
- });
110
- } else if (F.isSourceLocationNoMaterialize(nextTriple.predicate.loc)) {
111
- F.printFilter(ast, () => PRINT_WORD(","));
112
- } else {
113
- F.printFilter(ast, () => {
114
- PRINT_WORD(";");
115
- NEW_LINE();
64
+ /**
65
+ * [[55]](https://www.w3.org/TR/sparql11-query/#rTriplesBlock)
66
+ */
67
+ exports.triplesBlock = {
68
+ name: 'triplesBlock',
69
+ impl: implArgs => C => triplesDotSeperated(exports.triplesSameSubjectPath)(implArgs)(C),
70
+ gImpl: ({ SUBRULE, PRINT_WORD, HANDLE_LOC, NEW_LINE }) => (ast, { astFactory: F }) => {
71
+ for (const [index, triple] of ast.triples.entries()) {
72
+ HANDLE_LOC(triple, () => {
73
+ const nextTriple = ast.triples.at(index);
74
+ if (F.isTripleCollection(triple)) {
75
+ SUBRULE(exports.graphNodePath, triple);
76
+ // A top level tripleCollection block means that it is not used in a triple. So you endf with DOT.
77
+ F.printFilter(triple, () => {
78
+ PRINT_WORD('.');
79
+ NEW_LINE();
80
+ });
81
+ }
82
+ else {
83
+ // Subject
84
+ SUBRULE(exports.graphNodePath, triple.subject);
85
+ F.printFilter(triple, () => PRINT_WORD(''));
86
+ // Predicate
87
+ if (F.isTerm(triple.predicate) && F.isTermVariable(triple.predicate)) {
88
+ SUBRULE(general_js_1.varOrTerm, triple.predicate);
89
+ }
90
+ else {
91
+ SUBRULE(propertyPaths_js_1.pathGenerator, triple.predicate, undefined);
92
+ }
93
+ F.printFilter(triple, () => PRINT_WORD(''));
94
+ // Object
95
+ SUBRULE(exports.graphNodePath, triple.object);
96
+ // If no more things, or a top level collection (only possible if new block was part), or new subject: add DOT
97
+ if (nextTriple === undefined || F.isTripleCollection(nextTriple) ||
98
+ !F.isSourceLocationNoMaterialize(nextTriple.subject.loc)) {
99
+ F.printFilter(ast, () => {
100
+ PRINT_WORD('.');
101
+ NEW_LINE();
102
+ });
103
+ }
104
+ else if (F.isSourceLocationNoMaterialize(nextTriple.predicate.loc)) {
105
+ F.printFilter(ast, () => PRINT_WORD(','));
106
+ }
107
+ else {
108
+ F.printFilter(ast, () => {
109
+ PRINT_WORD(';');
110
+ NEW_LINE();
111
+ });
112
+ }
113
+ }
116
114
  });
117
- }
118
115
  }
119
- });
120
- }
121
- }
116
+ },
122
117
  };
118
+ /**
119
+ * [[75]](https://www.w3.org/TR/sparql11-query/#rTriplesSameSubject)
120
+ * [[81]](https://www.w3.org/TR/sparql11-query/#rTriplesSameSubjectPath)
121
+ * CONTRACT: triples generated from the subject come first, then comes the main triple,
122
+ * and then come the triples from the object. Only the first occurrence of a term has `SourceLocationType = source`
123
+ */
123
124
  function triplesSameSubjectImpl(name, allowPaths) {
124
- return {
125
- name,
126
- impl: ({ ACTION, SUBRULE, OR }) => (C) => OR([
127
- { ALT: () => {
128
- const subject = SUBRULE(import_general.varOrTerm);
129
- const res = SUBRULE(allowPaths ? propertyListPathNotEmpty : propertyListNotEmpty, ACTION(() => C.astFactory.dematerialized(subject)));
130
- return ACTION(() => {
131
- if (res.length > 0) {
132
- res[0].subject = subject;
133
- res[0].loc = C.astFactory.sourceLocation(subject, res[0]);
134
- }
135
- return res;
136
- });
137
- } },
138
- { ALT: () => {
139
- const subjectNode = SUBRULE(allowPaths ? triplesNodePath : triplesNode);
140
- const restNode = SUBRULE(allowPaths ? propertyListPath : propertyList, ACTION(() => C.astFactory.graphNodeIdentifier(subjectNode)));
141
- return ACTION(() => {
142
- if (restNode.length === 0) {
143
- return [subjectNode];
144
- }
145
- restNode[0].subject = subjectNode;
146
- restNode[0].loc = C.astFactory.sourceLocation(subjectNode, restNode[0]);
147
- return restNode;
148
- });
149
- } }
150
- ])
151
- };
125
+ return {
126
+ name,
127
+ impl: ({ ACTION, SUBRULE, OR }) => C => OR([
128
+ { ALT: () => {
129
+ const subject = SUBRULE(general_js_1.varOrTerm);
130
+ const res = SUBRULE(allowPaths ? exports.propertyListPathNotEmpty : exports.propertyListNotEmpty, ACTION(() => C.astFactory.dematerialized(subject)));
131
+ // Only the first occurrence of a subject is actually materialized.
132
+ return ACTION(() => {
133
+ if (res.length > 0) {
134
+ res[0].subject = subject;
135
+ res[0].loc = C.astFactory.sourceLocation(subject, res[0]);
136
+ }
137
+ return res;
138
+ });
139
+ } },
140
+ { ALT: () => {
141
+ const subjectNode = SUBRULE(allowPaths ? exports.triplesNodePath : exports.triplesNode);
142
+ const restNode = SUBRULE(allowPaths ? exports.propertyListPath : exports.propertyList, ACTION(() => C.astFactory.graphNodeIdentifier(subjectNode)));
143
+ return ACTION(() => {
144
+ if (restNode.length === 0) {
145
+ return [subjectNode];
146
+ }
147
+ restNode[0].subject = subjectNode;
148
+ restNode[0].loc = C.astFactory.sourceLocation(subjectNode, restNode[0]);
149
+ return restNode;
150
+ });
151
+ } },
152
+ ]),
153
+ };
152
154
  }
153
- const triplesSameSubject = triplesSameSubjectImpl("triplesSameSubject", false);
154
- const triplesSameSubjectPath = triplesSameSubjectImpl("triplesSameSubjectPath", true);
155
- const triplesTemplate = {
156
- name: "triplesTemplate",
157
- impl: triplesDotSeperated(triplesSameSubject)
155
+ exports.triplesSameSubject = triplesSameSubjectImpl('triplesSameSubject', false);
156
+ exports.triplesSameSubjectPath = triplesSameSubjectImpl('triplesSameSubjectPath', true);
157
+ /**
158
+ * [[52]](https://www.w3.org/TR/sparql11-query/#rTriplesTemplate)
159
+ */
160
+ exports.triplesTemplate = {
161
+ name: 'triplesTemplate',
162
+ impl: triplesDotSeperated(exports.triplesSameSubject),
158
163
  };
164
+ /**
165
+ * [[76]](https://www.w3.org/TR/sparql11-query/#rPropertyList)
166
+ * [[82]](https://www.w3.org/TR/sparql11-query/#rPropertyListPath)
167
+ */
159
168
  function propertyListImpl(name, allowPaths) {
160
- return {
161
- name,
162
- impl: ({ SUBRULE, OPTION }) => (_, subject) => OPTION(() => SUBRULE(allowPaths ? propertyListPathNotEmpty : propertyListNotEmpty, subject)) ?? []
163
- };
169
+ return {
170
+ name,
171
+ impl: ({ SUBRULE, OPTION }) => (_, subject) => OPTION(() => SUBRULE(allowPaths ? exports.propertyListPathNotEmpty : exports.propertyListNotEmpty, subject)) ?? [],
172
+ };
164
173
  }
165
- const propertyList = propertyListImpl("propertyList", false);
166
- const propertyListPath = propertyListImpl("propertyListPath", true);
174
+ exports.propertyList = propertyListImpl('propertyList', false);
175
+ exports.propertyListPath = propertyListImpl('propertyListPath', true);
176
+ // We could use gates for this, but in that case,
177
+ // a grammar not in need of paths would still have to include the path rules
178
+ /**
179
+ * [[77]](https://www.w3.org/TR/sparql11-query/#rPropertyListNotEmpty)
180
+ * [[83]](https://www.w3.org/TR/sparql11-query/#rPropertyListPathNotEmpty)
181
+ */
167
182
  function propertyListNotEmptyImplementation(name, allowPaths) {
168
- return {
169
- name,
170
- impl: ({ ACTION, CONSUME, AT_LEAST_ONE, SUBRULE1, MANY2, OR1 }) => (_, subject) => {
171
- const result = [];
172
- let parsedSemi = true;
173
- AT_LEAST_ONE({
174
- GATE: () => parsedSemi,
175
- DEF: () => {
176
- parsedSemi = false;
177
- const predicate = allowPaths ? OR1([
178
- { ALT: () => SUBRULE1(verbPath) },
179
- { ALT: () => SUBRULE1(verbSimple) }
180
- ]) : SUBRULE1(import_general.verb);
181
- const triples = SUBRULE1(allowPaths ? objectListPath : objectList, subject, predicate);
182
- MANY2(() => {
183
- CONSUME(l.symbols.semi);
184
- parsedSemi = true;
185
- });
186
- ACTION(() => {
187
- result.push(...triples);
188
- });
189
- }
190
- });
191
- return result;
192
- }
193
- };
183
+ return {
184
+ name,
185
+ impl: ({ ACTION, CONSUME, AT_LEAST_ONE, SUBRULE1, MANY2, OR1 }) => (_, subject) => {
186
+ const result = [];
187
+ let parsedSemi = true;
188
+ AT_LEAST_ONE({
189
+ GATE: () => parsedSemi,
190
+ DEF: () => {
191
+ parsedSemi = false;
192
+ const predicate = allowPaths ?
193
+ OR1([
194
+ { ALT: () => SUBRULE1(exports.verbPath) },
195
+ { ALT: () => SUBRULE1(exports.verbSimple) },
196
+ ]) :
197
+ SUBRULE1(general_js_1.verb);
198
+ const triples = SUBRULE1(allowPaths ? exports.objectListPath : exports.objectList, subject, predicate);
199
+ MANY2(() => {
200
+ CONSUME(l.symbols.semi);
201
+ parsedSemi = true;
202
+ });
203
+ ACTION(() => {
204
+ result.push(...triples);
205
+ });
206
+ },
207
+ });
208
+ return result;
209
+ },
210
+ };
194
211
  }
195
- const propertyListNotEmpty = propertyListNotEmptyImplementation("propertyListNotEmpty", false);
196
- const propertyListPathNotEmpty = propertyListNotEmptyImplementation("propertyListPathNotEmpty", true);
197
- const verbPath = {
198
- name: "verbPath",
199
- impl: ({ SUBRULE }) => () => SUBRULE(import_propertyPaths.path)
212
+ exports.propertyListNotEmpty = propertyListNotEmptyImplementation('propertyListNotEmpty', false);
213
+ exports.propertyListPathNotEmpty = propertyListNotEmptyImplementation('propertyListPathNotEmpty', true);
214
+ /**
215
+ * [[84]](https://www.w3.org/TR/sparql11-query/#rVerbPath)
216
+ */
217
+ exports.verbPath = {
218
+ name: 'verbPath',
219
+ impl: ({ SUBRULE }) => () => SUBRULE(propertyPaths_js_1.path),
200
220
  };
201
- const verbSimple = {
202
- name: "verbSimple",
203
- impl: ({ SUBRULE }) => () => SUBRULE(import_general.var_)
221
+ /**
222
+ * [[85]](https://www.w3.org/TR/sparql11-query/#rVerbSimple)
223
+ */
224
+ exports.verbSimple = {
225
+ name: 'verbSimple',
226
+ impl: ({ SUBRULE }) => () => SUBRULE(general_js_1.var_),
204
227
  };
228
+ /**
229
+ * [[79]](https://www.w3.org/TR/sparql11-query/#rObjectList)
230
+ * [[86]](https://www.w3.org/TR/sparql11-query/#rObjectListPath)
231
+ */
205
232
  function objectListImpl(name, allowPaths) {
206
- return {
207
- name,
208
- impl: ({ ACTION, SUBRULE, AT_LEAST_ONE_SEP }) => (_, subj, pred) => {
209
- const objects = [];
210
- AT_LEAST_ONE_SEP({
211
- SEP: l.symbols.comma,
212
- DEF: () => {
213
- const objectTriple = SUBRULE(allowPaths ? objectPath : object, subj, pred);
214
- ACTION(() => {
215
- objects.push(objectTriple);
216
- });
217
- }
218
- });
219
- return objects;
220
- }
221
- };
233
+ return {
234
+ name,
235
+ impl: ({ ACTION, SUBRULE, AT_LEAST_ONE_SEP }) => (_, subj, pred) => {
236
+ const objects = [];
237
+ AT_LEAST_ONE_SEP({
238
+ SEP: l.symbols.comma,
239
+ DEF: () => {
240
+ const objectTriple = SUBRULE(allowPaths ? exports.objectPath : exports.object, subj, pred);
241
+ ACTION(() => {
242
+ objects.push(objectTriple);
243
+ });
244
+ },
245
+ });
246
+ return objects;
247
+ },
248
+ };
222
249
  }
223
- const objectList = objectListImpl("objectList", false);
224
- const objectListPath = objectListImpl("objectListPath", true);
250
+ exports.objectList = objectListImpl('objectList', false);
251
+ exports.objectListPath = objectListImpl('objectListPath', true);
252
+ /**
253
+ * [[80]](https://www.w3.org/TR/sparql11-query/#rObject)
254
+ * [[87]](https://www.w3.org/TR/sparql11-query/#rObjectPath)
255
+ */
225
256
  function objectImpl(name, allowPaths) {
226
- return {
227
- name,
228
- impl: ({ ACTION, SUBRULE }) => (C, subject, predicate) => {
229
- const node = SUBRULE(allowPaths ? graphNodePath : graphNode);
230
- return ACTION(() => C.astFactory.triple(subject, predicate, node));
231
- }
232
- };
257
+ return {
258
+ name,
259
+ impl: ({ ACTION, SUBRULE }) => (C, subject, predicate) => {
260
+ const node = SUBRULE(allowPaths ? exports.graphNodePath : exports.graphNode);
261
+ return ACTION(() => C.astFactory.triple(subject, predicate, node));
262
+ },
263
+ };
233
264
  }
234
- const object = objectImpl("object", false);
235
- const objectPath = objectImpl("objectPath", true);
265
+ exports.object = objectImpl('object', false);
266
+ exports.objectPath = objectImpl('objectPath', true);
267
+ /**
268
+ * [[102]](https://www.w3.org/TR/sparql11-query/#rCollection)
269
+ * [[103]](https://www.w3.org/TR/sparql11-query/#rCollectionPath)
270
+ */
236
271
  function collectionImpl(name, allowPaths) {
237
- return {
238
- name,
239
- impl: ({ ACTION, AT_LEAST_ONE, SUBRULE, CONSUME }) => (C) => {
240
- const terms = [];
241
- const startToken = CONSUME(l.symbols.LParen);
242
- AT_LEAST_ONE(() => {
243
- terms.push(SUBRULE(allowPaths ? graphNodePath : graphNode));
244
- });
245
- const endToken = CONSUME(l.symbols.RParen);
246
- return ACTION(() => {
247
- const F = C.astFactory;
248
- const triples = [];
249
- const predFirst = F.termNamed(F.sourceLocationNoMaterialize(), import_utils.CommonIRIs.FIRST, void 0);
250
- const predRest = F.termNamed(F.sourceLocationNoMaterialize(), import_utils.CommonIRIs.REST, void 0);
251
- const predNil = F.termNamed(F.sourceLocationNoMaterialize(), import_utils.CommonIRIs.NIL, void 0);
252
- const listHead = F.termBlank(void 0, F.sourceLocationNoMaterialize());
253
- let iterHead = listHead;
254
- for (const [index, term] of terms.entries()) {
255
- const lastInList = index === terms.length - 1;
256
- const headTriple = F.triple(iterHead, predFirst, term);
257
- triples.push(headTriple);
258
- if (lastInList) {
259
- const nilTriple = F.triple(iterHead, predRest, predNil);
260
- triples.push(nilTriple);
261
- } else {
262
- const tail = F.termBlank(void 0, F.sourceLocationNoMaterialize());
263
- const linkTriple = F.triple(iterHead, predRest, tail);
264
- triples.push(linkTriple);
265
- iterHead = tail;
266
- }
267
- }
268
- return F.tripleCollectionList(listHead, triples, F.sourceLocation(startToken, endToken));
269
- });
270
- },
271
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F }) => {
272
- F.printFilter(ast, () => PRINT_WORD("("));
273
- for (const [idx, triple] of ast.triples.entries()) {
274
- if (idx % 2 === 0) {
275
- SUBRULE(allowPaths ? graphNodePath : graphNode, triple.object);
276
- }
277
- }
278
- F.printFilter(ast, () => PRINT_WORD(")"));
279
- }
280
- };
272
+ return {
273
+ name,
274
+ impl: ({ ACTION, AT_LEAST_ONE, SUBRULE, CONSUME }) => (C) => {
275
+ // Construct a [cons list](https://en.wikipedia.org/wiki/Cons#Lists),
276
+ // here called a [RDF collection](https://www.w3.org/TR/sparql11-query/#collections).
277
+ const terms = [];
278
+ const startToken = CONSUME(l.symbols.LParen);
279
+ AT_LEAST_ONE(() => {
280
+ terms.push(SUBRULE(allowPaths ? exports.graphNodePath : exports.graphNode));
281
+ });
282
+ const endToken = CONSUME(l.symbols.RParen);
283
+ return ACTION(() => {
284
+ const F = C.astFactory;
285
+ const triples = [];
286
+ // The triples created in your recursion
287
+ const predFirst = F.termNamed(F.sourceLocationNoMaterialize(), utils_js_1.CommonIRIs.FIRST, undefined);
288
+ const predRest = F.termNamed(F.sourceLocationNoMaterialize(), utils_js_1.CommonIRIs.REST, undefined);
289
+ const predNil = F.termNamed(F.sourceLocationNoMaterialize(), utils_js_1.CommonIRIs.NIL, undefined);
290
+ const listHead = F.termBlank(undefined, F.sourceLocationNoMaterialize());
291
+ let iterHead = listHead;
292
+ for (const [index, term] of terms.entries()) {
293
+ const lastInList = index === terms.length - 1;
294
+ const headTriple = F.triple(iterHead, predFirst, term);
295
+ triples.push(headTriple);
296
+ // If not the last, create new iterHead, otherwise, close list
297
+ if (lastInList) {
298
+ const nilTriple = F.triple(iterHead, predRest, predNil);
299
+ triples.push(nilTriple);
300
+ }
301
+ else {
302
+ const tail = F.termBlank(undefined, F.sourceLocationNoMaterialize());
303
+ const linkTriple = F.triple(iterHead, predRest, tail);
304
+ triples.push(linkTriple);
305
+ iterHead = tail;
306
+ }
307
+ }
308
+ return F.tripleCollectionList(listHead, triples, F.sourceLocation(startToken, endToken));
309
+ });
310
+ },
311
+ gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F }) => {
312
+ F.printFilter(ast, () => PRINT_WORD('('));
313
+ // Only every 2 triple is relevant. The odd triples are linking triples.
314
+ for (const [idx, triple] of ast.triples.entries()) {
315
+ if (idx % 2 === 0) {
316
+ SUBRULE(allowPaths ? exports.graphNodePath : exports.graphNode, triple.object);
317
+ }
318
+ }
319
+ F.printFilter(ast, () => PRINT_WORD(')'));
320
+ },
321
+ };
281
322
  }
282
- const collection = collectionImpl("collection", false);
283
- const collectionPath = collectionImpl("collectionPath", true);
323
+ exports.collection = collectionImpl('collection', false);
324
+ exports.collectionPath = collectionImpl('collectionPath', true);
325
+ /**
326
+ * [[98]](https://www.w3.org/TR/sparql11-query/#rTriplesNode)
327
+ * [[100]](https://www.w3.org/TR/sparql11-query/#rTriplesNodePath)
328
+ */
284
329
  function triplesNodeImpl(name, allowPaths) {
285
- return {
286
- name,
287
- impl: ({ SUBRULE, OR }) => () => OR([
288
- { ALT: () => SUBRULE(allowPaths ? collectionPath : collection) },
289
- { ALT: () => SUBRULE(allowPaths ? blankNodePropertyListPath : blankNodePropertyList) }
290
- ]),
291
- gImpl: ({ SUBRULE }) => (ast) => ast.subType === "list" ? SUBRULE(allowPaths ? collectionPath : collection, ast) : SUBRULE(allowPaths ? blankNodePropertyListPath : blankNodePropertyList, ast)
292
- };
330
+ return {
331
+ name,
332
+ impl: ({ SUBRULE, OR }) => () => OR([
333
+ { ALT: () => SUBRULE(allowPaths ? exports.collectionPath : exports.collection) },
334
+ { ALT: () => SUBRULE(allowPaths ? exports.blankNodePropertyListPath : exports.blankNodePropertyList) },
335
+ ]),
336
+ gImpl: ({ SUBRULE }) => ast => ast.subType === 'list' ?
337
+ SUBRULE(allowPaths ? exports.collectionPath : exports.collection, ast) :
338
+ SUBRULE(allowPaths ? exports.blankNodePropertyListPath : exports.blankNodePropertyList, ast),
339
+ };
293
340
  }
294
- const triplesNode = triplesNodeImpl("triplesNode", false);
295
- const triplesNodePath = triplesNodeImpl("triplesNodePath", true);
341
+ exports.triplesNode = triplesNodeImpl('triplesNode', false);
342
+ exports.triplesNodePath = triplesNodeImpl('triplesNodePath', true);
343
+ /**
344
+ * [[99]](https://www.w3.org/TR/sparql11-query/#rBlankNodePropertyList)
345
+ * [[101]](https://www.w3.org/TR/sparql11-query/#rBlankNodePropertyListPath)
346
+ */
296
347
  function blankNodePropertyListImpl(name, allowPaths) {
297
- const propertyPathNotEmptyImpl = allowPaths ? propertyListPathNotEmpty : propertyListNotEmpty;
298
- return {
299
- name,
300
- impl: ({ ACTION, SUBRULE, CONSUME }) => (C) => {
301
- const startToken = CONSUME(l.symbols.LSquare);
302
- const blankNode = ACTION(() => C.astFactory.termBlank(void 0, C.astFactory.sourceLocationNoMaterialize()));
303
- const propList = SUBRULE(propertyPathNotEmptyImpl, blankNode);
304
- const endToken = CONSUME(l.symbols.RSquare);
305
- return ACTION(() => C.astFactory.tripleCollectionBlankNodeProperties(blankNode, propList, C.astFactory.sourceLocation(startToken, endToken)));
306
- },
307
- gImpl: ({ SUBRULE, PRINT, PRINT_WORD, HANDLE_LOC, PRINT_ON_EMPTY, NEW_LINE }) => (ast, c) => {
308
- const { astFactory: F, indentInc } = c;
309
- F.printFilter(ast, () => {
310
- c[import_core.traqulaIndentation] += indentInc;
311
- PRINT("[");
312
- NEW_LINE();
313
- });
314
- for (const triple of ast.triples) {
315
- HANDLE_LOC(triple, () => {
316
- if (F.isTerm(triple.predicate) && F.isTermVariable(triple.predicate)) {
317
- SUBRULE(import_general.varOrTerm, triple.predicate);
318
- } else {
319
- SUBRULE(import_propertyPaths.pathGenerator, triple.predicate, void 0);
320
- }
321
- F.printFilter(triple, () => PRINT_WORD(""));
322
- SUBRULE(graphNodePath, triple.object);
323
- F.printFilter(ast, () => {
324
- PRINT_WORD(";");
325
- NEW_LINE();
326
- });
327
- });
328
- }
329
- F.printFilter(ast, () => {
330
- c[import_core.traqulaIndentation] -= indentInc;
331
- PRINT_ON_EMPTY("]");
332
- });
333
- }
334
- };
348
+ const propertyPathNotEmptyImpl = allowPaths ? exports.propertyListPathNotEmpty : exports.propertyListNotEmpty;
349
+ return {
350
+ name,
351
+ impl: ({ ACTION, SUBRULE, CONSUME }) => (C) => {
352
+ const startToken = CONSUME(l.symbols.LSquare);
353
+ const blankNode = ACTION(() => C.astFactory.termBlank(undefined, C.astFactory.sourceLocationNoMaterialize()));
354
+ const propList = SUBRULE(propertyPathNotEmptyImpl, blankNode);
355
+ const endToken = CONSUME(l.symbols.RSquare);
356
+ return ACTION(() => C.astFactory.tripleCollectionBlankNodeProperties(blankNode, propList, C.astFactory.sourceLocation(startToken, endToken)));
357
+ },
358
+ gImpl: ({ SUBRULE, PRINT, PRINT_WORD, HANDLE_LOC, PRINT_ON_EMPTY, NEW_LINE }) => (ast, c) => {
359
+ const { astFactory: F, indentInc } = c;
360
+ F.printFilter(ast, () => {
361
+ c[core_1.traqulaIndentation] += indentInc;
362
+ PRINT('[');
363
+ NEW_LINE();
364
+ });
365
+ for (const triple of ast.triples) {
366
+ HANDLE_LOC(triple, () => {
367
+ // Predicate
368
+ if (F.isTerm(triple.predicate) && F.isTermVariable(triple.predicate)) {
369
+ SUBRULE(general_js_1.varOrTerm, triple.predicate);
370
+ }
371
+ else {
372
+ SUBRULE(propertyPaths_js_1.pathGenerator, triple.predicate, undefined);
373
+ }
374
+ F.printFilter(triple, () => PRINT_WORD(''));
375
+ // Object
376
+ SUBRULE(exports.graphNodePath, triple.object);
377
+ F.printFilter(ast, () => {
378
+ PRINT_WORD(';');
379
+ NEW_LINE();
380
+ });
381
+ });
382
+ }
383
+ F.printFilter(ast, () => {
384
+ c[core_1.traqulaIndentation] -= indentInc;
385
+ PRINT_ON_EMPTY(']');
386
+ });
387
+ },
388
+ };
335
389
  }
336
- const blankNodePropertyList = blankNodePropertyListImpl("blankNodePropertyList", false);
337
- const blankNodePropertyListPath = blankNodePropertyListImpl("blankNodePropertyListPath", true);
390
+ exports.blankNodePropertyList = blankNodePropertyListImpl('blankNodePropertyList', false);
391
+ exports.blankNodePropertyListPath = blankNodePropertyListImpl('blankNodePropertyListPath', true);
392
+ /**
393
+ * [[103]](https://www.w3.org/TR/sparql11-query/#rGraphNode)
394
+ * [[105]](https://www.w3.org/TR/sparql11-query/#rGraphNodePath)
395
+ */
338
396
  function graphNodeImpl(name, allowPaths) {
339
- const triplesNodeRule = allowPaths ? triplesNodePath : triplesNode;
340
- return {
341
- name,
342
- impl: ({ SUBRULE, OR }) => (C) => OR([
343
- { ALT: () => SUBRULE(import_general.varOrTerm) },
344
- {
345
- GATE: () => C.parseMode.has("canCreateBlankNodes"),
346
- ALT: () => SUBRULE(triplesNodeRule)
347
- }
348
- ]),
349
- gImpl: ({ SUBRULE }) => (ast, { astFactory: F }) => {
350
- if (F.isTerm(ast)) {
351
- SUBRULE(import_general.varOrTerm, ast);
352
- } else {
353
- SUBRULE(triplesNodeRule, ast);
354
- }
355
- }
356
- };
397
+ const triplesNodeRule = allowPaths ? exports.triplesNodePath : exports.triplesNode;
398
+ return {
399
+ name,
400
+ impl: ({ SUBRULE, OR }) => C => OR([
401
+ { ALT: () => SUBRULE(general_js_1.varOrTerm) },
402
+ {
403
+ GATE: () => C.parseMode.has('canCreateBlankNodes'),
404
+ ALT: () => SUBRULE(triplesNodeRule),
405
+ },
406
+ ]),
407
+ gImpl: ({ SUBRULE }) => (ast, { astFactory: F }) => {
408
+ if (F.isTerm(ast)) {
409
+ SUBRULE(general_js_1.varOrTerm, ast);
410
+ }
411
+ else {
412
+ SUBRULE(triplesNodeRule, ast);
413
+ }
414
+ },
415
+ };
357
416
  }
358
- const graphNode = graphNodeImpl("graphNode", false);
359
- const graphNodePath = graphNodeImpl("graphNodePath", true);
360
- // Annotate the CommonJS export names for ESM import in node:
361
- 0 && (module.exports = {
362
- blankNodePropertyList,
363
- blankNodePropertyListPath,
364
- collection,
365
- collectionPath,
366
- graphNode,
367
- graphNodePath,
368
- object,
369
- objectList,
370
- objectListPath,
371
- objectPath,
372
- propertyList,
373
- propertyListNotEmpty,
374
- propertyListPath,
375
- propertyListPathNotEmpty,
376
- triplesBlock,
377
- triplesNode,
378
- triplesNodePath,
379
- triplesSameSubject,
380
- triplesSameSubjectPath,
381
- triplesTemplate,
382
- verbPath,
383
- verbSimple
384
- });
417
+ exports.graphNode = graphNodeImpl('graphNode', false);
418
+ exports.graphNodePath = graphNodeImpl('graphNodePath', true);
419
+ //# sourceMappingURL=tripleBlock.js.map