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

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