@traqula/rules-sparql-1-2 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/AstFactory.js +75 -94
- package/dist/cjs/lib/AstFactory.js.map +1 -0
- package/dist/cjs/lib/grammar.js +662 -602
- package/dist/cjs/lib/grammar.js.map +1 -0
- package/dist/cjs/lib/index.js +45 -50
- package/dist/cjs/lib/index.js.map +1 -0
- package/dist/cjs/lib/lexer.js +39 -92
- package/dist/cjs/lib/lexer.js.map +1 -0
- package/dist/cjs/lib/parserUtils.js +33 -42
- package/dist/cjs/lib/parserUtils.js.map +1 -0
- package/dist/cjs/lib/sparql12HelperTypes.js +2 -15
- package/dist/cjs/lib/sparql12HelperTypes.js.map +1 -0
- package/dist/cjs/lib/sparql12Types.js +2 -15
- package/dist/cjs/lib/sparql12Types.js.map +1 -0
- package/dist/cjs/lib/validators.js +82 -97
- package/dist/cjs/lib/validators.js.map +1 -0
- package/dist/esm/lib/AstFactory.d.ts +3 -0
- package/dist/esm/lib/AstFactory.js +4 -1
- package/dist/esm/lib/AstFactory.js.map +1 -1
- package/dist/esm/lib/grammar.d.ts +4 -4
- package/dist/esm/lib/grammar.js +12 -6
- package/dist/esm/lib/grammar.js.map +1 -1
- package/dist/esm/lib/lexer.d.ts +1 -1
- package/dist/esm/lib/parserUtils.d.ts +7 -4
- package/dist/esm/lib/parserUtils.js +15 -3
- package/dist/esm/lib/parserUtils.js.map +1 -1
- package/package.json +10 -10
package/dist/cjs/lib/grammar.js
CHANGED
|
@@ -1,644 +1,704 @@
|
|
|
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 grammar_exports = {};
|
|
30
|
-
__export(grammar_exports, {
|
|
31
|
-
annotation: () => annotation,
|
|
32
|
-
annotationBlock: () => annotationBlock,
|
|
33
|
-
annotationBlockPath: () => annotationBlockPath,
|
|
34
|
-
annotationPath: () => annotationPath,
|
|
35
|
-
buildInHasLang: () => buildInHasLang,
|
|
36
|
-
buildInHasLangDir: () => buildInHasLangDir,
|
|
37
|
-
buildInIsTriple: () => buildInIsTriple,
|
|
38
|
-
buildInLangDir: () => buildInLangDir,
|
|
39
|
-
buildInLangStrDir: () => buildInLangStrDir,
|
|
40
|
-
buildInObject: () => buildInObject,
|
|
41
|
-
buildInPredicate: () => buildInPredicate,
|
|
42
|
-
buildInSubject: () => buildInSubject,
|
|
43
|
-
buildInTriple: () => buildInTriple,
|
|
44
|
-
builtInCall: () => builtInCall,
|
|
45
|
-
dataBlockValue: () => dataBlockValue,
|
|
46
|
-
exprTripleTerm: () => exprTripleTerm,
|
|
47
|
-
exprTripleTermObject: () => exprTripleTermObject,
|
|
48
|
-
exprTripleTermSubject: () => exprTripleTermSubject,
|
|
49
|
-
generateGraphTerm: () => generateGraphTerm,
|
|
50
|
-
generateTriplesBlock: () => generateTriplesBlock,
|
|
51
|
-
graphNode: () => graphNode,
|
|
52
|
-
graphNodePath: () => graphNodePath,
|
|
53
|
-
object: () => object,
|
|
54
|
-
objectPath: () => objectPath,
|
|
55
|
-
primaryExpression: () => primaryExpression,
|
|
56
|
-
prologue: () => prologue,
|
|
57
|
-
rdfLiteral: () => rdfLiteral,
|
|
58
|
-
reifiedTriple: () => reifiedTriple,
|
|
59
|
-
reifiedTripleBlock: () => reifiedTripleBlock,
|
|
60
|
-
reifiedTripleBlockPath: () => reifiedTripleBlockPath,
|
|
61
|
-
reifiedTripleObject: () => reifiedTripleObject,
|
|
62
|
-
reifiedTripleSubject: () => reifiedTripleSubject,
|
|
63
|
-
reifier: () => reifier,
|
|
64
|
-
tripleTerm: () => tripleTerm,
|
|
65
|
-
tripleTermData: () => tripleTermData,
|
|
66
|
-
tripleTermDataObject: () => tripleTermDataObject,
|
|
67
|
-
tripleTermDataSubject: () => tripleTermDataSubject,
|
|
68
|
-
tripleTermObject: () => tripleTermObject,
|
|
69
|
-
tripleTermSubject: () => tripleTermSubject,
|
|
70
|
-
triplesSameSubject: () => triplesSameSubject,
|
|
71
|
-
triplesSameSubjectPath: () => triplesSameSubjectPath,
|
|
72
|
-
unaryExpression: () => unaryExpression,
|
|
73
|
-
varOrReifierId: () => varOrReifierId,
|
|
74
|
-
varOrTerm: () => varOrTerm,
|
|
75
|
-
versionDecl: () => versionDecl,
|
|
76
|
-
versionSpecifier: () => versionSpecifier
|
|
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;
|
|
77
17
|
});
|
|
78
|
-
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
var
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
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.generateGraphTerm = exports.generateTriplesBlock = exports.unaryExpression = exports.rdfLiteral = exports.builtInCall = exports.buildInObject = exports.buildInPredicate = exports.buildInSubject = exports.buildInTriple = exports.buildInIsTriple = exports.buildInHasLangDir = exports.buildInHasLang = exports.buildInLangStrDir = exports.buildInLangDir = exports.exprTripleTermObject = exports.exprTripleTermSubject = exports.exprTripleTerm = exports.primaryExpression = exports.tripleTermDataObject = exports.tripleTermDataSubject = exports.tripleTermData = exports.tripleTermObject = exports.tripleTermSubject = exports.tripleTerm = exports.reifiedTripleObject = exports.reifiedTripleSubject = exports.reifiedTriple = exports.varOrTerm = exports.graphNodePath = exports.graphNode = exports.annotationBlock = exports.annotationBlockPath = exports.annotation = exports.annotationPath = exports.objectPath = exports.object = exports.triplesSameSubjectPath = exports.triplesSameSubject = exports.varOrReifierId = exports.reifier = exports.dataBlockValue = exports.reifiedTripleBlockPath = exports.reifiedTripleBlock = exports.prologue = exports.versionSpecifier = exports.versionDecl = void 0;
|
|
37
|
+
const core_1 = require("@traqula/core");
|
|
38
|
+
const rules_sparql_1_1_1 = require("@traqula/rules-sparql-1-1");
|
|
39
|
+
const l12 = __importStar(require("./lexer.js"));
|
|
40
|
+
const validators_js_1 = require("./validators.js");
|
|
41
|
+
/**
|
|
42
|
+
*[[7]](https://www.w3.org/TR/sparql12-query/#rVersionDecl)
|
|
43
|
+
*/
|
|
44
|
+
exports.versionDecl = {
|
|
45
|
+
name: 'versionDecl',
|
|
46
|
+
impl: ({ ACTION, SUBRULE, CONSUME }) => (C) => {
|
|
47
|
+
const versionToken = CONSUME(l12.version);
|
|
48
|
+
const identifier = SUBRULE(exports.versionSpecifier);
|
|
49
|
+
return ACTION(() => C.astFactory.contextDefinitionVersion(identifier.val, C.astFactory.sourceLocation(versionToken, identifier)));
|
|
50
|
+
},
|
|
51
|
+
gImpl: ({ PRINT_ON_OWN_LINE }) => (ast, { astFactory: F }) => {
|
|
52
|
+
F.printFilter(ast, () => {
|
|
53
|
+
PRINT_ON_OWN_LINE('VERSION ', `${rules_sparql_1_1_1.gram.stringEscapedLexical(ast.version)}`);
|
|
54
|
+
});
|
|
55
|
+
},
|
|
95
56
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
57
|
+
/**
|
|
58
|
+
* [[8]](https://www.w3.org/TR/sparql12-query/#rVersionSpecifier)
|
|
59
|
+
*/
|
|
60
|
+
exports.versionSpecifier = {
|
|
61
|
+
name: 'versionSpecifier',
|
|
62
|
+
impl: ({ ACTION, CONSUME, OR }) => (C) => {
|
|
63
|
+
const token = OR([
|
|
64
|
+
{ ALT: () => CONSUME(rules_sparql_1_1_1.lex.terminals.stringLiteral1) },
|
|
65
|
+
{ ALT: () => CONSUME(rules_sparql_1_1_1.lex.terminals.stringLiteral2) },
|
|
66
|
+
]);
|
|
67
|
+
return ACTION(() => C.astFactory.wrap(token.image.slice(1, -1), C.astFactory.sourceLocation(token)));
|
|
68
|
+
},
|
|
105
69
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
70
|
+
/**
|
|
71
|
+
* OVERRIDING RULE {@link S11.prologue}
|
|
72
|
+
* [[4]](https://www.w3.org/TR/sparql12-query/#rPrologue)
|
|
73
|
+
*/
|
|
74
|
+
exports.prologue = {
|
|
75
|
+
name: 'prologue',
|
|
76
|
+
impl: ({ SUBRULE, MANY, OR }) => () => {
|
|
77
|
+
const result = [];
|
|
78
|
+
MANY(() => OR([
|
|
79
|
+
{ ALT: () => result.push(SUBRULE(rules_sparql_1_1_1.gram.baseDecl)) },
|
|
80
|
+
// TODO: the [spec](https://www.w3.org/TR/sparql11-query/#iriRefs) says you cannot redefine prefixes.
|
|
81
|
+
// We might need to check this.
|
|
82
|
+
{ ALT: () => result.push(SUBRULE(rules_sparql_1_1_1.gram.prefixDecl)) },
|
|
83
|
+
{ ALT: () => result.push(SUBRULE(exports.versionDecl)) },
|
|
84
|
+
]));
|
|
85
|
+
return result;
|
|
86
|
+
},
|
|
87
|
+
gImpl: ({ SUBRULE }) => (ast, { astFactory: F }) => {
|
|
88
|
+
for (const context of ast) {
|
|
89
|
+
if (F.isContextDefinitionBase(context)) {
|
|
90
|
+
SUBRULE(rules_sparql_1_1_1.gram.baseDecl, context);
|
|
91
|
+
}
|
|
92
|
+
else if (F.isContextDefinitionPrefix(context)) {
|
|
93
|
+
SUBRULE(rules_sparql_1_1_1.gram.prefixDecl, context);
|
|
94
|
+
}
|
|
95
|
+
else if (F.isContextDefinitionVersion(context)) {
|
|
96
|
+
SUBRULE(exports.versionDecl, context);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
130
100
|
};
|
|
131
101
|
function reifiedTripleBlockImpl(name, allowPath) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
102
|
+
return {
|
|
103
|
+
name,
|
|
104
|
+
impl: ({ ACTION, SUBRULE }) => (C) => {
|
|
105
|
+
const triple = SUBRULE(exports.reifiedTriple);
|
|
106
|
+
const properties = SUBRULE(allowPath ? rules_sparql_1_1_1.gram.propertyListPath : rules_sparql_1_1_1.gram.propertyList, ACTION(() => C.astFactory.dematerialized(triple.identifier)));
|
|
107
|
+
return ACTION(() => [triple, ...properties]);
|
|
108
|
+
},
|
|
109
|
+
};
|
|
140
110
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
111
|
+
/**
|
|
112
|
+
* [[58]](https://www.w3.org/TR/sparql12-query/#rReifiedTripleBlock) Used by triplesSameSubject
|
|
113
|
+
*/
|
|
114
|
+
exports.reifiedTripleBlock = reifiedTripleBlockImpl('reifiedTripleBlock', false);
|
|
115
|
+
/**
|
|
116
|
+
* [[59]](https://www.w3.org/TR/sparql12-query/#rReifiedTripleBlockPath) Used by TriplesSameSubjectPath
|
|
117
|
+
*/
|
|
118
|
+
exports.reifiedTripleBlockPath = reifiedTripleBlockImpl('reifiedTripleBlockPath', true);
|
|
119
|
+
/**
|
|
120
|
+
* OVERRIDING RULE: {@link S11.dataBlockValue}.
|
|
121
|
+
* [[69]](https://www.w3.org/TR/sparql12-query/#rDataBlockValue)
|
|
122
|
+
*/
|
|
123
|
+
exports.dataBlockValue = {
|
|
124
|
+
name: 'dataBlockValue',
|
|
125
|
+
impl: $ => C => $.OR2([
|
|
126
|
+
{ ALT: () => rules_sparql_1_1_1.gram.dataBlockValue.impl($)(C) },
|
|
127
|
+
{ ALT: () => $.SUBRULE(exports.tripleTermData) },
|
|
128
|
+
]),
|
|
149
129
|
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
130
|
+
/**
|
|
131
|
+
* [[70]](https://www.w3.org/TR/sparql12-query/#rReifier)
|
|
132
|
+
*/
|
|
133
|
+
exports.reifier = {
|
|
134
|
+
name: 'reifier',
|
|
135
|
+
impl: ({ ACTION, CONSUME, SUBRULE, OPTION }) => (C) => {
|
|
136
|
+
const tildeToken = CONSUME(l12.tilde);
|
|
137
|
+
const reifier = OPTION(() => SUBRULE(exports.varOrReifierId));
|
|
138
|
+
return ACTION(() => {
|
|
139
|
+
if (reifier === undefined && !C.parseMode.has('canCreateBlankNodes')) {
|
|
140
|
+
throw new Error('Cannot create blanknodes in current parse mode');
|
|
141
|
+
}
|
|
142
|
+
return C.astFactory.wrap(reifier ?? C.astFactory.termBlank(undefined, C.astFactory.sourceLocation()), C.astFactory.sourceLocation(tildeToken, reifier));
|
|
143
|
+
});
|
|
144
|
+
},
|
|
162
145
|
};
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
{
|
|
169
|
-
|
|
146
|
+
/**
|
|
147
|
+
* [[71]](https://www.w3.org/TR/sparql12-query/#rVarOrReifierId)
|
|
148
|
+
*/
|
|
149
|
+
exports.varOrReifierId = {
|
|
150
|
+
name: 'varOrReifierId',
|
|
151
|
+
impl: ({ SUBRULE, OR }) => C => OR([
|
|
152
|
+
{ GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(rules_sparql_1_1_1.gram.var_) },
|
|
153
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.iri) },
|
|
154
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.blankNode) },
|
|
155
|
+
]),
|
|
170
156
|
};
|
|
171
157
|
function triplesSameSubjectImpl(name, allowPaths) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
158
|
+
return {
|
|
159
|
+
name,
|
|
160
|
+
impl: $ => C => $.OR2([
|
|
161
|
+
{ ALT: () => allowPaths ?
|
|
162
|
+
rules_sparql_1_1_1.gram.triplesSameSubjectPath.impl($)(C) :
|
|
163
|
+
rules_sparql_1_1_1.gram.triplesSameSubject.impl($)(C) },
|
|
164
|
+
{ ALT: () => $.SUBRULE(allowPaths ? exports.reifiedTripleBlockPath : exports.reifiedTripleBlock) },
|
|
165
|
+
]),
|
|
166
|
+
};
|
|
179
167
|
}
|
|
180
|
-
|
|
181
|
-
|
|
168
|
+
/**
|
|
169
|
+
* OVERRIDING RULE {@link S11.triplesSameSubject}
|
|
170
|
+
* [[81]](https://www.w3.org/TR/sparql12-query/#rTriplesSameSubject)
|
|
171
|
+
*/
|
|
172
|
+
exports.triplesSameSubject = triplesSameSubjectImpl('triplesSameSubject', false);
|
|
173
|
+
/**
|
|
174
|
+
* OVERRIDING RULE {@link S11.triplesSameSubjectPath}
|
|
175
|
+
* [[87]](https://www.w3.org/TR/sparql12-query/#rTriplesSameSubjectPath)
|
|
176
|
+
*/
|
|
177
|
+
exports.triplesSameSubjectPath = triplesSameSubjectImpl('triplesSameSubjectPath', true);
|
|
182
178
|
function objectImpl(name, allowPaths) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
179
|
+
return {
|
|
180
|
+
name,
|
|
181
|
+
impl: ({ ACTION, SUBRULE }) => (C, subject, predicate) => {
|
|
182
|
+
const objectVal = SUBRULE(allowPaths ? exports.graphNodePath : exports.graphNode);
|
|
183
|
+
const annotationVal = SUBRULE(allowPaths ? exports.annotationPath : exports.annotation);
|
|
184
|
+
return ACTION(() => {
|
|
185
|
+
const F = C.astFactory;
|
|
186
|
+
if (F.isPathPure(predicate) && annotationVal.length > 0) {
|
|
187
|
+
throw new Error('Note 17 violation');
|
|
188
|
+
}
|
|
189
|
+
return F.annotatedTriple(subject, predicate, objectVal, annotationVal);
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
};
|
|
197
193
|
}
|
|
198
|
-
|
|
199
|
-
|
|
194
|
+
/**
|
|
195
|
+
* OVERRIDING RULE: {@link S11.object}.
|
|
196
|
+
* [[86]](https://www.w3.org/TR/sparql12-query/#rObject) Used by ObjectList
|
|
197
|
+
*/
|
|
198
|
+
exports.object = objectImpl('object', false);
|
|
199
|
+
/**
|
|
200
|
+
* OVERRIDING RULE: {@link S11.objectPath}.
|
|
201
|
+
* [[87]](https://www.w3.org/TR/sparql12-query/#rTriplesSameSubjectPath) Used by ObjectListPath
|
|
202
|
+
*/
|
|
203
|
+
exports.objectPath = objectImpl('objectPath', true);
|
|
200
204
|
function annotationImpl(name, allowPaths) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
205
|
+
return {
|
|
206
|
+
name,
|
|
207
|
+
impl: ({ ACTION, SUBRULE, OR, MANY }) => (C) => {
|
|
208
|
+
const annotations = [];
|
|
209
|
+
let currentReifier;
|
|
210
|
+
MANY(() => {
|
|
211
|
+
OR([
|
|
212
|
+
{ ALT: () => {
|
|
213
|
+
const node = SUBRULE(exports.reifier);
|
|
214
|
+
annotations.push(node);
|
|
215
|
+
currentReifier = node.val;
|
|
216
|
+
} },
|
|
217
|
+
{ ALT: () => {
|
|
218
|
+
ACTION(() => {
|
|
219
|
+
if (!currentReifier && !C.parseMode.has('canCreateBlankNodes')) {
|
|
220
|
+
throw new Error('Cannot create blanknodes in current parse mode');
|
|
221
|
+
}
|
|
222
|
+
currentReifier = currentReifier ?? C.astFactory.termBlank(undefined, C.astFactory.sourceLocation());
|
|
223
|
+
});
|
|
224
|
+
const block = SUBRULE(allowPaths ? exports.annotationBlockPath : exports.annotationBlock, currentReifier);
|
|
225
|
+
ACTION(() => {
|
|
226
|
+
annotations.push(block);
|
|
227
|
+
currentReifier = undefined;
|
|
228
|
+
});
|
|
229
|
+
} },
|
|
230
|
+
]);
|
|
219
231
|
});
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
} else {
|
|
235
|
-
F.printFilter(annotation2, () => PRINT_WORD("~"));
|
|
236
|
-
SUBRULE(graphNodePath, annotation2.val);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
};
|
|
232
|
+
return annotations;
|
|
233
|
+
},
|
|
234
|
+
gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F }) => {
|
|
235
|
+
for (const annotation of ast) {
|
|
236
|
+
if (F.isTripleCollectionBlankNodeProperties(annotation)) {
|
|
237
|
+
SUBRULE(exports.annotationBlockPath, annotation);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
F.printFilter(annotation, () => PRINT_WORD('~'));
|
|
241
|
+
SUBRULE(exports.graphNodePath, annotation.val);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
};
|
|
241
246
|
}
|
|
242
|
-
|
|
243
|
-
|
|
247
|
+
/**
|
|
248
|
+
* [[109]](https://www.w3.org/TR/sparql12-query/#rAnnotationPath)
|
|
249
|
+
*/
|
|
250
|
+
exports.annotationPath = annotationImpl('annotationPath', true);
|
|
251
|
+
/**
|
|
252
|
+
* [[111]](https://www.w3.org/TR/sparql12-query/#rAnnotation)
|
|
253
|
+
*/
|
|
254
|
+
exports.annotation = annotationImpl('annotation', false);
|
|
244
255
|
function annotationBlockImpl(name, allowPaths) {
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
256
|
+
return {
|
|
257
|
+
name,
|
|
258
|
+
impl: ({ ACTION, SUBRULE, CONSUME }) => (C, arg) => {
|
|
259
|
+
const open = CONSUME(l12.annotationOpen);
|
|
260
|
+
const res = SUBRULE(allowPaths ? rules_sparql_1_1_1.gram.propertyListPathNotEmpty : rules_sparql_1_1_1.gram.propertyListNotEmpty, arg);
|
|
261
|
+
const close = CONSUME(l12.annotationClose);
|
|
262
|
+
return ACTION(() => C.astFactory.tripleCollectionBlankNodeProperties(arg, res, C.astFactory.sourceLocation(open, close)));
|
|
263
|
+
},
|
|
264
|
+
gImpl: ({ SUBRULE, PRINT_WORD, HANDLE_LOC, NEW_LINE, PRINT_ON_OWN_LINE }) => (ast, C) => {
|
|
265
|
+
const { astFactory: F, indentInc } = C;
|
|
266
|
+
F.printFilter(ast, () => {
|
|
267
|
+
PRINT_WORD('{|');
|
|
268
|
+
if (ast.triples.length > 1) {
|
|
269
|
+
C[core_1.traqulaIndentation] += indentInc;
|
|
270
|
+
NEW_LINE();
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
function printTriple(triple) {
|
|
274
|
+
HANDLE_LOC(triple, () => {
|
|
275
|
+
if (F.isTerm(triple.predicate)) {
|
|
276
|
+
SUBRULE(exports.graphNodePath, triple.predicate);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
SUBRULE(rules_sparql_1_1_1.gram.pathGenerator, triple.predicate, undefined);
|
|
280
|
+
}
|
|
281
|
+
F.printFilter(triple, () => PRINT_WORD(''));
|
|
282
|
+
SUBRULE(exports.graphNodePath, triple.object);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
const [head, ...tail] = ast.triples;
|
|
286
|
+
printTriple(head);
|
|
287
|
+
for (const triple of tail) {
|
|
288
|
+
F.printFilter(ast, () => {
|
|
289
|
+
PRINT_WORD(';');
|
|
290
|
+
NEW_LINE();
|
|
291
|
+
});
|
|
292
|
+
printTriple(triple);
|
|
293
|
+
}
|
|
294
|
+
F.printFilter(ast, () => {
|
|
295
|
+
if (ast.triples.length > 1) {
|
|
296
|
+
PRINT_ON_OWN_LINE('|}');
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
PRINT_WORD('|}');
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
};
|
|
291
304
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
305
|
+
/**
|
|
306
|
+
* [[110]](https://www.w3.org/TR/sparql12-query/#rAnnotationBlockPath)
|
|
307
|
+
*/
|
|
308
|
+
exports.annotationBlockPath = annotationBlockImpl('annotationBlockPath', true);
|
|
309
|
+
/**
|
|
310
|
+
* [[112]](https://www.w3.org/TR/sparql12-query/#rAnnotationBlock)
|
|
311
|
+
*/
|
|
312
|
+
exports.annotationBlock = annotationBlockImpl('annotationBlock', false);
|
|
313
|
+
/**
|
|
314
|
+
* OVERRIDING RULE: {@link S11.graphNode}.
|
|
315
|
+
* [[113]](https://www.w3.org/TR/sparql12-query/#rGraphNode)
|
|
316
|
+
*/
|
|
317
|
+
exports.graphNode = {
|
|
318
|
+
name: 'graphNode',
|
|
319
|
+
impl: $ => C => $.OR2([
|
|
320
|
+
{ ALT: () => rules_sparql_1_1_1.gram.graphNode.impl($)(C) },
|
|
321
|
+
{ ALT: () => $.SUBRULE(exports.reifiedTriple) },
|
|
322
|
+
]),
|
|
300
323
|
};
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
324
|
+
/**
|
|
325
|
+
* OVERRIDING RULE: {@link S11.graphNodePath}.
|
|
326
|
+
* [[114]](https://www.w3.org/TR/sparql12-query/#rGraphNodePath)
|
|
327
|
+
*/
|
|
328
|
+
exports.graphNodePath = {
|
|
329
|
+
name: 'graphNodePath',
|
|
330
|
+
impl: $ => C => $.OR2([
|
|
331
|
+
{ ALT: () => rules_sparql_1_1_1.gram.graphNodePath.impl($)(C) },
|
|
332
|
+
{ ALT: () => $.SUBRULE(exports.reifiedTriple) },
|
|
333
|
+
]),
|
|
334
|
+
gImpl: $ => (ast, C) => {
|
|
335
|
+
if (C.astFactory.isTripleCollectionReifiedTriple(ast)) {
|
|
336
|
+
$.SUBRULE(exports.reifiedTriple, ast);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
rules_sparql_1_1_1.gram.graphNodePath.gImpl($)(ast, C);
|
|
340
|
+
}
|
|
341
|
+
},
|
|
314
342
|
};
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
{
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
343
|
+
/**
|
|
344
|
+
* OVERRIDING RULE: {@link S11.varOrTerm}.
|
|
345
|
+
* [[115]](https://www.w3.org/TR/sparql12-query/#rVarOrTerm)
|
|
346
|
+
*/
|
|
347
|
+
exports.varOrTerm = {
|
|
348
|
+
name: 'varOrTerm',
|
|
349
|
+
impl: ({ ACTION, SUBRULE, OR, CONSUME }) => C => OR([
|
|
350
|
+
{ GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(rules_sparql_1_1_1.gram.var_) },
|
|
351
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.iri) },
|
|
352
|
+
{ ALT: () => SUBRULE(exports.rdfLiteral) },
|
|
353
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.numericLiteral) },
|
|
354
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.booleanLiteral) },
|
|
355
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.blankNode) },
|
|
356
|
+
{ ALT: () => {
|
|
357
|
+
const token = CONSUME(rules_sparql_1_1_1.lex.terminals.nil);
|
|
358
|
+
return ACTION(() => C.astFactory.termNamed(C.astFactory.sourceLocation(token), rules_sparql_1_1_1.CommonIRIs.NIL));
|
|
359
|
+
} },
|
|
360
|
+
{ ALT: () => SUBRULE(exports.tripleTerm) },
|
|
361
|
+
]),
|
|
362
|
+
// Generation remains untouched - go through graphTerm
|
|
331
363
|
};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
364
|
+
/**
|
|
365
|
+
* [[116]](https://www.w3.org/TR/sparql12-query/#rReifiedTriple)
|
|
366
|
+
*/
|
|
367
|
+
exports.reifiedTriple = {
|
|
368
|
+
name: 'reifiedTriple',
|
|
369
|
+
impl: ({ ACTION, CONSUME, SUBRULE, OPTION }) => (C) => {
|
|
370
|
+
const open = CONSUME(l12.reificationOpen);
|
|
371
|
+
const subject = SUBRULE(exports.reifiedTripleSubject);
|
|
372
|
+
const predicate = SUBRULE(rules_sparql_1_1_1.gram.verb);
|
|
373
|
+
const object = SUBRULE(exports.reifiedTripleObject);
|
|
374
|
+
const reifierVal = OPTION(() => SUBRULE(exports.reifier));
|
|
375
|
+
const close = CONSUME(l12.reificationClose);
|
|
376
|
+
return ACTION(() => {
|
|
377
|
+
// A reifier would be auto generated in this case, but we are not allowed to use them.
|
|
378
|
+
if (reifierVal === undefined && !C.parseMode.has('canCreateBlankNodes')) {
|
|
379
|
+
throw new Error('Cannot create blanknodes in current parse mode');
|
|
380
|
+
}
|
|
381
|
+
return C.astFactory.tripleCollectionReifiedTriple(C.astFactory.sourceLocation(open, close), subject, predicate, object, reifierVal?.val);
|
|
382
|
+
});
|
|
383
|
+
},
|
|
384
|
+
gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F }) => {
|
|
385
|
+
F.printFilter(ast, () => PRINT_WORD('<<'));
|
|
386
|
+
const triple = ast.triples[0];
|
|
387
|
+
SUBRULE(exports.graphNodePath, triple.subject);
|
|
388
|
+
F.printFilter(ast, () => PRINT_WORD(''));
|
|
389
|
+
if (F.isPathPure(triple.predicate)) {
|
|
390
|
+
SUBRULE(rules_sparql_1_1_1.gram.pathGenerator, triple.predicate, undefined);
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
SUBRULE(exports.graphNodePath, triple.predicate);
|
|
394
|
+
}
|
|
395
|
+
F.printFilter(ast, () => PRINT_WORD(''));
|
|
396
|
+
SUBRULE(exports.graphNodePath, triple.object);
|
|
397
|
+
SUBRULE(exports.annotationPath, [F.wrap(ast.identifier, ast.identifier.loc)]);
|
|
398
|
+
F.printFilter(ast, () => PRINT_WORD('>>'));
|
|
399
|
+
},
|
|
363
400
|
};
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
{
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
401
|
+
/**
|
|
402
|
+
* [[117]](https://www.w3.org/TR/sparql12-query/#rReifiedTripleSubject)
|
|
403
|
+
*/
|
|
404
|
+
exports.reifiedTripleSubject = {
|
|
405
|
+
name: 'reifiedTripleSubject',
|
|
406
|
+
impl: ({ OR, SUBRULE }) => C => OR([
|
|
407
|
+
{ GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(rules_sparql_1_1_1.gram.var_) },
|
|
408
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.iri) },
|
|
409
|
+
{ ALT: () => SUBRULE(exports.rdfLiteral) },
|
|
410
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.numericLiteral) },
|
|
411
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.booleanLiteral) },
|
|
412
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.blankNode) },
|
|
413
|
+
{ ALT: () => SUBRULE(exports.reifiedTriple) },
|
|
414
|
+
{ ALT: () => SUBRULE(exports.tripleTerm) },
|
|
415
|
+
]),
|
|
376
416
|
};
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
417
|
+
/**
|
|
418
|
+
* [[118]](https://www.w3.org/TR/sparql12-query/#rReifiedTripleObject)
|
|
419
|
+
*/
|
|
420
|
+
exports.reifiedTripleObject = {
|
|
421
|
+
name: 'reifiedTripleObject',
|
|
422
|
+
impl: exports.reifiedTripleSubject.impl,
|
|
380
423
|
};
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
424
|
+
/**
|
|
425
|
+
* [[119]](https://www.w3.org/TR/sparql12-query/#rTripleTerm)
|
|
426
|
+
*/
|
|
427
|
+
exports.tripleTerm = {
|
|
428
|
+
name: 'tripleTerm',
|
|
429
|
+
impl: ({ ACTION, CONSUME, SUBRULE }) => (C) => {
|
|
430
|
+
const open = CONSUME(l12.tripleTermOpen);
|
|
431
|
+
const subject = SUBRULE(exports.tripleTermSubject);
|
|
432
|
+
const predicate = SUBRULE(rules_sparql_1_1_1.gram.verb);
|
|
433
|
+
const object = SUBRULE(exports.tripleTermObject);
|
|
434
|
+
const close = CONSUME(l12.tripleTermClose);
|
|
435
|
+
return ACTION(() => C.astFactory.termTriple(subject, predicate, object, C.astFactory.sourceLocation(open, close)));
|
|
436
|
+
},
|
|
437
|
+
gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F }) => {
|
|
438
|
+
F.printFilter(ast, () => PRINT_WORD('<<('));
|
|
439
|
+
SUBRULE(exports.graphNodePath, ast.subject);
|
|
440
|
+
F.printFilter(ast, () => PRINT_WORD(''));
|
|
441
|
+
SUBRULE(exports.graphNodePath, ast.predicate);
|
|
442
|
+
F.printFilter(ast, () => PRINT_WORD(''));
|
|
443
|
+
SUBRULE(exports.graphNodePath, ast.object);
|
|
444
|
+
F.printFilter(ast, () => PRINT_WORD(')>>'));
|
|
445
|
+
},
|
|
400
446
|
};
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
{
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
447
|
+
/**
|
|
448
|
+
* [[120]](https://www.w3.org/TR/sparql12-query/#rTripleTermSubject)
|
|
449
|
+
*/
|
|
450
|
+
exports.tripleTermSubject = {
|
|
451
|
+
name: 'tripleTermSubject',
|
|
452
|
+
impl: ({ SUBRULE, OR }) => C => OR([
|
|
453
|
+
{ GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(rules_sparql_1_1_1.gram.var_) },
|
|
454
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.iri) },
|
|
455
|
+
{ ALT: () => SUBRULE(exports.rdfLiteral) },
|
|
456
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.numericLiteral) },
|
|
457
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.booleanLiteral) },
|
|
458
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.blankNode) },
|
|
459
|
+
{ ALT: () => SUBRULE(exports.tripleTerm) },
|
|
460
|
+
]),
|
|
412
461
|
};
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
462
|
+
/**
|
|
463
|
+
* [[121]](https://www.w3.org/TR/sparql12-query/#rTripleTermObject)
|
|
464
|
+
*/
|
|
465
|
+
exports.tripleTermObject = {
|
|
466
|
+
name: 'tripleTermObject',
|
|
467
|
+
impl: exports.tripleTermSubject.impl,
|
|
416
468
|
};
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
469
|
+
/**
|
|
470
|
+
* [[122]](https://www.w3.org/TR/sparql12-query/#rTripleTermData)
|
|
471
|
+
*/
|
|
472
|
+
exports.tripleTermData = {
|
|
473
|
+
name: 'tripleTermData',
|
|
474
|
+
impl: ({ ACTION, CONSUME, OR, SUBRULE }) => (C) => {
|
|
475
|
+
const open = CONSUME(l12.tripleTermOpen);
|
|
476
|
+
const subject = SUBRULE(exports.tripleTermDataSubject);
|
|
477
|
+
const predicate = OR([
|
|
478
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.iri) },
|
|
479
|
+
{ ALT: () => {
|
|
480
|
+
const token = CONSUME(rules_sparql_1_1_1.lex.a);
|
|
481
|
+
return ACTION(() => C.astFactory.termNamed(C.astFactory.sourceLocation(token), rules_sparql_1_1_1.CommonIRIs.TYPE));
|
|
482
|
+
} },
|
|
483
|
+
]);
|
|
484
|
+
const object = SUBRULE(exports.tripleTermDataObject);
|
|
485
|
+
const close = CONSUME(l12.tripleTermClose);
|
|
486
|
+
return ACTION(() => C.astFactory.termTriple(subject, predicate, object, C.astFactory.sourceLocation(open, close)));
|
|
487
|
+
},
|
|
433
488
|
};
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
{
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
489
|
+
/**
|
|
490
|
+
* [[123]](https://www.w3.org/TR/sparql12-query/#rTripleTermDataSubject)
|
|
491
|
+
*/
|
|
492
|
+
exports.tripleTermDataSubject = {
|
|
493
|
+
name: 'tripleTermDataSubject',
|
|
494
|
+
impl: ({ OR, SUBRULE }) => () => OR([
|
|
495
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.iri) },
|
|
496
|
+
{ ALT: () => SUBRULE(exports.rdfLiteral) },
|
|
497
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.numericLiteral) },
|
|
498
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.booleanLiteral) },
|
|
499
|
+
{ ALT: () => SUBRULE(exports.tripleTermData) },
|
|
500
|
+
]),
|
|
443
501
|
};
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
502
|
+
/**
|
|
503
|
+
* [[124]](https://www.w3.org/TR/sparql12-query/#rTripleTermDataObject)
|
|
504
|
+
*/
|
|
505
|
+
exports.tripleTermDataObject = {
|
|
506
|
+
name: 'tripleTermDataObject',
|
|
507
|
+
impl: exports.tripleTermDataSubject.impl,
|
|
447
508
|
};
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
509
|
+
/**
|
|
510
|
+
* OVERRIDING RULE: {@link S11.primaryExpression}.
|
|
511
|
+
* [[136]](https://www.w3.org/TR/sparql12-query/#rPrimaryExpression)
|
|
512
|
+
*/
|
|
513
|
+
exports.primaryExpression = {
|
|
514
|
+
name: 'primaryExpression',
|
|
515
|
+
impl: $ => C => $.OR2([
|
|
516
|
+
{ ALT: () => rules_sparql_1_1_1.gram.primaryExpression.impl($)(C) },
|
|
517
|
+
{ ALT: () => $.SUBRULE(exports.exprTripleTerm) },
|
|
518
|
+
]),
|
|
454
519
|
};
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
520
|
+
/**
|
|
521
|
+
* [[137]](https://www.w3.org/TR/sparql12-query/#rExprTripleTerm)
|
|
522
|
+
*/
|
|
523
|
+
exports.exprTripleTerm = {
|
|
524
|
+
name: 'exprTripleTerm',
|
|
525
|
+
impl: ({ ACTION, CONSUME, SUBRULE }) => (C) => {
|
|
526
|
+
const open = CONSUME(l12.tripleTermOpen);
|
|
527
|
+
const subject = SUBRULE(exports.exprTripleTermSubject);
|
|
528
|
+
const predicate = SUBRULE(rules_sparql_1_1_1.gram.verb);
|
|
529
|
+
const object = SUBRULE(exports.exprTripleTermObject);
|
|
530
|
+
const close = CONSUME(l12.tripleTermClose);
|
|
531
|
+
return ACTION(() => C.astFactory.termTriple(subject, predicate, object, C.astFactory.sourceLocation(open, close)));
|
|
532
|
+
},
|
|
465
533
|
};
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
{
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
534
|
+
/**
|
|
535
|
+
* [[138]](https://www.w3.org/TR/sparql12-query/#rExprTripleTermSubject)
|
|
536
|
+
*/
|
|
537
|
+
exports.exprTripleTermSubject = {
|
|
538
|
+
name: 'exprTripleTermSubject',
|
|
539
|
+
impl: ({ OR, SUBRULE }) => C => OR([
|
|
540
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.iri) },
|
|
541
|
+
{ ALT: () => SUBRULE(exports.rdfLiteral) },
|
|
542
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.numericLiteral) },
|
|
543
|
+
{ ALT: () => SUBRULE(rules_sparql_1_1_1.gram.booleanLiteral) },
|
|
544
|
+
{ GATE: () => C.parseMode.has('canParseVars'), ALT: () => SUBRULE(rules_sparql_1_1_1.gram.var_) },
|
|
545
|
+
{ ALT: () => SUBRULE(exports.exprTripleTerm) },
|
|
546
|
+
]),
|
|
476
547
|
};
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
548
|
+
/**
|
|
549
|
+
* [[139]](https://www.w3.org/TR/sparql12-query/#rExprTripleTermObject)
|
|
550
|
+
*/
|
|
551
|
+
exports.exprTripleTermObject = {
|
|
552
|
+
name: 'exprTripleTermObject',
|
|
553
|
+
impl: exports.exprTripleTermSubject.impl,
|
|
480
554
|
};
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
555
|
+
exports.buildInLangDir = (0, rules_sparql_1_1_1.funcExpr1)(l12.buildInLangDir);
|
|
556
|
+
exports.buildInLangStrDir = (0, rules_sparql_1_1_1.funcExpr3)(l12.buildInStrLangDir);
|
|
557
|
+
exports.buildInHasLang = (0, rules_sparql_1_1_1.funcExpr1)(l12.buildInHasLang);
|
|
558
|
+
exports.buildInHasLangDir = (0, rules_sparql_1_1_1.funcExpr1)(l12.buildInHasLangDir);
|
|
559
|
+
exports.buildInIsTriple = (0, rules_sparql_1_1_1.funcExpr1)(l12.buildInIsTRIPLE);
|
|
560
|
+
exports.buildInTriple = (0, rules_sparql_1_1_1.funcExpr3)(l12.buildInTRIPLE);
|
|
561
|
+
exports.buildInSubject = (0, rules_sparql_1_1_1.funcExpr1)(l12.buildInSUBJECT);
|
|
562
|
+
exports.buildInPredicate = (0, rules_sparql_1_1_1.funcExpr1)(l12.buildInPREDICATE);
|
|
563
|
+
exports.buildInObject = (0, rules_sparql_1_1_1.funcExpr1)(l12.buildInOBJECT);
|
|
564
|
+
/**
|
|
565
|
+
* OVERRIDING RULE: {@link S11.builtInCall}.
|
|
566
|
+
* [[141]](https://www.w3.org/TR/sparql12-query/#rBuiltInCall)
|
|
567
|
+
*/
|
|
568
|
+
exports.builtInCall = {
|
|
569
|
+
name: 'builtInCall',
|
|
570
|
+
impl: $ => C => $.OR2([
|
|
571
|
+
{ ALT: () => rules_sparql_1_1_1.gram.builtInCall.impl($)(C) },
|
|
572
|
+
{ ALT: () => $.SUBRULE(exports.buildInLangDir) },
|
|
573
|
+
{ ALT: () => $.SUBRULE(exports.buildInLangStrDir) },
|
|
574
|
+
{ ALT: () => $.SUBRULE(exports.buildInHasLang) },
|
|
575
|
+
{ ALT: () => $.SUBRULE(exports.buildInHasLangDir) },
|
|
576
|
+
{ ALT: () => $.SUBRULE(exports.buildInIsTriple) },
|
|
577
|
+
{ ALT: () => $.SUBRULE(exports.buildInTriple) },
|
|
578
|
+
{ ALT: () => $.SUBRULE(exports.buildInSubject) },
|
|
579
|
+
{ ALT: () => $.SUBRULE(exports.buildInPredicate) },
|
|
580
|
+
{ ALT: () => $.SUBRULE(exports.buildInObject) },
|
|
581
|
+
]),
|
|
504
582
|
};
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
583
|
+
/**
|
|
584
|
+
* OVERRIDING RULE: {@link S11.rdfLiteral}.
|
|
585
|
+
* No retyping is needed since the return type is the same
|
|
586
|
+
* [[149]](https://www.w3.org/TR/sparql12-query/#rRDFLiteral)
|
|
587
|
+
*/
|
|
588
|
+
exports.rdfLiteral = {
|
|
589
|
+
name: 'rdfLiteral',
|
|
590
|
+
impl: ({ ACTION, SUBRULE, OPTION, CONSUME, OR }) => (C) => {
|
|
591
|
+
const value = SUBRULE(rules_sparql_1_1_1.gram.string);
|
|
592
|
+
return OPTION(() => OR([
|
|
593
|
+
{ ALT: () => {
|
|
594
|
+
const langTag = CONSUME(l12.LANG_DIR);
|
|
595
|
+
return ACTION(() => {
|
|
596
|
+
const literal = C.astFactory.termLiteral(C.astFactory.sourceLocation(value, langTag), value.value, langTag.image.slice(1).toLowerCase());
|
|
597
|
+
(0, validators_js_1.langTagHasCorrectRange)(literal);
|
|
598
|
+
return literal;
|
|
599
|
+
});
|
|
600
|
+
} },
|
|
601
|
+
{ ALT: () => {
|
|
602
|
+
CONSUME(rules_sparql_1_1_1.lex.symbols.hathat);
|
|
603
|
+
const iriVal = SUBRULE(rules_sparql_1_1_1.gram.iri);
|
|
604
|
+
return ACTION(() => C.astFactory.termLiteral(C.astFactory.sourceLocation(value, iriVal), value.value, iriVal));
|
|
605
|
+
} },
|
|
606
|
+
])) ?? value;
|
|
607
|
+
},
|
|
525
608
|
};
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
609
|
+
exports.unaryExpression = {
|
|
610
|
+
name: 'unaryExpression',
|
|
611
|
+
impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, OR1, OR2 }) => C => OR1([
|
|
612
|
+
{ ALT: () => SUBRULE1(exports.primaryExpression) },
|
|
613
|
+
{ ALT: () => {
|
|
614
|
+
const operator = CONSUME(rules_sparql_1_1_1.lex.symbols.exclamation);
|
|
615
|
+
const expr = SUBRULE1(exports.unaryExpression);
|
|
616
|
+
return ACTION(() => C.astFactory.expressionOperation('!', [expr], C.astFactory.sourceLocation(operator, expr)));
|
|
617
|
+
} },
|
|
618
|
+
{ ALT: () => {
|
|
619
|
+
const operator = OR2([
|
|
620
|
+
{ ALT: () => CONSUME(rules_sparql_1_1_1.lex.symbols.opPlus) },
|
|
621
|
+
{ ALT: () => CONSUME(rules_sparql_1_1_1.lex.symbols.opMinus) },
|
|
622
|
+
]);
|
|
623
|
+
const expr = SUBRULE2(exports.primaryExpression);
|
|
624
|
+
return ACTION(() => C.astFactory.expressionOperation(operator.image === '!' ? '!' : (operator.image === '+' ? 'UPLUS' : 'UMINUS'), [expr], C.astFactory.sourceLocation(operator, expr)));
|
|
625
|
+
} },
|
|
626
|
+
]),
|
|
544
627
|
};
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
628
|
+
/**
|
|
629
|
+
* OVERRIDING RULE: {@link S11.triplesBlock}.
|
|
630
|
+
*/
|
|
631
|
+
exports.generateTriplesBlock = {
|
|
632
|
+
name: 'triplesBlock',
|
|
633
|
+
gImpl: ({ SUBRULE, PRINT_WORD, NEW_LINE, HANDLE_LOC }) => (ast, { astFactory: F }) => {
|
|
634
|
+
for (const [index, triple] of ast.triples.entries()) {
|
|
635
|
+
HANDLE_LOC(triple, () => {
|
|
636
|
+
const nextTriple = ast.triples.at(index + 1);
|
|
637
|
+
if (F.isTripleCollection(triple)) {
|
|
638
|
+
SUBRULE(exports.graphNodePath, triple);
|
|
639
|
+
// A top level tripleCollection block means that it is either not used in a triple
|
|
640
|
+
// - or is the subject of a triple. In case it is the subject,
|
|
641
|
+
// the identifier of the block will be the subject of the next triple and that subject is not materialized.
|
|
642
|
+
const isSubjectOfTriple = nextTriple?.type === 'triple' &&
|
|
643
|
+
F.isSourceLocationNoMaterialize(nextTriple.subject.loc);
|
|
644
|
+
if (!isSubjectOfTriple) {
|
|
645
|
+
F.printFilter(triple, () => {
|
|
646
|
+
PRINT_WORD('.');
|
|
647
|
+
NEW_LINE();
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
// Subject
|
|
653
|
+
SUBRULE(exports.graphNodePath, triple.subject);
|
|
654
|
+
F.printFilter(ast, () => PRINT_WORD(''));
|
|
655
|
+
// Predicate
|
|
656
|
+
if (F.isPathPure(triple.predicate)) {
|
|
657
|
+
SUBRULE(rules_sparql_1_1_1.gram.pathGenerator, triple.predicate, undefined);
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
SUBRULE(exports.graphNodePath, triple.predicate);
|
|
661
|
+
}
|
|
662
|
+
F.printFilter(ast, () => PRINT_WORD(''));
|
|
663
|
+
// Object
|
|
664
|
+
SUBRULE(exports.graphNodePath, triple.object);
|
|
665
|
+
SUBRULE(exports.annotationPath, triple.annotations ?? []);
|
|
666
|
+
// If no more things, or a top level collection (only possible if new block was part), or new subject: add DOT
|
|
667
|
+
if (nextTriple === undefined || F.isTripleCollection(nextTriple) ||
|
|
668
|
+
!F.isSourceLocationNoMaterialize(nextTriple.subject.loc)) {
|
|
669
|
+
F.printFilter(ast, () => {
|
|
670
|
+
PRINT_WORD('.');
|
|
671
|
+
NEW_LINE();
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
else if (F.isSourceLocationNoMaterialize(nextTriple.predicate.loc)) {
|
|
675
|
+
F.printFilter(ast, () => PRINT_WORD(','));
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
F.printFilter(ast, () => {
|
|
679
|
+
PRINT_WORD(';');
|
|
680
|
+
NEW_LINE();
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
}
|
|
572
684
|
});
|
|
573
|
-
} else if (F.isSourceLocationNoMaterialize(nextTriple.predicate.loc)) {
|
|
574
|
-
F.printFilter(ast, () => PRINT_WORD(","));
|
|
575
|
-
} else {
|
|
576
|
-
F.printFilter(ast, () => {
|
|
577
|
-
PRINT_WORD(";");
|
|
578
|
-
NEW_LINE();
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
685
|
}
|
|
582
|
-
|
|
583
|
-
}
|
|
584
|
-
}
|
|
686
|
+
},
|
|
585
687
|
};
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
688
|
+
/**
|
|
689
|
+
* OVERRIDING RULE: {@link S11.graphTerm}.
|
|
690
|
+
* No retyping is needed since the return type is the same
|
|
691
|
+
* [[149]](https://www.w3.org/TR/sparql12-query/#rRDFLiteral)
|
|
692
|
+
*/
|
|
693
|
+
exports.generateGraphTerm = {
|
|
694
|
+
name: 'graphTerm',
|
|
695
|
+
gImpl: $ => (ast, C) => {
|
|
696
|
+
if (C.astFactory.isTermTriple(ast)) {
|
|
697
|
+
$.SUBRULE(exports.tripleTerm, ast);
|
|
698
|
+
}
|
|
699
|
+
else {
|
|
700
|
+
rules_sparql_1_1_1.gram.graphTerm.gImpl($)(ast, C);
|
|
701
|
+
}
|
|
702
|
+
},
|
|
595
703
|
};
|
|
596
|
-
|
|
597
|
-
0 && (module.exports = {
|
|
598
|
-
annotation,
|
|
599
|
-
annotationBlock,
|
|
600
|
-
annotationBlockPath,
|
|
601
|
-
annotationPath,
|
|
602
|
-
buildInHasLang,
|
|
603
|
-
buildInHasLangDir,
|
|
604
|
-
buildInIsTriple,
|
|
605
|
-
buildInLangDir,
|
|
606
|
-
buildInLangStrDir,
|
|
607
|
-
buildInObject,
|
|
608
|
-
buildInPredicate,
|
|
609
|
-
buildInSubject,
|
|
610
|
-
buildInTriple,
|
|
611
|
-
builtInCall,
|
|
612
|
-
dataBlockValue,
|
|
613
|
-
exprTripleTerm,
|
|
614
|
-
exprTripleTermObject,
|
|
615
|
-
exprTripleTermSubject,
|
|
616
|
-
generateGraphTerm,
|
|
617
|
-
generateTriplesBlock,
|
|
618
|
-
graphNode,
|
|
619
|
-
graphNodePath,
|
|
620
|
-
object,
|
|
621
|
-
objectPath,
|
|
622
|
-
primaryExpression,
|
|
623
|
-
prologue,
|
|
624
|
-
rdfLiteral,
|
|
625
|
-
reifiedTriple,
|
|
626
|
-
reifiedTripleBlock,
|
|
627
|
-
reifiedTripleBlockPath,
|
|
628
|
-
reifiedTripleObject,
|
|
629
|
-
reifiedTripleSubject,
|
|
630
|
-
reifier,
|
|
631
|
-
tripleTerm,
|
|
632
|
-
tripleTermData,
|
|
633
|
-
tripleTermDataObject,
|
|
634
|
-
tripleTermDataSubject,
|
|
635
|
-
tripleTermObject,
|
|
636
|
-
tripleTermSubject,
|
|
637
|
-
triplesSameSubject,
|
|
638
|
-
triplesSameSubjectPath,
|
|
639
|
-
unaryExpression,
|
|
640
|
-
varOrReifierId,
|
|
641
|
-
varOrTerm,
|
|
642
|
-
versionDecl,
|
|
643
|
-
versionSpecifier
|
|
644
|
-
});
|
|
704
|
+
//# sourceMappingURL=grammar.js.map
|