@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.
- package/README.md +2 -0
- package/dist/cjs/lib/MinimalSparqlParser.js +66 -58
- package/dist/cjs/lib/MinimalSparqlParser.js.map +1 -0
- package/dist/cjs/lib/Sparql11types.js +2 -15
- package/dist/cjs/lib/Sparql11types.js.map +1 -0
- package/dist/cjs/lib/astFactory.js +110 -119
- package/dist/cjs/lib/astFactory.js.map +1 -0
- package/dist/cjs/lib/expressionHelpers.js +181 -191
- package/dist/cjs/lib/expressionHelpers.js.map +1 -0
- package/dist/cjs/lib/factoryMixins/ContextFactory.js +30 -52
- package/dist/cjs/lib/factoryMixins/ContextFactory.js.map +1 -0
- package/dist/cjs/lib/factoryMixins/ExpressionFactory.js +83 -102
- package/dist/cjs/lib/factoryMixins/ExpressionFactory.js.map +1 -0
- package/dist/cjs/lib/factoryMixins/GraphRefFactory.js +51 -73
- package/dist/cjs/lib/factoryMixins/GraphRefFactory.js.map +1 -0
- package/dist/cjs/lib/factoryMixins/PathFactory.js +68 -87
- package/dist/cjs/lib/factoryMixins/PathFactory.js.map +1 -0
- package/dist/cjs/lib/factoryMixins/Patternfactory.js +98 -120
- package/dist/cjs/lib/factoryMixins/Patternfactory.js.map +1 -0
- package/dist/cjs/lib/factoryMixins/QueryFactory.js +43 -65
- package/dist/cjs/lib/factoryMixins/QueryFactory.js.map +1 -0
- package/dist/cjs/lib/factoryMixins/SolutionModifiersFactory.js +55 -77
- package/dist/cjs/lib/factoryMixins/SolutionModifiersFactory.js.map +1 -0
- package/dist/cjs/lib/factoryMixins/TermFactory.js +81 -102
- package/dist/cjs/lib/factoryMixins/TermFactory.js.map +1 -0
- package/dist/cjs/lib/factoryMixins/UpdateOperationFactory.js +126 -147
- package/dist/cjs/lib/factoryMixins/UpdateOperationFactory.js.map +1 -0
- package/dist/cjs/lib/factoryMixins/mixins.js +21 -38
- package/dist/cjs/lib/factoryMixins/mixins.js.map +1 -0
- package/dist/cjs/lib/grammar/builtIn.js +277 -377
- package/dist/cjs/lib/grammar/builtIn.js.map +1 -0
- package/dist/cjs/lib/grammar/dataSetClause.js +110 -109
- package/dist/cjs/lib/grammar/dataSetClause.js.map +1 -0
- package/dist/cjs/lib/grammar/expression.js +387 -358
- package/dist/cjs/lib/grammar/expression.js.map +1 -0
- package/dist/cjs/lib/grammar/general.js +173 -158
- package/dist/cjs/lib/grammar/general.js.map +1 -0
- package/dist/cjs/lib/grammar/index.js +94 -111
- package/dist/cjs/lib/grammar/index.js.map +1 -0
- package/dist/cjs/lib/grammar/literals.js +292 -266
- package/dist/cjs/lib/grammar/literals.js.map +1 -0
- package/dist/cjs/lib/grammar/propertyPaths.js +206 -193
- package/dist/cjs/lib/grammar/propertyPaths.js.map +1 -0
- package/dist/cjs/lib/grammar/queryUnit.js +395 -372
- package/dist/cjs/lib/grammar/queryUnit.js.map +1 -0
- package/dist/cjs/lib/grammar/solutionModifier.js +281 -265
- package/dist/cjs/lib/grammar/solutionModifier.js.map +1 -0
- package/dist/cjs/lib/grammar/tripleBlock.js +396 -355
- package/dist/cjs/lib/grammar/tripleBlock.js.map +1 -0
- package/dist/cjs/lib/grammar/updateUnit.js +551 -519
- package/dist/cjs/lib/grammar/updateUnit.js.map +1 -0
- package/dist/cjs/lib/grammar/whereClause.js +486 -459
- package/dist/cjs/lib/grammar/whereClause.js.map +1 -0
- package/dist/cjs/lib/index.js +47 -54
- package/dist/cjs/lib/index.js.map +1 -0
- package/dist/cjs/lib/lexer/BuiltInCalls.js +188 -333
- package/dist/cjs/lib/lexer/BuiltInCalls.js.map +1 -0
- package/dist/cjs/lib/lexer/graph.js +10 -40
- package/dist/cjs/lib/lexer/graph.js.map +1 -0
- package/dist/cjs/lib/lexer/index.js +43 -48
- package/dist/cjs/lib/lexer/index.js.map +1 -0
- package/dist/cjs/lib/lexer/lexer.js +84 -195
- package/dist/cjs/lib/lexer/lexer.js.map +1 -0
- package/dist/cjs/lib/lexer/lexerPatterns.js +40 -132
- package/dist/cjs/lib/lexer/lexerPatterns.js.map +1 -0
- package/dist/cjs/lib/lexer/symbols.js +31 -106
- package/dist/cjs/lib/lexer/symbols.js.map +1 -0
- package/dist/cjs/lib/lexer/terminals.js +100 -102
- package/dist/cjs/lib/lexer/terminals.js.map +1 -0
- package/dist/cjs/lib/sparql11HelperTypes.js +2 -15
- package/dist/cjs/lib/sparql11HelperTypes.js.map +1 -0
- package/dist/cjs/lib/utils.js +40 -58
- package/dist/cjs/lib/utils.js.map +1 -0
- package/dist/cjs/lib/validation/validators.js +217 -196
- package/dist/cjs/lib/validation/validators.js.map +1 -0
- package/dist/esm/lib/MinimalSparqlParser.d.ts +26 -8
- package/dist/esm/lib/MinimalSparqlParser.js +40 -11
- package/dist/esm/lib/MinimalSparqlParser.js.map +1 -1
- package/dist/esm/lib/astFactory.d.ts +66 -45
- package/dist/esm/lib/astFactory.js +3 -0
- package/dist/esm/lib/astFactory.js.map +1 -1
- package/dist/esm/lib/factoryMixins/ContextFactory.d.ts +7 -5
- package/dist/esm/lib/factoryMixins/ExpressionFactory.d.ts +7 -5
- package/dist/esm/lib/factoryMixins/GraphRefFactory.d.ts +7 -5
- package/dist/esm/lib/factoryMixins/PathFactory.d.ts +7 -5
- package/dist/esm/lib/factoryMixins/Patternfactory.d.ts +7 -5
- package/dist/esm/lib/factoryMixins/QueryFactory.d.ts +7 -5
- package/dist/esm/lib/factoryMixins/SolutionModifiersFactory.d.ts +7 -5
- package/dist/esm/lib/factoryMixins/TermFactory.d.ts +7 -5
- package/dist/esm/lib/factoryMixins/UpdateOperationFactory.d.ts +7 -5
- package/dist/esm/lib/grammar/index.js +1 -1
- package/dist/esm/lib/grammar/index.js.map +1 -1
- package/dist/esm/lib/grammar/literals.js +23 -13
- package/dist/esm/lib/grammar/literals.js.map +1 -1
- package/dist/esm/lib/grammar/propertyPaths.d.ts +2 -2
- package/dist/esm/lib/grammar/tripleBlock.d.ts +4 -4
- package/dist/esm/lib/grammar/tripleBlock.js +18 -12
- package/dist/esm/lib/grammar/tripleBlock.js.map +1 -1
- package/dist/esm/lib/grammar/updateUnit.js +2 -2
- package/dist/esm/lib/grammar/updateUnit.js.map +1 -1
- package/dist/esm/lib/lexer/BuiltInCalls.d.ts +1 -1
- package/dist/esm/lib/lexer/graph.d.ts +1 -1
- package/dist/esm/lib/lexer/lexer.d.ts +2 -2
- package/dist/esm/lib/lexer/lexerPatterns.d.ts +1 -1
- package/dist/esm/lib/lexer/lexerPatterns.js +1 -1
- package/dist/esm/lib/lexer/lexerPatterns.js.map +1 -1
- package/dist/esm/lib/lexer/symbols.d.ts +1 -1
- package/dist/esm/lib/lexer/terminals.d.ts +2 -2
- package/dist/esm/lib/lexer/terminals.js +3 -3
- package/dist/esm/lib/lexer/terminals.js.map +1 -1
- package/dist/esm/lib/sparql11HelperTypes.d.ts +1 -1
- package/dist/esm/lib/sparql11HelperTypes.js.map +1 -1
- package/dist/esm/lib/validation/validators.d.ts +2 -2
- package/dist/esm/lib/validation/validators.js +61 -51
- package/dist/esm/lib/validation/validators.js.map +1 -1
- package/package.json +10 -10
|
@@ -1,384 +1,425 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
175
|
+
return {
|
|
176
|
+
name,
|
|
177
|
+
impl: ({ SUBRULE, OPTION }) => (_, subject) => OPTION(() => SUBRULE(allowPaths ? exports.propertyListPathNotEmpty : exports.propertyListNotEmpty, subject)) ?? [],
|
|
178
|
+
};
|
|
164
179
|
}
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
224
|
-
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
235
|
-
|
|
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
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
283
|
-
|
|
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
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
-
|
|
295
|
-
|
|
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
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
337
|
-
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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
|