@manta-eu/datalog-parser 0.1.4 → 0.1.6
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/dist/index.js +202 -203
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { match as p, P as
|
|
1
|
+
import { match as p, P as u } from "ts-pattern";
|
|
2
2
|
import Ce from "decimal.js";
|
|
3
3
|
import { GeneratorBuilder as Rr, ParserBuilder as F } from "@traqula/core";
|
|
4
4
|
import { sparql11GeneratorBuilder as It } from "@traqula/generator-sparql-1-1";
|
|
5
5
|
import { AstFactory as br, lex as Qe, completeGeneratorContext as Or, gram as n, MinimalSparqlParser as xr, sparqlCodepointEscape as vr } from "@traqula/rules-sparql-1-1";
|
|
6
6
|
import { createToken as c, Lexer as Mt, CstParser as Cr, EOF as Ir } from "chevrotain";
|
|
7
7
|
import { z as j } from "zod";
|
|
8
|
-
const xn = (e) => p(e).with({ type: "triple" }, () => !0).otherwise(() => !1), vn = (e) => p(e).with({ type: "property" }, () => !0).otherwise(() => !1), Cn = (e) => p(e).with({ type: "class" }, () => !0).otherwise(() => !1), In = (e) => p(e).with({ type: "general" }, () => !0).otherwise(() => !1),
|
|
8
|
+
const xn = (e) => p(e).with({ type: "triple" }, () => !0).otherwise(() => !1), vn = (e) => p(e).with({ type: "property" }, () => !0).otherwise(() => !1), Cn = (e) => p(e).with({ type: "class" }, () => !0).otherwise(() => !1), In = (e) => p(e).with({ type: "general" }, () => !0).otherwise(() => !1), C = (e) => p(e).with({ type: "variable" }, () => !0).otherwise(() => !1), Mn = (e) => p(e).with({ type: "iri" }, () => !0).otherwise(() => !1), Z = (e) => p(e).with({ type: "literal" }, () => !0).otherwise(() => !1), Bn = (e) => p(e).with({ type: "blank" }, () => !0).otherwise(() => !1), Fn = (e) => p(e).with({ type: "negation" }, () => !0).otherwise(() => !1), Pn = (e) => p(e).with({ type: "filter" }, () => !0).otherwise(() => !1), kn = (e) => p(e).with({ type: "bind" }, () => !0).otherwise(() => !1), $n = (e) => p(e).with({ type: "aggregate" }, () => !0).otherwise(() => !1), Dn = (e) => p(e).with({ type: "skolem" }, () => !0).otherwise(() => !1), Gn = (e) => p(e).with({ type: "binary" }, () => !0).otherwise(() => !1), _n = (e) => p(e).with({ type: "unary" }, () => !0).otherwise(() => !1), Vn = (e) => p(e).with({ type: "term" }, () => !0).otherwise(() => !1), jn = (e) => p(e).with({ type: "function" }, () => !0).otherwise(() => !1), qn = (e) => p(e).with({ type: "triple" }, () => "triple").with({ type: "property" }, () => "property").with({ type: "class" }, () => "class").with({ type: "general" }, () => "general").exhaustive(), Xn = (e) => p(e).with({ type: "variable" }, () => "variable").with({ type: "iri" }, () => "iri").with({ type: "literal" }, () => "literal").with({ type: "blank" }, () => "blank").exhaustive(), Hn = (e) => p(e).with({ type: "binary" }, () => "binary").with({ type: "unary" }, () => "unary").with({ type: "term" }, () => "term").with({ type: "function" }, () => "function").with({ type: "in" }, () => "in").exhaustive(), Mr = (e) => p(e).with({ type: "triple" }, (t) => [t.subject, t.predicate, t.object].filter(C)).with({ type: "property" }, (t) => [t.subject, t.object].filter(C)).with({ type: "class" }, (t) => [t.instance].filter(C)).with({ type: "general" }, (t) => t.terms.filter(C)).exhaustive(), Br = (e) => {
|
|
9
9
|
const t = Mr(e), r = "graph" in e ? e.graph : void 0;
|
|
10
|
-
return r &&
|
|
11
|
-
}, Qn = (e) => e.function, zn = (e) => p(e).with(
|
|
10
|
+
return r && C(r) ? [...t, r] : t;
|
|
11
|
+
}, Qn = (e) => e.function, zn = (e) => p(e).with(u.union("+", "-", "*", "/", "<", ">", "<=", ">="), () => !0).with(u.union("=", "!=", "||", "&&"), () => !1).exhaustive(), Kn = (e) => p(e).with(u.union("||", "&&", "=", "!=", "<", ">", "<=", ">="), () => !0).with(u.union("+", "-", "*", "/"), () => !1).exhaustive(), ze = '[^\\s<>"{}|^`\\\\]', Fr = new RegExp(`^[a-z][a-z0-9+.-]*:${ze}*$`, "i");
|
|
12
12
|
function Wn(e) {
|
|
13
13
|
return Fr.test(e);
|
|
14
14
|
}
|
|
@@ -28,10 +28,10 @@ function _r(e, t) {
|
|
|
28
28
|
function Vr(e) {
|
|
29
29
|
const t = Nt(e) ? e.match(Dr) : null;
|
|
30
30
|
if (!t) return e;
|
|
31
|
-
const [, r = "", i = "", s = "", o] = t, a = i + s,
|
|
32
|
-
if (a.length +
|
|
33
|
-
const
|
|
34
|
-
return
|
|
31
|
+
const [, r = "", i = "", s = "", o] = t, a = i + s, l = i.length + Number(o ?? 0), g = l <= 0 ? -l : Math.max(0, l - a.length);
|
|
32
|
+
if (a.length + g > Gr) return e;
|
|
33
|
+
const y = _r(a, l), m = y.integer.replace(/^0+(?=\d)/, ""), h = y.fraction.replace(/0+$/, ""), N = h ? `${m}.${h}` : m;
|
|
34
|
+
return N === "0" || r === "+" ? N : `${r}${N}`;
|
|
35
35
|
}
|
|
36
36
|
function Yn(e) {
|
|
37
37
|
if (Pr.test(e)) return e.toLowerCase() === "true";
|
|
@@ -68,7 +68,7 @@ const Rt = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", bt = "http://www.w
|
|
|
68
68
|
">=": "<="
|
|
69
69
|
};
|
|
70
70
|
function Me(e) {
|
|
71
|
-
return p(e).with({ type:
|
|
71
|
+
return p(e).with({ type: u.union("triple", "property", "class", "general") }, () => !0).otherwise(() => !1);
|
|
72
72
|
}
|
|
73
73
|
function M(e) {
|
|
74
74
|
return p(e).with({ type: "binary" }, ({ left: t, right: r }) => M(t) || M(r)).with({ type: "unary" }, ({ operand: t }) => M(t)).with({ type: "term" }, () => !1).with(
|
|
@@ -80,12 +80,12 @@ function M(e) {
|
|
|
80
80
|
).exhaustive();
|
|
81
81
|
}
|
|
82
82
|
function Ot(e) {
|
|
83
|
-
return p(e).with({ type: "skolem" }, () => !0).with({ type:
|
|
83
|
+
return p(e).with({ type: "skolem" }, () => !0).with({ type: u.union("filter", "bind") }, ({ expression: t }) => M(t)).with({ type: "negation" }, ({ formulas: t }) => t.some(Ot)).with(
|
|
84
84
|
{ type: "aggregate" },
|
|
85
85
|
({ atoms: t, bindings: r }) => t.some(Ot) || (r?.some(
|
|
86
86
|
({ expression: i, secondExpression: s }) => i !== "*" && M(i) || s !== void 0 && M(s)
|
|
87
87
|
) ?? !1)
|
|
88
|
-
).with({ type:
|
|
88
|
+
).with({ type: u.union("triple", "property", "class", "general") }, () => !1).exhaustive();
|
|
89
89
|
}
|
|
90
90
|
function We(e) {
|
|
91
91
|
return e.some((t) => t.type !== "negation" && Ot(t));
|
|
@@ -98,7 +98,7 @@ function Ye(e) {
|
|
|
98
98
|
})).with(
|
|
99
99
|
{
|
|
100
100
|
type: "property",
|
|
101
|
-
predicate:
|
|
101
|
+
predicate: u.union("a", "rdf:type", Rt),
|
|
102
102
|
object: { type: "iri" }
|
|
103
103
|
},
|
|
104
104
|
(t) => ({
|
|
@@ -109,7 +109,7 @@ function Ye(e) {
|
|
|
109
109
|
).with(
|
|
110
110
|
{
|
|
111
111
|
type: "triple",
|
|
112
|
-
predicate: { type: "iri", value:
|
|
112
|
+
predicate: { type: "iri", value: u.union("a", "rdf:type", Rt) },
|
|
113
113
|
object: { type: "iri" }
|
|
114
114
|
},
|
|
115
115
|
(t) => ({
|
|
@@ -126,7 +126,7 @@ function Ze(e) {
|
|
|
126
126
|
object: t.object,
|
|
127
127
|
graph: t.graph
|
|
128
128
|
})).with(
|
|
129
|
-
{ type: "triple", predicate: { type: "iri", value:
|
|
129
|
+
{ type: "triple", predicate: { type: "iri", value: u.not(u.union("a", "rdf:type", Rt)) } },
|
|
130
130
|
(t) => ({
|
|
131
131
|
predicate: t.predicate.value,
|
|
132
132
|
subject: t.subject,
|
|
@@ -178,10 +178,10 @@ function is(e) {
|
|
|
178
178
|
}
|
|
179
179
|
function Hr(e) {
|
|
180
180
|
return p(e).with(
|
|
181
|
-
{ type: "binary", operator:
|
|
181
|
+
{ type: "binary", operator: u.union("=", "!=", "<", ">", "<=", ">=") },
|
|
182
182
|
(t) => {
|
|
183
183
|
const r = D(t.left), i = D(t.right);
|
|
184
|
-
return !r || !i ? null :
|
|
184
|
+
return !r || !i ? null : C(r) && Z(i) ? { variableName: r.name, operator: t.operator, literal: i } : Z(r) && C(i) ? {
|
|
185
185
|
variableName: i.name,
|
|
186
186
|
operator: Bt[t.operator],
|
|
187
187
|
literal: r
|
|
@@ -192,14 +192,14 @@ function Hr(e) {
|
|
|
192
192
|
function Qr(e) {
|
|
193
193
|
return p(e).returnType().with(
|
|
194
194
|
{ type: "binary", operator: "=" },
|
|
195
|
-
(t) => p([D(t.left), D(t.right)]).returnType().with([
|
|
195
|
+
(t) => p([D(t.left), D(t.right)]).returnType().with([u.not(u.nullish), { type: "literal" }], ([r, i]) => ({ subject: r, literal: i })).with([{ type: "literal" }, u.not(u.nullish)], ([r, i]) => ({ subject: i, literal: r })).otherwise(() => null)
|
|
196
196
|
).otherwise(() => null);
|
|
197
197
|
}
|
|
198
198
|
function ns(e) {
|
|
199
199
|
if (e.type === "in") {
|
|
200
200
|
const s = D(e.expression), o = e.list.flatMap((a) => {
|
|
201
|
-
const
|
|
202
|
-
return
|
|
201
|
+
const l = Yr(a);
|
|
202
|
+
return l ? [l] : [];
|
|
203
203
|
});
|
|
204
204
|
return s && o.length > 0 && o.length === e.list.length ? { subject: s, literals: o, negated: e.negated } : null;
|
|
205
205
|
}
|
|
@@ -219,7 +219,7 @@ function ns(e) {
|
|
|
219
219
|
}
|
|
220
220
|
function zr(e) {
|
|
221
221
|
const t = D(e);
|
|
222
|
-
return t &&
|
|
222
|
+
return t && C(t) ? t.name : null;
|
|
223
223
|
}
|
|
224
224
|
function Kr(e) {
|
|
225
225
|
return p(e).with({ type: "skolem" }, (t) => {
|
|
@@ -233,11 +233,11 @@ function ss(e) {
|
|
|
233
233
|
}, i = (o) => {
|
|
234
234
|
rt(o).forEach((a) => t.add(a));
|
|
235
235
|
}, s = (o) => {
|
|
236
|
-
p(o).with({ type:
|
|
236
|
+
p(o).with({ type: u.union("triple", "property", "class", "general") }, i).with({ type: "negation" }, (a) => a.formulas.forEach(s)).with({ type: "filter" }, (a) => r(a.expression)).with({ type: "bind" }, (a) => {
|
|
237
237
|
r(a.expression), t.add(a.variable);
|
|
238
238
|
}).with({ type: "aggregate" }, (a) => {
|
|
239
|
-
a.atoms.forEach(s), a.onVars?.forEach((
|
|
240
|
-
t.add(
|
|
239
|
+
a.atoms.forEach(s), a.onVars?.forEach((l) => t.add(l)), a.bindings?.forEach((l) => {
|
|
240
|
+
t.add(l.variable), l.expression !== "*" && r(l.expression), l.secondExpression && r(l.secondExpression);
|
|
241
241
|
});
|
|
242
242
|
}).with({ type: "skolem" }, (a) => a.args.forEach(r)).exhaustive();
|
|
243
243
|
};
|
|
@@ -245,27 +245,27 @@ function ss(e) {
|
|
|
245
245
|
}
|
|
246
246
|
function as(e, t) {
|
|
247
247
|
const r = /* @__PURE__ */ new Set(), i = (a) => {
|
|
248
|
-
a.includes(t) && a.forEach((
|
|
248
|
+
a.includes(t) && a.forEach((l) => r.add(l));
|
|
249
249
|
}, s = (a) => {
|
|
250
250
|
i(rt(a));
|
|
251
251
|
}, o = (a) => {
|
|
252
|
-
p(a).with({ type:
|
|
252
|
+
p(a).with({ type: u.union("triple", "property", "class", "general") }, s).with({ type: "negation" }, (l) => l.formulas.forEach(o)).with({ type: "filter" }, (l) => i(w(l.expression))).with(
|
|
253
253
|
{ type: "bind" },
|
|
254
|
-
(
|
|
255
|
-
).with({ type: "aggregate" }, (
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
...
|
|
259
|
-
...(
|
|
254
|
+
(l) => i([...w(l.expression), l.variable])
|
|
255
|
+
).with({ type: "aggregate" }, (l) => {
|
|
256
|
+
l.atoms.forEach(o);
|
|
257
|
+
const g = [
|
|
258
|
+
...l.onVars ?? [],
|
|
259
|
+
...(l.bindings ?? []).flatMap((y) => [
|
|
260
260
|
y.variable,
|
|
261
261
|
...y.expression === "*" ? [] : w(y.expression),
|
|
262
262
|
...y.secondExpression ? w(y.secondExpression) : []
|
|
263
263
|
])
|
|
264
264
|
];
|
|
265
|
-
i(
|
|
265
|
+
i(g);
|
|
266
266
|
}).with(
|
|
267
267
|
{ type: "skolem" },
|
|
268
|
-
(
|
|
268
|
+
(l) => i(l.args.flatMap((g) => w(g)))
|
|
269
269
|
).exhaustive();
|
|
270
270
|
};
|
|
271
271
|
return e.head.forEach(s), e.body.forEach(o), r;
|
|
@@ -274,7 +274,7 @@ function rt(e) {
|
|
|
274
274
|
return Br(e).map((t) => t.name);
|
|
275
275
|
}
|
|
276
276
|
function Wr(e) {
|
|
277
|
-
return e &&
|
|
277
|
+
return e && C(e) ? [e.name] : [];
|
|
278
278
|
}
|
|
279
279
|
function w(e) {
|
|
280
280
|
return p(e).with({ type: "binary" }, (t) => [
|
|
@@ -298,26 +298,26 @@ function xt(e, t) {
|
|
|
298
298
|
function er(e) {
|
|
299
299
|
return Ke(e) ? `<${e}>` : e;
|
|
300
300
|
}
|
|
301
|
-
function
|
|
301
|
+
function O(e, t = {}) {
|
|
302
302
|
return p(e).with({ type: "variable" }, (r) => `?${r.name}`).with({ type: "iri" }, (r) => r.prefixed ? r.value : `<${r.value}>`).with({ type: "literal" }, (r) => {
|
|
303
303
|
const i = t.stripSimpleLiteralDatatypes && Fe(r) ? r.value : JSON.stringify(r.value);
|
|
304
304
|
return r.language ? `${i}@${r.language}` : r.datatype ? t.stripSimpleLiteralDatatypes && Fe(r) ? i : `${i}^^${er(r.datatype)}` : i;
|
|
305
305
|
}).with({ type: "blank" }, (r) => `_:${r.label}`).exhaustive();
|
|
306
306
|
}
|
|
307
307
|
function os(e, t = {}) {
|
|
308
|
-
const r = "graph" in e && e.graph ? ` ${
|
|
308
|
+
const r = "graph" in e && e.graph ? ` ${O(e.graph, t)}` : "";
|
|
309
309
|
return p(e).with(
|
|
310
310
|
{ type: "property" },
|
|
311
|
-
(i) => `${i.predicate}[${
|
|
311
|
+
(i) => `${i.predicate}[${O(i.subject, t)}, ${O(i.object, t)}]${r}`
|
|
312
312
|
).with(
|
|
313
313
|
{ type: "triple" },
|
|
314
|
-
(i) => `[${
|
|
314
|
+
(i) => `[${O(i.subject, t)}, ${O(i.predicate, t)}, ${O(i.object, t)}]${r}`
|
|
315
315
|
).with(
|
|
316
316
|
{ type: "class" },
|
|
317
|
-
(i) => `${i.className}[${
|
|
317
|
+
(i) => `${i.className}[${O(i.instance, t)}]${r}`
|
|
318
318
|
).with(
|
|
319
319
|
{ type: "general" },
|
|
320
|
-
(i) => `${i.tableName}(${i.terms.map((s) =>
|
|
320
|
+
(i) => `${i.tableName}(${i.terms.map((s) => O(s, t)).join(", ")})`
|
|
321
321
|
).exhaustive();
|
|
322
322
|
}
|
|
323
323
|
function Fe(e) {
|
|
@@ -329,23 +329,23 @@ function ls(e, t = {}) {
|
|
|
329
329
|
function X(e, t = {}) {
|
|
330
330
|
return p(e).with({ type: "binary" }, (r) => [
|
|
331
331
|
...Pe(r.left, r.operator, "left", t),
|
|
332
|
-
|
|
332
|
+
v(` ${r.operator} `),
|
|
333
333
|
...Pe(r.right, r.operator, "right", t)
|
|
334
|
-
]).with({ type: "unary" }, (r) => [
|
|
335
|
-
|
|
334
|
+
]).with({ type: "unary" }, (r) => [v(r.operator), ...ti(r.operand, t)]).with({ type: "term" }, (r) => ei(r.term, t)).with({ type: "function" }, (r) => [
|
|
335
|
+
v(`${r.name}(`),
|
|
336
336
|
...ke(
|
|
337
337
|
r.args.map((i) => X(i, t)),
|
|
338
338
|
", "
|
|
339
339
|
),
|
|
340
|
-
|
|
340
|
+
v(")")
|
|
341
341
|
]).with({ type: "in" }, (r) => [
|
|
342
342
|
...X(r.expression, t),
|
|
343
|
-
|
|
343
|
+
v(` ${r.negated ? "NOT IN" : "IN"} (`),
|
|
344
344
|
...ke(
|
|
345
345
|
r.list.map((i) => X(i, t)),
|
|
346
346
|
", "
|
|
347
347
|
),
|
|
348
|
-
|
|
348
|
+
v(")")
|
|
349
349
|
]).exhaustive();
|
|
350
350
|
}
|
|
351
351
|
function Zr(e, t, r) {
|
|
@@ -365,25 +365,25 @@ function ti(e, t) {
|
|
|
365
365
|
return Jr(e) ? rr(r) : r;
|
|
366
366
|
}
|
|
367
367
|
function ei(e, t) {
|
|
368
|
-
return
|
|
368
|
+
return C(e) ? [ii(e.name)] : Z(e) ? [ni(e, t)] : [v(O(e, t))];
|
|
369
369
|
}
|
|
370
370
|
function rr(e) {
|
|
371
|
-
return [
|
|
371
|
+
return [v("("), ...e, v(")")];
|
|
372
372
|
}
|
|
373
373
|
function ke(e, t) {
|
|
374
|
-
return e.flatMap((r, i) => i === 0 ? r : [
|
|
374
|
+
return e.flatMap((r, i) => i === 0 ? r : [v(t), ...r]);
|
|
375
375
|
}
|
|
376
376
|
function ri(e) {
|
|
377
377
|
return e.map((t) => t.type === "variable" ? `?${t.name}` : t.text).join("");
|
|
378
378
|
}
|
|
379
|
-
function
|
|
379
|
+
function v(e) {
|
|
380
380
|
return { type: "text", text: e };
|
|
381
381
|
}
|
|
382
382
|
function ii(e) {
|
|
383
383
|
return { type: "variable", name: e };
|
|
384
384
|
}
|
|
385
385
|
function ni(e, t) {
|
|
386
|
-
return { type: "literal", literal: e, text:
|
|
386
|
+
return { type: "literal", literal: e, text: O(e, t) };
|
|
387
387
|
}
|
|
388
388
|
function D(e) {
|
|
389
389
|
return e.type === "term" ? e.term : null;
|
|
@@ -396,20 +396,20 @@ function vt(e) {
|
|
|
396
396
|
return p(e).with({ type: "bind" }, ({ groundedTarget: t }) => t !== void 0).with(
|
|
397
397
|
{ type: "aggregate" },
|
|
398
398
|
({ groundedOnTargets: t, bindings: r, atoms: i }) => t !== void 0 || (r?.some((s) => s.groundedTarget !== void 0) ?? !1) || i.some(vt)
|
|
399
|
-
).with({ type: "negation" }, ({ formulas: t }) => t.some(vt)).with({ type:
|
|
399
|
+
).with({ type: "negation" }, ({ formulas: t }) => t.some(vt)).with({ type: u.union("triple", "property", "class", "general", "filter", "skolem") }, () => !1).exhaustive();
|
|
400
400
|
}
|
|
401
|
-
const E = new br(),
|
|
401
|
+
const E = new br(), f = E.gen(), $e = It.getRule("aggregate"), De = It.getRule("expression"), ai = {
|
|
402
402
|
...$e,
|
|
403
403
|
gImpl: (e) => (t, r) => {
|
|
404
404
|
const i = t.secondExpression;
|
|
405
405
|
if (!i)
|
|
406
406
|
return $e.gImpl(e)(t, r);
|
|
407
|
-
const { PRINT_WORD: s, SUBRULE: o } = e, a = t.expression[0],
|
|
408
|
-
if (
|
|
407
|
+
const { PRINT_WORD: s, SUBRULE: o } = e, a = t.expression[0], l = r.astFactory;
|
|
408
|
+
if (l.isWildcard(a))
|
|
409
409
|
throw new Error(`Aggregate ${t.aggregation.toUpperCase()} cannot combine * with a second expression.`);
|
|
410
|
-
|
|
410
|
+
l.printFilter(t, () => {
|
|
411
411
|
s(t.aggregation.toUpperCase(), "("), t.distinct && s("DISTINCT");
|
|
412
|
-
}), o(De, a),
|
|
412
|
+
}), o(De, a), l.printFilter(t, () => s(",")), o(De, i), l.printFilter(t, () => s(")"));
|
|
413
413
|
}
|
|
414
414
|
}, oi = Rr.create(It).patchRule(ai).build(), li = /* @__PURE__ */ new Set(["MIN_ARGMIN", "MAX_ARGMIN", "MIN_ARGMAX", "MAX_ARGMAX"]), ui = new Map(
|
|
415
415
|
Object.entries(Qe.builtIn).filter(([e]) => e !== "BuiltInCalls" && e !== "allBuiltInCalls").filter(([, e]) => e && typeof e == "object" && "LABEL" in e).map(([, e]) => {
|
|
@@ -419,12 +419,12 @@ const E = new br(), g = E.gen(), $e = It.getRule("aggregate"), De = It.getRule("
|
|
|
419
419
|
);
|
|
420
420
|
function $(e) {
|
|
421
421
|
if (e.includes("://") || e.startsWith("urn:") || e.startsWith("mailto:") || e.startsWith("tel:") || e.startsWith("data:"))
|
|
422
|
-
return E.termNamed(
|
|
422
|
+
return E.termNamed(f, e);
|
|
423
423
|
const r = e.indexOf(":");
|
|
424
|
-
return r >= 0 ? E.termNamed(
|
|
424
|
+
return r >= 0 ? E.termNamed(f, e.slice(r + 1), e.slice(0, r)) : E.termNamed(f, e);
|
|
425
425
|
}
|
|
426
426
|
function st(e, t) {
|
|
427
|
-
return E.expressionOperation(e, t,
|
|
427
|
+
return E.expressionOperation(e, t, f);
|
|
428
428
|
}
|
|
429
429
|
function ci(e, t) {
|
|
430
430
|
const { function: r, expression: i, secondExpression: s } = e, o = li.has(r), a = s !== void 0;
|
|
@@ -434,17 +434,17 @@ function ci(e, t) {
|
|
|
434
434
|
throw new Error(`Aggregate ${r} cannot use * as an expression.`);
|
|
435
435
|
if (!o && a)
|
|
436
436
|
throw new Error(`Aggregate ${r} accepts only one expression.`);
|
|
437
|
-
const
|
|
437
|
+
const l = i === "*" ? E.wildcard(f) : b(i, t), g = E.aggregate(
|
|
438
438
|
r.toLowerCase(),
|
|
439
439
|
e.distinct || !1,
|
|
440
|
-
|
|
440
|
+
l,
|
|
441
441
|
void 0,
|
|
442
|
-
|
|
442
|
+
f
|
|
443
443
|
);
|
|
444
444
|
return a ? {
|
|
445
|
-
...
|
|
446
|
-
secondExpression:
|
|
447
|
-
} :
|
|
445
|
+
...g,
|
|
446
|
+
secondExpression: b(s, t)
|
|
447
|
+
} : g;
|
|
448
448
|
}
|
|
449
449
|
function P(e, t, r = void 0) {
|
|
450
450
|
return p(r).with("predicate", () => {
|
|
@@ -456,37 +456,37 @@ function P(e, t, r = void 0) {
|
|
|
456
456
|
}).with("graph", () => {
|
|
457
457
|
if (e.type !== "variable" && e.type !== "iri")
|
|
458
458
|
throw new Error(`Invalid graph name term: ${e.type}. Graph names can only be variables or IRIs.`);
|
|
459
|
-
}).with(
|
|
460
|
-
}).exhaustive(), r === "predicate" && e.type === "iri" && e.value === "a" ? $("rdf:type") : p(e).with({ type: "variable" }, (i) => (t.add(i.name), E.termVariable(i.name,
|
|
461
|
-
{ type: "literal", language:
|
|
462
|
-
(i) => E.termLiteral(
|
|
463
|
-
).with({ type: "literal", datatype:
|
|
459
|
+
}).with(u.nullish, () => {
|
|
460
|
+
}).exhaustive(), r === "predicate" && e.type === "iri" && e.value === "a" ? $("rdf:type") : p(e).with({ type: "variable" }, (i) => (t.add(i.name), E.termVariable(i.name, f))).with({ type: "iri", prefixed: !0 }, (i) => $(i.value)).with({ type: "iri", prefixed: !1 }, (i) => E.termNamed(f, i.value)).with(
|
|
461
|
+
{ type: "literal", language: u.string },
|
|
462
|
+
(i) => E.termLiteral(f, i.value, i.language)
|
|
463
|
+
).with({ type: "literal", datatype: u.string }, (i) => {
|
|
464
464
|
const s = $(i.datatype);
|
|
465
|
-
return E.termLiteral(
|
|
466
|
-
}).with({ type: "literal" }, (i) => E.termLiteral(
|
|
465
|
+
return E.termLiteral(f, i.value, s);
|
|
466
|
+
}).with({ type: "literal" }, (i) => E.termLiteral(f, i.value)).with({ type: "blank" }, (i) => E.termBlank(i.label, f)).exhaustive();
|
|
467
467
|
}
|
|
468
468
|
function pi(e, t) {
|
|
469
|
-
const r = e.args.map((o) =>
|
|
469
|
+
const r = e.args.map((o) => b(o, t)), i = ui.get(e.name.toLowerCase());
|
|
470
470
|
if (i)
|
|
471
471
|
return st(i.toLowerCase(), r);
|
|
472
472
|
const s = $(e.name);
|
|
473
|
-
return E.expressionFunctionCall(s, r, !1,
|
|
473
|
+
return E.expressionFunctionCall(s, r, !1, f);
|
|
474
474
|
}
|
|
475
|
-
function
|
|
475
|
+
function b(e, t) {
|
|
476
476
|
return p(e).with(
|
|
477
477
|
{ type: "binary" },
|
|
478
478
|
(r) => st(r.operator, [
|
|
479
|
-
|
|
480
|
-
|
|
479
|
+
b(r.left, t),
|
|
480
|
+
b(r.right, t)
|
|
481
481
|
])
|
|
482
482
|
).with(
|
|
483
483
|
{ type: "unary" },
|
|
484
|
-
(r) => st(r.operator, [
|
|
484
|
+
(r) => st(r.operator, [b(r.operand, t)])
|
|
485
485
|
).with({ type: "term" }, (r) => P(r.term, t, "expression")).with({ type: "function" }, (r) => pi(r, t)).with(
|
|
486
486
|
{ type: "in" },
|
|
487
487
|
(r) => st(r.negated ? "notin" : "in", [
|
|
488
|
-
|
|
489
|
-
...r.list.map((i) =>
|
|
488
|
+
b(r.expression, t),
|
|
489
|
+
...r.list.map((i) => b(i, t))
|
|
490
490
|
])
|
|
491
491
|
).exhaustive();
|
|
492
492
|
}
|
|
@@ -509,34 +509,34 @@ function Ft(e, t) {
|
|
|
509
509
|
}).exhaustive();
|
|
510
510
|
if (!r) return { triples: [] };
|
|
511
511
|
if ("graph" in e && e.graph) {
|
|
512
|
-
const i = E.patternBgp([r],
|
|
512
|
+
const i = E.patternBgp([r], f);
|
|
513
513
|
return { graph: E.patternGraph(
|
|
514
514
|
P(e.graph, t, "graph"),
|
|
515
515
|
[i],
|
|
516
|
-
|
|
516
|
+
f
|
|
517
517
|
) };
|
|
518
518
|
}
|
|
519
519
|
return { triples: [r] };
|
|
520
520
|
}
|
|
521
521
|
function hi(e, t) {
|
|
522
522
|
return e.formulas.filter((r) => "type" in r).flatMap(
|
|
523
|
-
(r) => p(r).with({ type:
|
|
523
|
+
(r) => p(r).with({ type: u.union("triple", "property", "class") }, (i) => Ft(i, t).triples || []).with({ type: "general" }, () => {
|
|
524
524
|
throw new Error("General formulas are not supported in negation patterns.");
|
|
525
525
|
}).exhaustive()
|
|
526
526
|
);
|
|
527
527
|
}
|
|
528
528
|
function di(e, t) {
|
|
529
529
|
return e.reduce(
|
|
530
|
-
(r, i) => "type" in i ? p(i).with({ type:
|
|
530
|
+
(r, i) => "type" in i ? p(i).with({ type: u.union("triple", "property", "class") }, (s) => {
|
|
531
531
|
const o = Ft(s, t);
|
|
532
532
|
return o.graph ? { ...r, graphPatterns: [...r.graphPatterns, o.graph] } : o.triples ? { ...r, triples: [...r.triples, ...o.triples] } : r;
|
|
533
533
|
}).with({ type: "filter" }, (s) => {
|
|
534
|
-
const o =
|
|
534
|
+
const o = b(s.expression, t), a = E.patternFilter(o, f);
|
|
535
535
|
return { ...r, filters: [...r.filters, a] };
|
|
536
536
|
}).with({ type: "bind" }, (s) => {
|
|
537
537
|
t.add(s.variable);
|
|
538
|
-
const o =
|
|
539
|
-
return { ...r, binds: [...r.binds,
|
|
538
|
+
const o = b(s.expression, t), a = E.termVariable(s.variable, f), l = E.patternBind(o, a, f);
|
|
539
|
+
return { ...r, binds: [...r.binds, l] };
|
|
540
540
|
}).with({ type: "general" }, () => {
|
|
541
541
|
throw new Error("General formulas are not supported in atom processing.");
|
|
542
542
|
}).exhaustive() : r,
|
|
@@ -544,7 +544,7 @@ function di(e, t) {
|
|
|
544
544
|
);
|
|
545
545
|
}
|
|
546
546
|
function Ei(e, t) {
|
|
547
|
-
const { triples: r, filters: i, binds: s, graphPatterns: o } = di(e.atoms, t), a = e.onVars || [],
|
|
547
|
+
const { triples: r, filters: i, binds: s, graphPatterns: o } = di(e.atoms, t), a = e.onVars || [], l = a.map((m) => (t.add(m), E.termVariable(m, f))), g = [], y = [];
|
|
548
548
|
return e.bindings?.forEach((m) => {
|
|
549
549
|
if (t.add(m.variable), m.expression === void 0) {
|
|
550
550
|
const k = m.function !== void 0 ? `Aggregate ${m.function}` : "Expression-only aggregate binding";
|
|
@@ -552,35 +552,35 @@ function Ei(e, t) {
|
|
|
552
552
|
}
|
|
553
553
|
if (m.function === void 0 && m.secondExpression !== void 0)
|
|
554
554
|
throw new Error("Expression-only aggregate bindings cannot have a second expression.");
|
|
555
|
-
const h = m.function !== void 0,
|
|
556
|
-
h ?
|
|
555
|
+
const h = m.function !== void 0, N = h ? ci(m, t) : b(m.expression, t), T = E.termVariable(m.variable, f), A = E.patternBind(N, T, f);
|
|
556
|
+
h ? g.push(A) : y.push(A);
|
|
557
557
|
}), {
|
|
558
558
|
triples: r,
|
|
559
559
|
filters: i,
|
|
560
560
|
binds: [...s, ...y],
|
|
561
561
|
graphPatterns: o,
|
|
562
|
-
selectVars: [...
|
|
562
|
+
selectVars: [...l, ...g],
|
|
563
563
|
groupBy: a
|
|
564
564
|
};
|
|
565
565
|
}
|
|
566
566
|
function fi(e, t) {
|
|
567
567
|
ir(e);
|
|
568
568
|
const r = /* @__PURE__ */ new Set(), i = e.reduce(
|
|
569
|
-
(h,
|
|
569
|
+
(h, N) => p(N).with({ type: u.union("triple", "property", "class", "general") }, (T) => {
|
|
570
570
|
const A = Ft(T, r);
|
|
571
571
|
return A.graph ? { ...h, graphPatterns: [...h.graphPatterns, A.graph] } : A.triples ? { ...h, triples: [...h.triples, ...A.triples] } : h;
|
|
572
572
|
}).with({ type: "filter" }, (T) => {
|
|
573
|
-
const A =
|
|
573
|
+
const A = b(T.expression, r), k = E.patternFilter(A, f);
|
|
574
574
|
return { ...h, filters: [...h.filters, k] };
|
|
575
575
|
}).with({ type: "bind" }, (T) => {
|
|
576
|
-
const A =
|
|
576
|
+
const A = b(T.expression, r);
|
|
577
577
|
r.add(T.variable);
|
|
578
|
-
const k = E.termVariable(T.variable,
|
|
578
|
+
const k = E.termVariable(T.variable, f), At = E.patternBind(A, k, f);
|
|
579
579
|
return { ...h, binds: [...h.binds, At] };
|
|
580
580
|
}).with({ type: "negation" }, (T) => {
|
|
581
581
|
const A = hi(T, r);
|
|
582
582
|
if (A.length > 0) {
|
|
583
|
-
const k = E.patternBgp(A,
|
|
583
|
+
const k = E.patternBgp(A, f), At = E.patternGroup([k], f), Sr = E.expressionPatternOperation("notexists", At, f), Nr = E.patternFilter(Sr, f);
|
|
584
584
|
return { ...h, filters: [...h.filters, Nr] };
|
|
585
585
|
}
|
|
586
586
|
return h;
|
|
@@ -606,36 +606,36 @@ function fi(e, t) {
|
|
|
606
606
|
aggregateSelectVars: []
|
|
607
607
|
}
|
|
608
608
|
), s = [
|
|
609
|
-
...i.triples.length > 0 ? [E.patternBgp(i.triples,
|
|
609
|
+
...i.triples.length > 0 ? [E.patternBgp(i.triples, f)] : [],
|
|
610
610
|
...i.graphPatterns,
|
|
611
611
|
...i.filters,
|
|
612
612
|
...i.binds
|
|
613
|
-
], o = i.aggregateSelectVars.length > 0 ? i.aggregateSelectVars : r.size > 0 ? Array.from(r).map((h) => E.termVariable(h,
|
|
613
|
+
], o = i.aggregateSelectVars.length > 0 ? i.aggregateSelectVars : r.size > 0 ? Array.from(r).map((h) => E.termVariable(h, f)) : [E.wildcard(f)], a = i.groupByVars.length > 0 ? {
|
|
614
614
|
group: E.solutionModifierGroup(
|
|
615
|
-
i.groupByVars.map((h) => E.termVariable(h,
|
|
616
|
-
|
|
615
|
+
i.groupByVars.map((h) => E.termVariable(h, f)),
|
|
616
|
+
f
|
|
617
617
|
)
|
|
618
|
-
} : {},
|
|
619
|
-
const T = E.termNamed(
|
|
620
|
-
return E.contextDefinitionPrefix(
|
|
621
|
-
}) : [],
|
|
618
|
+
} : {}, l = t ? Object.entries(t).map(([h, N]) => {
|
|
619
|
+
const T = E.termNamed(f, N);
|
|
620
|
+
return E.contextDefinitionPrefix(f, h, T);
|
|
621
|
+
}) : [], g = E.querySelect(
|
|
622
622
|
{
|
|
623
|
-
context:
|
|
623
|
+
context: l,
|
|
624
624
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-ts-comment
|
|
625
625
|
variables: o,
|
|
626
626
|
// @ts-ignore - Fails in CI for some reason
|
|
627
|
-
where: E.patternGroup(s,
|
|
628
|
-
datasets: E.datasetClauses([],
|
|
627
|
+
where: E.patternGroup(s, f),
|
|
628
|
+
datasets: E.datasetClauses([], f),
|
|
629
629
|
solutionModifiers: a
|
|
630
630
|
},
|
|
631
|
-
|
|
632
|
-
), y = oi.queryOrUpdate(
|
|
631
|
+
f
|
|
632
|
+
), y = oi.queryOrUpdate(g, Or({ indentInc: 2 })).trim(), m = i.aggregateSelectVars.length > 0 ? i.aggregateSelectVars.map((h) => "value" in h && typeof h.value == "string" ? h.value : "variable" in h && h.variable && "value" in h.variable ? h.variable.value : null).filter((h) => h !== null) : Array.from(r);
|
|
633
633
|
return {
|
|
634
634
|
query: y,
|
|
635
635
|
variables: m
|
|
636
636
|
};
|
|
637
637
|
}
|
|
638
|
-
const Pt = c({ name: "RULE_ARROW", pattern: /:-/ }), at = c({ name: "NOT", pattern: /NOT/ }), kt = c({ name: "EXISTS", pattern: /EXISTS?/ }), W = c({ name: "IN", pattern: /IN/ }), $t = c({ name: "FILTER", pattern: /FILTER/ }), Q = c({ name: "BIND", pattern: /BIND/ }), z = c({ name: "AS", pattern: /AS/ }), Lt = c({ name: "AGGREGATE", pattern: /AGGREGATE/ }), Ut = c({ name: "ON", pattern: /ON/ }), Dt = c({ name: "COUNT", pattern: /COUNT/ }), Gt = c({ name: "MIN", pattern: /MIN/ }), _t = c({ name: "MAX", pattern: /MAX/ }), Vt = c({ name: "SUM", pattern: /SUM/ }), jt = c({ name: "MUL", pattern: /MUL/ }), qt = c({ name: "AVG", pattern: /AVG/ }), Xt = c({ name: "COUNT_MIN", pattern: /COUNT_MIN/ }), Ht = c({ name: "COUNT_MAX", pattern: /COUNT_MAX/ }), Qt = c({ name: "MIN_ARGMIN", pattern: /MIN_ARGMIN/ }), zt = c({ name: "MAX_ARGMIN", pattern: /MAX_ARGMIN/ }), Kt = c({ name: "MIN_ARGMAX", pattern: /MIN_ARGMAX/ }), Wt = c({ name: "MAX_ARGMAX", pattern: /MAX_ARGMAX/ }), ot = c({ name: "DISTINCT", pattern: /DISTINCT/ }), Yt = c({ name: "CONCAT", pattern: /CONCAT/ }), Zt = c({ name: "STR", pattern: /STR/ }), Jt = c({ name: "IF", pattern: /IF/ }), te = c({ name: "IRI", pattern: /IRI/ }), lt = c({ name: "SKOLEM", pattern: /SKOLEM/ }), ee = c({ name: "ROUND", pattern: /ROUND/ }), re = c({ name: "REGEX", pattern: /REGEX/ }), ie = c({ name: "TRUE", pattern: /true/ }), ne = c({ name: "FALSE", pattern: /false/ }), se = c({ name: "EQUALS", pattern: /=/ }), ae = c({ name: "NOT_EQUALS", pattern: /!=/ }), oe = c({ name: "LESS_THAN", pattern: /</ }), le = c({ name: "LESS_THAN_OR_EQUAL", pattern: /<=/ }), ue = c({ name: "GREATER_THAN", pattern: />/ }), ce = c({ name: "GREATER_THAN_OR_EQUAL", pattern: />=/ }), pe = c({ name: "AND", pattern: /&&/ }), he = c({ name: "OR", pattern: /\|\|/ }), ut = c({ name: "PLUS", pattern: /\+/ }), ct = c({ name: "MINUS", pattern: /-/ }), pt = c({ name: "STAR", pattern: /\*/ }), de = c({ name: "SLASH", pattern: /\// }), Ee = c({ name: "EXCLAMATION", pattern: /!/ }), fe = c({ name: "DOT", pattern: /\./ }), S = c({ name: "COMMA", pattern: /,/ }), L = c({ name: "LPAREN", pattern: /\(/ }), U = c({ name: "RPAREN", pattern: /\)/ }), ht = c({ name: "LBRACKET", pattern: /\[/ }), dt = c({ name: "RBRACKET", pattern: /\]/ }), nr = c({ name: "AT", pattern: /@/ }), Et = c({ name: "HAT", pattern: /\^/ }), sr = c({ name: "COLON", pattern: /:/ }),
|
|
638
|
+
const Pt = c({ name: "RULE_ARROW", pattern: /:-/ }), at = c({ name: "NOT", pattern: /NOT/ }), kt = c({ name: "EXISTS", pattern: /EXISTS?/ }), W = c({ name: "IN", pattern: /IN/ }), $t = c({ name: "FILTER", pattern: /FILTER/ }), Q = c({ name: "BIND", pattern: /BIND/ }), z = c({ name: "AS", pattern: /AS/ }), Lt = c({ name: "AGGREGATE", pattern: /AGGREGATE/ }), Ut = c({ name: "ON", pattern: /ON/ }), Dt = c({ name: "COUNT", pattern: /COUNT/ }), Gt = c({ name: "MIN", pattern: /MIN/ }), _t = c({ name: "MAX", pattern: /MAX/ }), Vt = c({ name: "SUM", pattern: /SUM/ }), jt = c({ name: "MUL", pattern: /MUL/ }), qt = c({ name: "AVG", pattern: /AVG/ }), Xt = c({ name: "COUNT_MIN", pattern: /COUNT_MIN/ }), Ht = c({ name: "COUNT_MAX", pattern: /COUNT_MAX/ }), Qt = c({ name: "MIN_ARGMIN", pattern: /MIN_ARGMIN/ }), zt = c({ name: "MAX_ARGMIN", pattern: /MAX_ARGMIN/ }), Kt = c({ name: "MIN_ARGMAX", pattern: /MIN_ARGMAX/ }), Wt = c({ name: "MAX_ARGMAX", pattern: /MAX_ARGMAX/ }), ot = c({ name: "DISTINCT", pattern: /DISTINCT/ }), Yt = c({ name: "CONCAT", pattern: /CONCAT/ }), Zt = c({ name: "STR", pattern: /STR/ }), Jt = c({ name: "IF", pattern: /IF/ }), te = c({ name: "IRI", pattern: /IRI/ }), lt = c({ name: "SKOLEM", pattern: /SKOLEM/ }), ee = c({ name: "ROUND", pattern: /ROUND/ }), re = c({ name: "REGEX", pattern: /REGEX/ }), ie = c({ name: "TRUE", pattern: /true/ }), ne = c({ name: "FALSE", pattern: /false/ }), se = c({ name: "EQUALS", pattern: /=/ }), ae = c({ name: "NOT_EQUALS", pattern: /!=/ }), oe = c({ name: "LESS_THAN", pattern: /</ }), le = c({ name: "LESS_THAN_OR_EQUAL", pattern: /<=/ }), ue = c({ name: "GREATER_THAN", pattern: />/ }), ce = c({ name: "GREATER_THAN_OR_EQUAL", pattern: />=/ }), pe = c({ name: "AND", pattern: /&&/ }), he = c({ name: "OR", pattern: /\|\|/ }), ut = c({ name: "PLUS", pattern: /\+/ }), ct = c({ name: "MINUS", pattern: /-/ }), pt = c({ name: "STAR", pattern: /\*/ }), de = c({ name: "SLASH", pattern: /\// }), Ee = c({ name: "EXCLAMATION", pattern: /!/ }), fe = c({ name: "DOT", pattern: /\./ }), S = c({ name: "COMMA", pattern: /,/ }), L = c({ name: "LPAREN", pattern: /\(/ }), U = c({ name: "RPAREN", pattern: /\)/ }), ht = c({ name: "LBRACKET", pattern: /\[/ }), dt = c({ name: "RBRACKET", pattern: /\]/ }), nr = c({ name: "AT", pattern: /@/ }), Et = c({ name: "HAT", pattern: /\^/ }), sr = c({ name: "COLON", pattern: /:/ }), R = c({ name: "VARIABLE", pattern: /\?[a-zA-Z_][a-zA-Z0-9_]*/ }), ge = c({ name: "IRI_REF", pattern: new RegExp(`<${ze}*>`) }), me = c({ name: "INTERNAL_FUNCTION", pattern: /<internal:[^>]+>/ }), J = c({ name: "BLANK_NODE", pattern: /_:[\w](?:[\w.-]*[\w-])?/ }), ye = "%[0-9a-fA-F]{2}|\\\\[-_~.!$&'()*+,;=/?#@%]", gi = `(?:[\\w:]|${ye})`, mi = `(?:[\\w:.-]|${ye})`, yi = `(?:[\\w:-]|${ye})`, ar = `${gi}(?:${mi}*${yi})?`, it = c({
|
|
639
639
|
name: "PREFIXED_NAME",
|
|
640
640
|
pattern: new RegExp(`[a-zA-Z_][\\w]*:${ar}`)
|
|
641
641
|
}), wt = c({ name: "PREFIX_ONLY", pattern: /[a-zA-Z_][\w]*:/ }), Le = c({
|
|
@@ -713,7 +713,7 @@ const Pt = c({ name: "RULE_ARROW", pattern: /:-/ }), at = c({ name: "NOT", patte
|
|
|
713
713
|
Ue,
|
|
714
714
|
Se,
|
|
715
715
|
// Identifiers and names
|
|
716
|
-
|
|
716
|
+
R,
|
|
717
717
|
me,
|
|
718
718
|
ge,
|
|
719
719
|
J,
|
|
@@ -773,7 +773,7 @@ const Pt = c({ name: "RULE_ARROW", pattern: /:-/ }), at = c({ name: "NOT", patte
|
|
|
773
773
|
pt,
|
|
774
774
|
de,
|
|
775
775
|
Ee
|
|
776
|
-
]), hs = /* @__PURE__ */ new Set([fe, S, L, U, ht, dt, nr, Et, sr]), ds = /* @__PURE__ */ new Set([
|
|
776
|
+
]), hs = /* @__PURE__ */ new Set([fe, S, L, U, ht, dt, nr, Et, sr]), ds = /* @__PURE__ */ new Set([R, J, Se, tt]);
|
|
777
777
|
for (const e of [...wi, ...Ai, ...Ti])
|
|
778
778
|
e.LONGER_ALT = [it, wt, tt];
|
|
779
779
|
let Ni;
|
|
@@ -815,19 +815,19 @@ function be(e, t) {
|
|
|
815
815
|
i++;
|
|
816
816
|
continue;
|
|
817
817
|
}
|
|
818
|
-
const o = s === "u" ? 4 : 8, a = o + 2,
|
|
819
|
-
if (
|
|
818
|
+
const o = s === "u" ? 4 : 8, a = o + 2, l = r.image.slice(i, i + a), g = r.image.slice(i + 2, i + a), y = r.startOffset + i;
|
|
819
|
+
if (g.length !== o || !/^[0-9a-fA-F]+$/.test(g))
|
|
820
820
|
return Y(
|
|
821
821
|
e,
|
|
822
822
|
y,
|
|
823
|
-
|
|
823
|
+
l.length,
|
|
824
824
|
`Unicode escape \\${s} must contain ${o} hexadecimal digits`
|
|
825
825
|
);
|
|
826
|
-
const m = Number.parseInt(
|
|
826
|
+
const m = Number.parseInt(g, 16);
|
|
827
827
|
if (m >= 55296 && m <= 57343)
|
|
828
|
-
return Y(e, y, a, `Unicode escape ${
|
|
828
|
+
return Y(e, y, a, `Unicode escape ${l} denotes a surrogate code point`);
|
|
829
829
|
if (m > 1114111)
|
|
830
|
-
return Y(e, y, a, `Unicode escape ${
|
|
830
|
+
return Y(e, y, a, `Unicode escape ${l} is outside the Unicode range`);
|
|
831
831
|
i += a - 1;
|
|
832
832
|
}
|
|
833
833
|
}
|
|
@@ -881,7 +881,7 @@ class Oe extends Cr {
|
|
|
881
881
|
});
|
|
882
882
|
// Graph name for named graph atoms - can be IRI or Variable
|
|
883
883
|
graphName = this.RULE("graphName", () => {
|
|
884
|
-
this.OR([{ ALT: () => this.CONSUME(
|
|
884
|
+
this.OR([{ ALT: () => this.CONSUME(R) }, { ALT: () => this.SUBRULE(this.iri) }]);
|
|
885
885
|
});
|
|
886
886
|
// DefaultGraphAtom := TripleAtom | PropertyAtom | ClassAtom
|
|
887
887
|
defaultGraphAtom = this.RULE("defaultGraphAtom", () => {
|
|
@@ -911,7 +911,7 @@ class Oe extends Cr {
|
|
|
911
911
|
// Term := Variable | IRI | Literal | BlankNode
|
|
912
912
|
term = this.RULE("term", () => {
|
|
913
913
|
this.OR([
|
|
914
|
-
{ ALT: () => this.CONSUME(
|
|
914
|
+
{ ALT: () => this.CONSUME(R) },
|
|
915
915
|
{ ALT: () => this.SUBRULE(this.iri) },
|
|
916
916
|
{ ALT: () => this.SUBRULE(this.literal) },
|
|
917
917
|
{ ALT: () => this.CONSUME(J) }
|
|
@@ -947,10 +947,7 @@ class Oe extends Cr {
|
|
|
947
947
|
this.OR([{ ALT: () => this.CONSUME(ie) }, { ALT: () => this.CONSUME(ne) }]);
|
|
948
948
|
});
|
|
949
949
|
stringLiteral = this.RULE("stringLiteral", () => {
|
|
950
|
-
this.OR([
|
|
951
|
-
{ ALT: () => this.CONSUME(Te) },
|
|
952
|
-
{ ALT: () => this.CONSUME(ft) }
|
|
953
|
-
]), this.OPTION(() => {
|
|
950
|
+
this.OR([{ ALT: () => this.CONSUME(Te) }, { ALT: () => this.CONSUME(ft) }]), this.OPTION(() => {
|
|
954
951
|
this.OR2([
|
|
955
952
|
{ ALT: () => this.CONSUME(Se) },
|
|
956
953
|
{
|
|
@@ -976,8 +973,8 @@ class Oe extends Cr {
|
|
|
976
973
|
});
|
|
977
974
|
// ExistsClause := 'EXISTS' variable (',' variable)* 'IN'
|
|
978
975
|
existsClause = this.RULE("existsClause", () => {
|
|
979
|
-
this.CONSUME(kt), this.CONSUME(
|
|
980
|
-
this.CONSUME(S), this.CONSUME2(
|
|
976
|
+
this.CONSUME(kt), this.CONSUME(R), this.MANY(() => {
|
|
977
|
+
this.CONSUME(S), this.CONSUME2(R);
|
|
981
978
|
}), this.CONSUME(W);
|
|
982
979
|
});
|
|
983
980
|
// AtomList := Atom (',' Atom)*
|
|
@@ -1006,7 +1003,7 @@ class Oe extends Cr {
|
|
|
1006
1003
|
});
|
|
1007
1004
|
// BindAtom := 'BIND' '(' Expression 'AS' variable ')'
|
|
1008
1005
|
bindAtom = this.RULE("bindAtom", () => {
|
|
1009
|
-
this.CONSUME(Q), this.CONSUME(L), this.SUBRULE(this.expression), this.CONSUME(z), this.CONSUME(
|
|
1006
|
+
this.CONSUME(Q), this.CONSUME(L), this.SUBRULE(this.expression), this.CONSUME(z), this.CONSUME(R), this.CONSUME(U);
|
|
1010
1007
|
});
|
|
1011
1008
|
// SkolemAtom := 'SKOLEM' '(' ArgumentList ')'
|
|
1012
1009
|
skolemAtom = this.RULE("skolemAtom", () => {
|
|
@@ -1022,15 +1019,15 @@ class Oe extends Cr {
|
|
|
1022
1019
|
});
|
|
1023
1020
|
// OnClause := 'ON' variable+
|
|
1024
1021
|
onClause = this.RULE("onClause", () => {
|
|
1025
|
-
this.CONSUME(Ut), this.CONSUME(
|
|
1026
|
-
this.CONSUME2(
|
|
1022
|
+
this.CONSUME(Ut), this.CONSUME(R), this.MANY(() => {
|
|
1023
|
+
this.CONSUME2(R);
|
|
1027
1024
|
});
|
|
1028
1025
|
});
|
|
1029
1026
|
// AggregateBind := ('BIND' AggregateFunction | AggregateFunction) 'AS' variable
|
|
1030
1027
|
aggregateBind = this.RULE("aggregateBind", () => {
|
|
1031
1028
|
this.OPTION(() => {
|
|
1032
1029
|
this.CONSUME(Q);
|
|
1033
|
-
}), this.SUBRULE(this.aggregateFunction), this.CONSUME(z), this.CONSUME(
|
|
1030
|
+
}), this.SUBRULE(this.aggregateFunction), this.CONSUME(z), this.CONSUME(R);
|
|
1034
1031
|
});
|
|
1035
1032
|
// AggregateFunction := AggregateFunction1 | AggregateFunction2
|
|
1036
1033
|
aggregateFunction = this.RULE("aggregateFunction", () => {
|
|
@@ -1039,7 +1036,8 @@ class Oe extends Cr {
|
|
|
1039
1036
|
{ ALT: () => this.SUBRULE(this.aggregateFunction2) }
|
|
1040
1037
|
]);
|
|
1041
1038
|
});
|
|
1042
|
-
// AggregateFunction1 := (SUM | MUL | AVG | MIN | COUNT_MIN | MAX | COUNT_MAX | COUNT)
|
|
1039
|
+
// AggregateFunction1 := (SUM | MUL | AVG | MIN | COUNT_MIN | MAX | COUNT_MAX | COUNT)
|
|
1040
|
+
// '(' DISTINCT? (STAR | Expression) ')'
|
|
1043
1041
|
aggregateFunction1 = this.RULE("aggregateFunction1", () => {
|
|
1044
1042
|
this.OR([
|
|
1045
1043
|
{ ALT: () => this.CONSUME(Xt) },
|
|
@@ -1054,7 +1052,8 @@ class Oe extends Cr {
|
|
|
1054
1052
|
this.CONSUME(ot);
|
|
1055
1053
|
}), this.OR2([{ ALT: () => this.CONSUME(pt) }, { ALT: () => this.SUBRULE(this.expression) }]), this.CONSUME(U);
|
|
1056
1054
|
});
|
|
1057
|
-
// AggregateFunction2 := (MIN_ARGMIN | MAX_ARGMIN | MIN_ARGMAX | MAX_ARGMAX)
|
|
1055
|
+
// AggregateFunction2 := (MIN_ARGMIN | MAX_ARGMIN | MIN_ARGMAX | MAX_ARGMAX)
|
|
1056
|
+
// '(' DISTINCT? Expression ',' Expression ')'
|
|
1058
1057
|
aggregateFunction2 = this.RULE("aggregateFunction2", () => {
|
|
1059
1058
|
this.OR([
|
|
1060
1059
|
{ ALT: () => this.CONSUME(Qt) },
|
|
@@ -1196,7 +1195,7 @@ class Oe extends Cr {
|
|
|
1196
1195
|
},
|
|
1197
1196
|
{ ALT: () => this.SUBRULE(this.functionCall) },
|
|
1198
1197
|
{ ALT: () => this.SUBRULE(this.literal) },
|
|
1199
|
-
{ ALT: () => this.CONSUME(
|
|
1198
|
+
{ ALT: () => this.CONSUME(R) },
|
|
1200
1199
|
{ ALT: () => this.SUBRULE(this.iri) }
|
|
1201
1200
|
]);
|
|
1202
1201
|
});
|
|
@@ -1247,7 +1246,7 @@ class bi extends Oe {
|
|
|
1247
1246
|
});
|
|
1248
1247
|
// Each rule below records this once, so the default occurrence index is unambiguous.
|
|
1249
1248
|
variableOrGroundedTarget() {
|
|
1250
|
-
this.OR([{ ALT: () => this.CONSUME(
|
|
1249
|
+
this.OR([{ ALT: () => this.CONSUME(R) }, { ALT: () => this.SUBRULE(this.groundedAsTarget) }]);
|
|
1251
1250
|
}
|
|
1252
1251
|
// OnClause := 'ON' (variable | GroundedAsTarget)*
|
|
1253
1252
|
// Grounding substitutes the grouping variables as well, and an aggregate
|
|
@@ -1290,7 +1289,7 @@ class bi extends Oe {
|
|
|
1290
1289
|
},
|
|
1291
1290
|
{ ALT: () => this.SUBRULE(this.functionCall) },
|
|
1292
1291
|
{ ALT: () => this.SUBRULE(this.literal) },
|
|
1293
|
-
{ ALT: () => this.CONSUME(
|
|
1292
|
+
{ ALT: () => this.CONSUME(R) },
|
|
1294
1293
|
{ ALT: () => this.CONSUME(J) },
|
|
1295
1294
|
{ ALT: () => this.SUBRULE(this.iri) }
|
|
1296
1295
|
]);
|
|
@@ -1306,13 +1305,13 @@ function vi(e) {
|
|
|
1306
1305
|
function Ci(e) {
|
|
1307
1306
|
ir(e.body);
|
|
1308
1307
|
const t = e.body.filter((s) => s.type !== "negation"), r = We(e.body) ? t.filter(
|
|
1309
|
-
(s) => p(s).with({ type:
|
|
1308
|
+
(s) => p(s).with({ type: u.union("triple", "property", "class") }, () => !0).otherwise(() => !1)
|
|
1310
1309
|
) : t, { query: i } = fi(r);
|
|
1311
1310
|
return `${i}
|
|
1312
1311
|
LIMIT 1`;
|
|
1313
1312
|
}
|
|
1314
1313
|
function fs(e) {
|
|
1315
|
-
return p(e).with({ type: "variable" }, (t) => `?${t.name}`).with({ type: "iri", value: "a" }, () => "rdf:type").with({ type: "iri", prefixed: !0 }, (t) => t.value).with({ type: "iri", prefixed: !1 }, (t) => `<${t.value}>`).with({ type: "literal", language:
|
|
1314
|
+
return p(e).with({ type: "variable" }, (t) => `?${t.name}`).with({ type: "iri", value: "a" }, () => "rdf:type").with({ type: "iri", prefixed: !0 }, (t) => t.value).with({ type: "iri", prefixed: !1 }, (t) => `<${t.value}>`).with({ type: "literal", language: u.string }, (t) => `"${t.value}"@${t.language}`).with({ type: "literal", datatype: u.string }, (t) => `"${t.value}"^^${er(t.datatype)}`).with({ type: "literal" }, (t) => `"${t.value}"`).with({ type: "blank" }, (t) => `_:${t.label}`).exhaustive();
|
|
1316
1315
|
}
|
|
1317
1316
|
function Ii(e) {
|
|
1318
1317
|
const t = e.head[0];
|
|
@@ -1331,7 +1330,7 @@ function Ii(e) {
|
|
|
1331
1330
|
})).with({ type: "general" }, () => null).exhaustive() : null;
|
|
1332
1331
|
}
|
|
1333
1332
|
function G(e) {
|
|
1334
|
-
return p(e).with({ type: "variable" }, (t) => `:test_${t.name}`).with({ type: "iri", prefixed: !0 }, (t) => t.value).with({ type: "iri", prefixed: !1 }, (t) => `<${t.value}>`).with({ type: "literal", datatype:
|
|
1333
|
+
return p(e).with({ type: "variable" }, (t) => `:test_${t.name}`).with({ type: "iri", prefixed: !0 }, (t) => t.value).with({ type: "iri", prefixed: !1 }, (t) => `<${t.value}>`).with({ type: "literal", datatype: u.string }, (t) => `"${t.value}"^^${t.datatype}`).with({ type: "literal" }, (t) => `"${t.value}"`).with({ type: "blank" }, (t) => `_:${t.label}`).exhaustive();
|
|
1335
1334
|
}
|
|
1336
1335
|
const Mi = j.object({
|
|
1337
1336
|
results: j.object({
|
|
@@ -1353,13 +1352,13 @@ async function gs(e, t, r, i, s) {
|
|
|
1353
1352
|
verified: !1,
|
|
1354
1353
|
error: "Could not generate test triple from rule head"
|
|
1355
1354
|
};
|
|
1356
|
-
const
|
|
1357
|
-
if (
|
|
1355
|
+
const l = Ci(e), g = await Fi(l, t, r, i);
|
|
1356
|
+
if (g)
|
|
1358
1357
|
return {
|
|
1359
1358
|
verified: !1,
|
|
1360
1359
|
testTriple: a,
|
|
1361
|
-
candidateQuery:
|
|
1362
|
-
error:
|
|
1360
|
+
candidateQuery: l,
|
|
1361
|
+
error: g
|
|
1363
1362
|
};
|
|
1364
1363
|
const y = Pi(a), m = new URL(`datastores/${r}/sparql`, t), h = await fetch(m.toString(), {
|
|
1365
1364
|
method: "POST",
|
|
@@ -1376,7 +1375,7 @@ async function gs(e, t, r, i, s) {
|
|
|
1376
1375
|
verified: Bi.parse(await h.json()).boolean,
|
|
1377
1376
|
testTriple: a,
|
|
1378
1377
|
sparqlQuery: y,
|
|
1379
|
-
candidateQuery:
|
|
1378
|
+
candidateQuery: l
|
|
1380
1379
|
};
|
|
1381
1380
|
} catch (a) {
|
|
1382
1381
|
return {
|
|
@@ -1398,13 +1397,13 @@ async function Fi(e, t, r, i) {
|
|
|
1398
1397
|
body: e
|
|
1399
1398
|
});
|
|
1400
1399
|
if (!o.ok) {
|
|
1401
|
-
let
|
|
1400
|
+
let l = "";
|
|
1402
1401
|
try {
|
|
1403
|
-
|
|
1402
|
+
l = await o.text();
|
|
1404
1403
|
} catch {
|
|
1405
1404
|
}
|
|
1406
|
-
const
|
|
1407
|
-
return `Candidate query failed: ${o.status}${
|
|
1405
|
+
const g = l || o.statusText;
|
|
1406
|
+
return `Candidate query failed: ${o.status}${g ? ` - ${g}` : ""}`;
|
|
1408
1407
|
}
|
|
1409
1408
|
return Mi.parse(await o.json()).results.bindings.length > 0 ? void 0 : "No candidate variable bindings found for rule body - rule cannot fire";
|
|
1410
1409
|
} catch (s) {
|
|
@@ -1422,7 +1421,7 @@ function Pi(e) {
|
|
|
1422
1421
|
`.trim();
|
|
1423
1422
|
}
|
|
1424
1423
|
function ms(e) {
|
|
1425
|
-
return p(e).with({ verified: !0 }, () => "Inference verification succeeded").with({ error:
|
|
1424
|
+
return p(e).with({ verified: !0 }, () => "Inference verification succeeded").with({ error: u.string }, (t) => t.error).with({ testTriple: u.nullish }, () => "Could not determine what triple should be inferred by this rule").with({ testTriple: u.not(u.nullish) }, (t) => {
|
|
1426
1425
|
const { subject: r, predicate: i, object: s } = t.testTriple;
|
|
1427
1426
|
return `Expected inference was not produced:
|
|
1428
1427
|
|
|
@@ -1468,13 +1467,13 @@ function pr(e) {
|
|
|
1468
1467
|
} : cr();
|
|
1469
1468
|
}
|
|
1470
1469
|
function Ct(e) {
|
|
1471
|
-
return p(e).with({ type:
|
|
1470
|
+
return p(e).with({ type: u.union("triple", "property", "class", "general") }, pr).with(
|
|
1472
1471
|
{ type: "negation" },
|
|
1473
1472
|
({ formulas: t }) => gt(t.map(Ct))
|
|
1474
1473
|
).with(
|
|
1475
1474
|
{ type: "aggregate" },
|
|
1476
1475
|
({ atoms: t }) => gt(t.map(Ct))
|
|
1477
|
-
).with({ type:
|
|
1476
|
+
).with({ type: u.union("filter", "bind", "skolem") }, cr).exhaustive();
|
|
1478
1477
|
}
|
|
1479
1478
|
function Di(e) {
|
|
1480
1479
|
return {
|
|
@@ -1799,10 +1798,10 @@ function Ls(e) {
|
|
|
1799
1798
|
return { allowed: !1, error: "Empty SPARQL update -- no operations found." };
|
|
1800
1799
|
const i = r.filter((a) => !Ge(a.subType));
|
|
1801
1800
|
if (i.length > 0) {
|
|
1802
|
-
const a = i.map((
|
|
1801
|
+
const a = i.map((g) => g.subType);
|
|
1803
1802
|
return {
|
|
1804
1803
|
allowed: !1,
|
|
1805
|
-
error: `Blocked operations: ${i.map((
|
|
1804
|
+
error: `Blocked operations: ${i.map((g) => nn[g.subType]).join(", ")}. Only INSERT DATA, DELETE DATA, and DELETE/INSERT WHERE are permitted.`,
|
|
1806
1805
|
blockedOperations: a
|
|
1807
1806
|
};
|
|
1808
1807
|
}
|
|
@@ -1822,8 +1821,8 @@ async function ln(e) {
|
|
|
1822
1821
|
}
|
|
1823
1822
|
});
|
|
1824
1823
|
if (!o.ok) {
|
|
1825
|
-
const
|
|
1826
|
-
throw new Error(`Failed to create connection: ${o.status} - ${
|
|
1824
|
+
const l = await o.text();
|
|
1825
|
+
throw new Error(`Failed to create connection: ${o.status} - ${l}`);
|
|
1827
1826
|
}
|
|
1828
1827
|
const a = o.headers.get("Location");
|
|
1829
1828
|
if (!a)
|
|
@@ -1840,8 +1839,8 @@ async function un(e) {
|
|
|
1840
1839
|
}
|
|
1841
1840
|
});
|
|
1842
1841
|
if (!a.ok) {
|
|
1843
|
-
const
|
|
1844
|
-
throw new Error(`Failed to begin transaction: ${a.status} - ${
|
|
1842
|
+
const l = await a.text();
|
|
1843
|
+
throw new Error(`Failed to begin transaction: ${a.status} - ${l}`);
|
|
1845
1844
|
}
|
|
1846
1845
|
}
|
|
1847
1846
|
async function cn(e) {
|
|
@@ -1854,8 +1853,8 @@ async function cn(e) {
|
|
|
1854
1853
|
}
|
|
1855
1854
|
});
|
|
1856
1855
|
if (!a.ok) {
|
|
1857
|
-
const
|
|
1858
|
-
throw new Error(`Failed to commit transaction: ${a.status} - ${
|
|
1856
|
+
const l = await a.text();
|
|
1857
|
+
throw new Error(`Failed to commit transaction: ${a.status} - ${l}`);
|
|
1859
1858
|
}
|
|
1860
1859
|
}
|
|
1861
1860
|
async function pn(e) {
|
|
@@ -1868,8 +1867,8 @@ async function pn(e) {
|
|
|
1868
1867
|
}
|
|
1869
1868
|
});
|
|
1870
1869
|
if (!a.ok) {
|
|
1871
|
-
const
|
|
1872
|
-
throw new Error(`Failed to rollback transaction: ${a.status} - ${
|
|
1870
|
+
const l = await a.text();
|
|
1871
|
+
throw new Error(`Failed to rollback transaction: ${a.status} - ${l}`);
|
|
1873
1872
|
}
|
|
1874
1873
|
}
|
|
1875
1874
|
async function hn(e) {
|
|
@@ -1880,8 +1879,8 @@ async function hn(e) {
|
|
|
1880
1879
|
}
|
|
1881
1880
|
});
|
|
1882
1881
|
if (!a.ok) {
|
|
1883
|
-
const
|
|
1884
|
-
throw new Error(`Failed to delete connection: ${a.status} - ${
|
|
1882
|
+
const l = await a.text();
|
|
1883
|
+
throw new Error(`Failed to delete connection: ${a.status} - ${l}`);
|
|
1885
1884
|
}
|
|
1886
1885
|
}
|
|
1887
1886
|
async function Us(e, t) {
|
|
@@ -1915,12 +1914,12 @@ function ws(e) {
|
|
|
1915
1914
|
return a || (a = { variable: o, predicateEvidence: [] }, t.set(o, a)), a;
|
|
1916
1915
|
}
|
|
1917
1916
|
function i(o) {
|
|
1918
|
-
const { atom: a, fromBody:
|
|
1919
|
-
if (
|
|
1920
|
-
const
|
|
1921
|
-
if (
|
|
1922
|
-
const T = r(
|
|
1923
|
-
T.classTerm ??=
|
|
1917
|
+
const { atom: a, fromBody: l = !1 } = o, g = Ye(a);
|
|
1918
|
+
if (g) {
|
|
1919
|
+
const N = St(g.instance);
|
|
1920
|
+
if (N) {
|
|
1921
|
+
const T = r(N);
|
|
1922
|
+
T.classTerm ??= g.className, l && (T.bodyClassTerm ??= g.className);
|
|
1924
1923
|
}
|
|
1925
1924
|
return;
|
|
1926
1925
|
}
|
|
@@ -1958,7 +1957,7 @@ function dn(e, t) {
|
|
|
1958
1957
|
}
|
|
1959
1958
|
}
|
|
1960
1959
|
const En = new Oe({ selfAnalysis: !1 }).getBaseCstVisitorConstructor();
|
|
1961
|
-
function
|
|
1960
|
+
function x(e, t) {
|
|
1962
1961
|
if (e === void 0)
|
|
1963
1962
|
throw new Error(t);
|
|
1964
1963
|
return e;
|
|
@@ -1987,10 +1986,10 @@ function _(e, t, r = e.image) {
|
|
|
1987
1986
|
}
|
|
1988
1987
|
function je(e) {
|
|
1989
1988
|
return p(e).returnType().with(
|
|
1990
|
-
{ IRI_REF:
|
|
1989
|
+
{ IRI_REF: u.when(d) },
|
|
1991
1990
|
({ IRI_REF: t }) => _(t[0], !1, t[0].image.slice(1, -1))
|
|
1992
|
-
).with({ PREFIXED_NAME:
|
|
1993
|
-
{ INTERNAL_FUNCTION:
|
|
1991
|
+
).with({ PREFIXED_NAME: u.when(d) }, ({ PREFIXED_NAME: t }) => _(t[0], !0)).with({ PREFIX_ONLY: u.when(d) }, ({ PREFIX_ONLY: t }) => _(t[0], !0)).with({ IDENTIFIER: u.when(d) }, ({ IDENTIFIER: t }) => _(t[0], !1)).with({ DEFAULT_NS_IRI: u.when(d) }, ({ DEFAULT_NS_IRI: t }) => _(t[0], !0)).with(
|
|
1992
|
+
{ INTERNAL_FUNCTION: u.when(d) },
|
|
1994
1993
|
({ INTERNAL_FUNCTION: t }) => _(t[0], !1)
|
|
1995
1994
|
).otherwise(() => {
|
|
1996
1995
|
throw new Error("Unknown IRI type");
|
|
@@ -2005,7 +2004,7 @@ function fn(e, t) {
|
|
|
2005
2004
|
}
|
|
2006
2005
|
class gn extends En {
|
|
2007
2006
|
rule(t) {
|
|
2008
|
-
const r = this.visit(
|
|
2007
|
+
const r = this.visit(x(t.ruleHead, "Rule missing head")), i = t.ruleBody?.[0] ? this.visit(t.ruleBody) : [];
|
|
2009
2008
|
return { head: r, body: i };
|
|
2010
2009
|
}
|
|
2011
2010
|
ruleHead(t) {
|
|
@@ -2113,13 +2112,13 @@ class gn extends En {
|
|
|
2113
2112
|
stringLiteral(t) {
|
|
2114
2113
|
const r = t.STRING_LITERAL_LONG?.[0], i = t.STRING_LITERAL?.[0], s = r ?? i;
|
|
2115
2114
|
if (!s) throw new Error("Unknown string literal format");
|
|
2116
|
-
const o = r ? this.unquoteTripleString(s.image) : this.unquoteString(s.image), a = K(s),
|
|
2115
|
+
const o = r ? this.unquoteTripleString(s.image) : this.unquoteString(s.image), a = K(s), l = t.LANGTAG?.[0], g = t.iri?.[0] ? je(t.iri[0].children) : void 0, y = l ? K(l).end : g ? K(g.token).end : a.end, m = {
|
|
2117
2116
|
type: "literal",
|
|
2118
2117
|
value: o,
|
|
2119
2118
|
termSpan: { start: a.start, end: y },
|
|
2120
2119
|
valueSpan: fn(s, r ? 3 : 1)
|
|
2121
2120
|
};
|
|
2122
|
-
return
|
|
2121
|
+
return l ? m.language = l.image.substring(1) : g && (m.datatype = g.term.value), m;
|
|
2123
2122
|
}
|
|
2124
2123
|
negation(t) {
|
|
2125
2124
|
const r = [];
|
|
@@ -2155,13 +2154,13 @@ class gn extends En {
|
|
|
2155
2154
|
filterAtom(t) {
|
|
2156
2155
|
return {
|
|
2157
2156
|
type: "filter",
|
|
2158
|
-
expression: this.visit(
|
|
2157
|
+
expression: this.visit(x(t.expression, "Filter missing expression"))
|
|
2159
2158
|
};
|
|
2160
2159
|
}
|
|
2161
2160
|
bindAtom(t) {
|
|
2162
2161
|
return {
|
|
2163
2162
|
type: "bind",
|
|
2164
|
-
expression: this.visit(
|
|
2163
|
+
expression: this.visit(x(t.expression, "Bind missing expression")),
|
|
2165
2164
|
...this.asTarget(t, "Bind missing variable")
|
|
2166
2165
|
};
|
|
2167
2166
|
}
|
|
@@ -2170,8 +2169,8 @@ class gn extends En {
|
|
|
2170
2169
|
asTarget(t, r) {
|
|
2171
2170
|
const i = t.VARIABLE?.[0];
|
|
2172
2171
|
if (i) return { variable: i.image.substring(1) };
|
|
2173
|
-
const s = this.visit(
|
|
2174
|
-
return { variable:
|
|
2172
|
+
const s = this.visit(x(t.groundedAsTarget, r));
|
|
2173
|
+
return { variable: O(s, { stripSimpleLiteralDatatypes: !0 }), groundedTarget: s };
|
|
2175
2174
|
}
|
|
2176
2175
|
// A variable-free `term`, so it visits identically.
|
|
2177
2176
|
groundedAsTarget(t) {
|
|
@@ -2180,7 +2179,7 @@ class gn extends En {
|
|
|
2180
2179
|
skolemAtom(t) {
|
|
2181
2180
|
return {
|
|
2182
2181
|
type: "skolem",
|
|
2183
|
-
args: this.visit(
|
|
2182
|
+
args: this.visit(x(t.argumentList, "Skolem missing argument list"))
|
|
2184
2183
|
};
|
|
2185
2184
|
}
|
|
2186
2185
|
aggregate(t) {
|
|
@@ -2199,7 +2198,7 @@ class gn extends En {
|
|
|
2199
2198
|
// variables ahead of any substituted values preserves source order in practice.
|
|
2200
2199
|
onClause(t) {
|
|
2201
2200
|
const r = t.VARIABLE?.map((o) => o.image.substring(1)) ?? [], i = t.groundedAsTarget?.map((o) => this.visit(o)) ?? [], s = i.map(
|
|
2202
|
-
(o) =>
|
|
2201
|
+
(o) => O(o, { stripSimpleLiteralDatatypes: !0 })
|
|
2203
2202
|
);
|
|
2204
2203
|
return {
|
|
2205
2204
|
onVars: [...r, ...s],
|
|
@@ -2209,12 +2208,12 @@ class gn extends En {
|
|
|
2209
2208
|
aggregateBind(t) {
|
|
2210
2209
|
const r = this.asTarget(t, "AggregateBind missing variable");
|
|
2211
2210
|
return t.aggregateFunction?.[0] ? { ...this.visit(t.aggregateFunction), ...r } : {
|
|
2212
|
-
expression: this.visit(
|
|
2211
|
+
expression: this.visit(x(t.expression, "AggregateBind missing expression")),
|
|
2213
2212
|
...r
|
|
2214
2213
|
};
|
|
2215
2214
|
}
|
|
2216
2215
|
aggregateFunction(t) {
|
|
2217
|
-
return p(t).with({ aggregateFunction1:
|
|
2216
|
+
return p(t).with({ aggregateFunction1: u.when(d) }, (r) => this.visit(r.aggregateFunction1[0])).with({ aggregateFunction2: u.when(d) }, (r) => this.visit(r.aggregateFunction2[0])).otherwise(() => {
|
|
2218
2217
|
throw new Error("Unknown aggregate function arity");
|
|
2219
2218
|
});
|
|
2220
2219
|
}
|
|
@@ -2268,9 +2267,9 @@ class gn extends En {
|
|
|
2268
2267
|
).otherwise(() => {
|
|
2269
2268
|
throw new Error("Unknown aggregate function");
|
|
2270
2269
|
}),
|
|
2271
|
-
expression: this.visit(
|
|
2270
|
+
expression: this.visit(x(t.firstExpr?.[0], "AggregateFunction2 missing first expression")),
|
|
2272
2271
|
secondExpression: this.visit(
|
|
2273
|
-
|
|
2272
|
+
x(t.secondExpr?.[0], "AggregateFunction2 missing second expression")
|
|
2274
2273
|
),
|
|
2275
2274
|
...t.DISTINCT && { distinct: !0 }
|
|
2276
2275
|
};
|
|
@@ -2313,7 +2312,7 @@ class gn extends En {
|
|
|
2313
2312
|
}
|
|
2314
2313
|
return t.additiveExpression.length > 1 ? {
|
|
2315
2314
|
type: "binary",
|
|
2316
|
-
operator: p(t).with({ EQUALS:
|
|
2315
|
+
operator: p(t).with({ EQUALS: u.when(Boolean) }, () => "=").with({ NOT_EQUALS: u.when(Boolean) }, () => "!=").with({ LESS_THAN: u.when(Boolean) }, () => "<").with({ GREATER_THAN: u.when(Boolean) }, () => ">").with({ LESS_THAN_OR_EQUAL: u.when(Boolean) }, () => "<=").with({ GREATER_THAN_OR_EQUAL: u.when(Boolean) }, () => ">=").otherwise(() => "="),
|
|
2317
2316
|
left: r,
|
|
2318
2317
|
right: t.additiveExpression[1] ? this.visit(t.additiveExpression[1]) : r
|
|
2319
2318
|
} : r;
|
|
@@ -2350,21 +2349,21 @@ class gn extends En {
|
|
|
2350
2349
|
}
|
|
2351
2350
|
unaryExpression(t) {
|
|
2352
2351
|
return p(t).with(
|
|
2353
|
-
{ EXCLAMATION:
|
|
2352
|
+
{ EXCLAMATION: u.when(Boolean) },
|
|
2354
2353
|
() => ({
|
|
2355
2354
|
type: "unary",
|
|
2356
2355
|
operator: "!",
|
|
2357
2356
|
operand: this.visit(t.primaryExpression)
|
|
2358
2357
|
})
|
|
2359
2358
|
).with(
|
|
2360
|
-
{ PLUS:
|
|
2359
|
+
{ PLUS: u.when(Boolean) },
|
|
2361
2360
|
() => ({
|
|
2362
2361
|
type: "unary",
|
|
2363
2362
|
operator: "+",
|
|
2364
2363
|
operand: this.visit(t.primaryExpression)
|
|
2365
2364
|
})
|
|
2366
2365
|
).with(
|
|
2367
|
-
{ MINUS:
|
|
2366
|
+
{ MINUS: u.when(Boolean) },
|
|
2368
2367
|
() => ({
|
|
2369
2368
|
type: "unary",
|
|
2370
2369
|
operator: "-",
|
|
@@ -2373,7 +2372,7 @@ class gn extends En {
|
|
|
2373
2372
|
).otherwise(() => this.visit(t.primaryExpression));
|
|
2374
2373
|
}
|
|
2375
2374
|
functionCall(t) {
|
|
2376
|
-
return p(t).with({ concatFunction:
|
|
2375
|
+
return p(t).with({ concatFunction: u.when(d) }, (r) => this.visit(r.concatFunction[0])).with({ strFunction: u.when(d) }, (r) => this.visit(r.strFunction[0])).with({ ifFunction: u.when(d) }, (r) => this.visit(r.ifFunction[0])).with({ iriFunction: u.when(d) }, (r) => this.visit(r.iriFunction[0])).with({ skolemFunction: u.when(d) }, (r) => this.visit(r.skolemFunction[0])).with({ roundFunction: u.when(d) }, (r) => this.visit(r.roundFunction[0])).with({ regexFunction: u.when(d) }, (r) => this.visit(r.regexFunction[0])).with({ iri: u.when(d), LPAREN: u.when(d) }, (r) => {
|
|
2377
2376
|
const i = r.iri[0] ? this.visit(r.iri[0]) : null, s = i && typeof i == "object" && "type" in i && i.type === "iri" && "value" in i ? String(i.value) : "unknown", o = r.argumentList?.[0] ? this.visit(r.argumentList[0]) : [];
|
|
2378
2377
|
return { type: "function", name: s, args: o };
|
|
2379
2378
|
}).otherwise(() => {
|
|
@@ -2425,8 +2424,8 @@ class gn extends En {
|
|
|
2425
2424
|
}
|
|
2426
2425
|
regexFunction(t) {
|
|
2427
2426
|
const r = [
|
|
2428
|
-
this.visit(
|
|
2429
|
-
this.visit(
|
|
2427
|
+
this.visit(x(t.textExpr, "REGEX missing text expression")),
|
|
2428
|
+
this.visit(x(t.patternExpr, "REGEX missing pattern expression"))
|
|
2430
2429
|
];
|
|
2431
2430
|
return t.flagsExpr?.[0] && r.push(this.visit(t.flagsExpr)), {
|
|
2432
2431
|
type: "function",
|
|
@@ -2438,13 +2437,13 @@ class gn extends En {
|
|
|
2438
2437
|
return t.expression.map((r) => this.visit(r));
|
|
2439
2438
|
}
|
|
2440
2439
|
primaryExpression(t) {
|
|
2441
|
-
return p(t).with({ expression:
|
|
2440
|
+
return p(t).with({ expression: u.when(d) }, (r) => this.visit(r.expression[0])).with({ functionCall: u.when(d) }, (r) => this.visit(r.functionCall[0])).with({ literal: u.when(d) }, (r) => ({ type: "term", term: this.visit(r.literal[0]) })).with({ VARIABLE: u.when(d) }, (r) => ({
|
|
2442
2441
|
type: "term",
|
|
2443
2442
|
term: { type: "variable", name: r.VARIABLE[0].image.substring(1) }
|
|
2444
|
-
})).with({ BLANK_NODE:
|
|
2443
|
+
})).with({ BLANK_NODE: u.when(d) }, (r) => ({
|
|
2445
2444
|
type: "term",
|
|
2446
2445
|
term: { type: "blank", label: r.BLANK_NODE[0].image.substring(2) }
|
|
2447
|
-
})).with({ iri:
|
|
2446
|
+
})).with({ iri: u.when(d) }, (r) => ({ type: "term", term: this.visit(r.iri[0]) })).otherwise(() => {
|
|
2448
2447
|
throw new Error("Unknown primary expression type");
|
|
2449
2448
|
});
|
|
2450
2449
|
}
|
|
@@ -2481,7 +2480,7 @@ function B(e, t, r) {
|
|
|
2481
2480
|
});
|
|
2482
2481
|
}
|
|
2483
2482
|
function yt(e, t) {
|
|
2484
|
-
p(e).with({ type:
|
|
2483
|
+
p(e).with({ type: u.union("triple", "property", "class", "general") }, (r) => {
|
|
2485
2484
|
I(t, rt(r));
|
|
2486
2485
|
}).with({ type: "filter" }, (r) => {
|
|
2487
2486
|
I(t, w(r.expression));
|
|
@@ -2499,12 +2498,12 @@ function yt(e, t) {
|
|
|
2499
2498
|
}).exhaustive();
|
|
2500
2499
|
}
|
|
2501
2500
|
function yr(e, t) {
|
|
2502
|
-
p(e).with({ type:
|
|
2501
|
+
p(e).with({ type: u.union("triple", "property", "class", "general") }, (r) => {
|
|
2503
2502
|
I(t, rt(r));
|
|
2504
2503
|
}).with({ type: "skolem" }, (r) => {
|
|
2505
2504
|
const i = Kr(r);
|
|
2506
2505
|
i && t.add(i);
|
|
2507
|
-
}).with({ type:
|
|
2506
|
+
}).with({ type: u.union("bind", "filter", "negation", "aggregate") }, () => {
|
|
2508
2507
|
}).exhaustive();
|
|
2509
2508
|
}
|
|
2510
2509
|
function yn(e, t, r, i) {
|
|
@@ -2538,7 +2537,7 @@ function Ur(e, t, r) {
|
|
|
2538
2537
|
});
|
|
2539
2538
|
}
|
|
2540
2539
|
function wr(e, t, r) {
|
|
2541
|
-
p(e).with({ type:
|
|
2540
|
+
p(e).with({ type: u.union("triple", "property", "class", "general") }, () => {
|
|
2542
2541
|
}).with({ type: "filter" }, (i) => {
|
|
2543
2542
|
B(t, w(i.expression), r);
|
|
2544
2543
|
}).with({ type: "bind" }, (i) => {
|
|
@@ -2730,7 +2729,7 @@ export {
|
|
|
2730
2729
|
Te as STRING_LITERAL_LONG,
|
|
2731
2730
|
Vt as SUM,
|
|
2732
2731
|
ie as TRUE,
|
|
2733
|
-
|
|
2732
|
+
R as VARIABLE,
|
|
2734
2733
|
Ui as WHITESPACE,
|
|
2735
2734
|
or as allTokens,
|
|
2736
2735
|
bs as areRulesEquivalent,
|
|
@@ -2799,7 +2798,7 @@ export {
|
|
|
2799
2798
|
Vn as isTermExpression,
|
|
2800
2799
|
xn as isTripleAtom,
|
|
2801
2800
|
_n as isUnaryExpression,
|
|
2802
|
-
|
|
2801
|
+
C as isVariableTerm,
|
|
2803
2802
|
et as isXsdDatatype,
|
|
2804
2803
|
wi as keywordTokenTypes,
|
|
2805
2804
|
ns as literalSetComparisonFromExpression,
|
|
@@ -2825,7 +2824,7 @@ export {
|
|
|
2825
2824
|
Kr as skolemMintedVariable,
|
|
2826
2825
|
Si as stringLiteralTokenTypes,
|
|
2827
2826
|
Ns as termTextsEqual,
|
|
2828
|
-
|
|
2827
|
+
O as termToDatalogText,
|
|
2829
2828
|
fs as termToSparql,
|
|
2830
2829
|
ds as termTokenTypes,
|
|
2831
2830
|
Je as termsEqual,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manta-eu/datalog-parser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "RDFox Datalog parser and AST builder with inference verification",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -30,12 +30,14 @@
|
|
|
30
30
|
"@microsoft/api-extractor": "7.56.0",
|
|
31
31
|
"@types/node": "^24.13.3",
|
|
32
32
|
"@vitest/coverage-v8": "^4.1.8",
|
|
33
|
+
"eslint": "^9.39.2",
|
|
33
34
|
"prettier": "^3.8.1",
|
|
34
35
|
"tsx": "^4.21.0",
|
|
35
36
|
"typescript": "^5.9.3",
|
|
36
37
|
"vite": "^7.3.1",
|
|
37
38
|
"vite-plugin-dts": "^4.5.4",
|
|
38
|
-
"vitest": "^4.1.8"
|
|
39
|
+
"vitest": "^4.1.8",
|
|
40
|
+
"@manta-eu/eslint-config": "0.1.0"
|
|
39
41
|
},
|
|
40
42
|
"prettier": {
|
|
41
43
|
"printWidth": 120
|
|
@@ -54,6 +56,8 @@
|
|
|
54
56
|
"format:check": "prettier --check .",
|
|
55
57
|
"diagrams": "tsx scripts/generate-diagrams.ts",
|
|
56
58
|
"generate-types": "tsx generate-types.ts",
|
|
57
|
-
"build:parser-wasm": "vite build --config vite.wasm.config.ts && mkdir -p dist && javy build dist-wasm-js/wasm-entry.js -o dist/parser.wasm"
|
|
59
|
+
"build:parser-wasm": "vite build --config vite.wasm.config.ts && mkdir -p dist && javy build dist-wasm-js/wasm-entry.js -o dist/parser.wasm",
|
|
60
|
+
"lint": "eslint .",
|
|
61
|
+
"lint:fix": "eslint . --fix"
|
|
58
62
|
}
|
|
59
63
|
}
|