@manta-eu/datalog-parser 0.1.5 → 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.
Files changed (2) hide show
  1. package/dist/index.js +197 -197
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
- import { match as p, P as l } from "ts-pattern";
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), v = (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(v)).with({ type: "property" }, (t) => [t.subject, t.object].filter(v)).with({ type: "class" }, (t) => [t.instance].filter(v)).with({ type: "general" }, (t) => t.terms.filter(v)).exhaustive(), Br = (e) => {
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 && v(r) ? [...t, r] : t;
11
- }, Qn = (e) => e.function, zn = (e) => p(e).with(l.union("+", "-", "*", "/", "<", ">", "<=", ">="), () => !0).with(l.union("=", "!=", "||", "&&"), () => !1).exhaustive(), Kn = (e) => p(e).with(l.union("||", "&&", "=", "!=", "<", ">", "<=", ">="), () => !0).with(l.union("+", "-", "*", "/"), () => !1).exhaustive(), ze = '[^\\s<>"{}|^`\\\\]', Fr = new RegExp(`^[a-z][a-z0-9+.-]*:${ze}*$`, "i");
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, u = i.length + Number(o ?? 0);
32
- if (a.length + Math.abs(u) > Gr) return e;
33
- const f = _r(a, u), y = f.integer.replace(/^0+(?=\d)/, ""), m = f.fraction.replace(/0+$/, ""), h = m ? `${y}.${m}` : y;
34
- return h === "0" || r === "+" ? h : `${r}${h}`;
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: l.union("triple", "property", "class", "general") }, () => !0).otherwise(() => !1);
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: l.union("filter", "bind") }, ({ expression: t }) => M(t)).with({ type: "negation" }, ({ formulas: t }) => t.some(Ot)).with(
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: l.union("triple", "property", "class", "general") }, () => !1).exhaustive();
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: l.union("a", "rdf:type", Rt),
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: l.union("a", "rdf:type", Rt) },
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: l.not(l.union("a", "rdf:type", Rt)) } },
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: l.union("=", "!=", "<", ">", "<=", ">=") },
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 : v(r) && Z(i) ? { variableName: r.name, operator: t.operator, literal: i } : Z(r) && v(i) ? {
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([l.not(l.nullish), { type: "literal" }], ([r, i]) => ({ subject: r, literal: i })).with([{ type: "literal" }, l.not(l.nullish)], ([r, i]) => ({ subject: i, literal: r })).otherwise(() => null)
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 u = Yr(a);
202
- return u ? [u] : [];
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 && v(t) ? t.name : null;
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: l.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) => {
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((u) => t.add(u)), a.bindings?.forEach((u) => {
240
- t.add(u.variable), u.expression !== "*" && r(u.expression), u.secondExpression && r(u.secondExpression);
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((u) => r.add(u));
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: l.union("triple", "property", "class", "general") }, s).with({ type: "negation" }, (u) => u.formulas.forEach(o)).with({ type: "filter" }, (u) => i(w(u.expression))).with(
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
- (u) => i([...w(u.expression), u.variable])
255
- ).with({ type: "aggregate" }, (u) => {
256
- u.atoms.forEach(o);
257
- const f = [
258
- ...u.onVars ?? [],
259
- ...(u.bindings ?? []).flatMap((y) => [
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(f);
265
+ i(g);
266
266
  }).with(
267
267
  { type: "skolem" },
268
- (u) => i(u.args.flatMap((f) => w(f)))
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 && v(e) ? [e.name] : [];
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 b(e, t = {}) {
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 ? ` ${b(e.graph, t)}` : "";
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}[${b(i.subject, t)}, ${b(i.object, t)}]${r}`
311
+ (i) => `${i.predicate}[${O(i.subject, t)}, ${O(i.object, t)}]${r}`
312
312
  ).with(
313
313
  { type: "triple" },
314
- (i) => `[${b(i.subject, t)}, ${b(i.predicate, t)}, ${b(i.object, t)}]${r}`
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}[${b(i.instance, t)}]${r}`
317
+ (i) => `${i.className}[${O(i.instance, t)}]${r}`
318
318
  ).with(
319
319
  { type: "general" },
320
- (i) => `${i.tableName}(${i.terms.map((s) => b(s, t)).join(", ")})`
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
- x(` ${r.operator} `),
332
+ v(` ${r.operator} `),
333
333
  ...Pe(r.right, r.operator, "right", t)
334
- ]).with({ type: "unary" }, (r) => [x(r.operator), ...ti(r.operand, t)]).with({ type: "term" }, (r) => ei(r.term, t)).with({ type: "function" }, (r) => [
335
- x(`${r.name}(`),
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
- x(")")
340
+ v(")")
341
341
  ]).with({ type: "in" }, (r) => [
342
342
  ...X(r.expression, t),
343
- x(` ${r.negated ? "NOT IN" : "IN"} (`),
343
+ v(` ${r.negated ? "NOT IN" : "IN"} (`),
344
344
  ...ke(
345
345
  r.list.map((i) => X(i, t)),
346
346
  ", "
347
347
  ),
348
- x(")")
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 v(e) ? [ii(e.name)] : Z(e) ? [ni(e, t)] : [x(b(e, t))];
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 [x("("), ...e, x(")")];
371
+ return [v("("), ...e, v(")")];
372
372
  }
373
373
  function ke(e, t) {
374
- return e.flatMap((r, i) => i === 0 ? r : [x(t), ...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 x(e) {
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: b(e, t) };
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: l.union("triple", "property", "class", "general", "filter", "skolem") }, () => !1).exhaustive();
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(), g = E.gen(), $e = It.getRule("aggregate"), De = It.getRule("expression"), ai = {
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], u = r.astFactory;
408
- if (u.isWildcard(a))
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
- u.printFilter(t, () => {
410
+ l.printFilter(t, () => {
411
411
  s(t.aggregation.toUpperCase(), "("), t.distinct && s("DISTINCT");
412
- }), o(De, a), u.printFilter(t, () => s(",")), o(De, i), u.printFilter(t, () => s(")"));
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(g, e);
422
+ return E.termNamed(f, e);
423
423
  const r = e.indexOf(":");
424
- return r >= 0 ? E.termNamed(g, e.slice(r + 1), e.slice(0, r)) : E.termNamed(g, e);
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, g);
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 u = i === "*" ? E.wildcard(g) : R(i, t), f = E.aggregate(
437
+ const l = i === "*" ? E.wildcard(f) : b(i, t), g = E.aggregate(
438
438
  r.toLowerCase(),
439
439
  e.distinct || !1,
440
- u,
440
+ l,
441
441
  void 0,
442
- g
442
+ f
443
443
  );
444
444
  return a ? {
445
- ...f,
446
- secondExpression: R(s, t)
447
- } : f;
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(l.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, g))).with({ type: "iri", prefixed: !0 }, (i) => $(i.value)).with({ type: "iri", prefixed: !1 }, (i) => E.termNamed(g, i.value)).with(
461
- { type: "literal", language: l.string },
462
- (i) => E.termLiteral(g, i.value, i.language)
463
- ).with({ type: "literal", datatype: l.string }, (i) => {
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(g, i.value, s);
466
- }).with({ type: "literal" }, (i) => E.termLiteral(g, i.value)).with({ type: "blank" }, (i) => E.termBlank(i.label, g)).exhaustive();
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) => R(o, t)), i = ui.get(e.name.toLowerCase());
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, g);
473
+ return E.expressionFunctionCall(s, r, !1, f);
474
474
  }
475
- function R(e, t) {
475
+ function b(e, t) {
476
476
  return p(e).with(
477
477
  { type: "binary" },
478
478
  (r) => st(r.operator, [
479
- R(r.left, t),
480
- R(r.right, t)
479
+ b(r.left, t),
480
+ b(r.right, t)
481
481
  ])
482
482
  ).with(
483
483
  { type: "unary" },
484
- (r) => st(r.operator, [R(r.operand, t)])
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
- R(r.expression, t),
489
- ...r.list.map((i) => R(i, t))
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], g);
512
+ const i = E.patternBgp([r], f);
513
513
  return { graph: E.patternGraph(
514
514
  P(e.graph, t, "graph"),
515
515
  [i],
516
- g
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: l.union("triple", "property", "class") }, (i) => Ft(i, t).triples || []).with({ type: "general" }, () => {
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: l.union("triple", "property", "class") }, (s) => {
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 = R(s.expression, t), a = E.patternFilter(o, g);
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 = R(s.expression, t), a = E.termVariable(s.variable, g), u = E.patternBind(o, a, g);
539
- return { ...r, binds: [...r.binds, u] };
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 || [], u = a.map((m) => (t.add(m), E.termVariable(m, g))), f = [], y = [];
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, C = h ? ci(m, t) : R(m.expression, t), T = E.termVariable(m.variable, g), A = E.patternBind(C, T, g);
556
- h ? f.push(A) : y.push(A);
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: [...u, ...f],
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, C) => p(C).with({ type: l.union("triple", "property", "class", "general") }, (T) => {
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 = R(T.expression, r), k = E.patternFilter(A, g);
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 = R(T.expression, r);
576
+ const A = b(T.expression, r);
577
577
  r.add(T.variable);
578
- const k = E.termVariable(T.variable, g), At = E.patternBind(A, k, g);
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, g), At = E.patternGroup([k], g), Sr = E.expressionPatternOperation("notexists", At, g), Nr = E.patternFilter(Sr, g);
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, g)] : [],
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, g)) : [E.wildcard(g)], a = i.groupByVars.length > 0 ? {
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, g)),
616
- g
615
+ i.groupByVars.map((h) => E.termVariable(h, f)),
616
+ f
617
617
  )
618
- } : {}, u = t ? Object.entries(t).map(([h, C]) => {
619
- const T = E.termNamed(g, C);
620
- return E.contextDefinitionPrefix(g, h, T);
621
- }) : [], f = E.querySelect(
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: u,
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, g),
628
- datasets: E.datasetClauses([], g),
627
+ where: E.patternGroup(s, f),
628
+ datasets: E.datasetClauses([], f),
629
629
  solutionModifiers: a
630
630
  },
631
- g
632
- ), y = oi.queryOrUpdate(f, 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);
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: /:/ }), N = 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({
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
- N,
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([N, J, Se, tt]);
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, u = r.image.slice(i, i + a), f = r.image.slice(i + 2, i + a), y = r.startOffset + i;
819
- if (f.length !== o || !/^[0-9a-fA-F]+$/.test(f))
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
- u.length,
823
+ l.length,
824
824
  `Unicode escape \\${s} must contain ${o} hexadecimal digits`
825
825
  );
826
- const m = Number.parseInt(f, 16);
826
+ const m = Number.parseInt(g, 16);
827
827
  if (m >= 55296 && m <= 57343)
828
- return Y(e, y, a, `Unicode escape ${u} denotes a surrogate code point`);
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 ${u} is outside the Unicode range`);
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(N) }, { ALT: () => this.SUBRULE(this.iri) }]);
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(N) },
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) }
@@ -973,8 +973,8 @@ class Oe extends Cr {
973
973
  });
974
974
  // ExistsClause := 'EXISTS' variable (',' variable)* 'IN'
975
975
  existsClause = this.RULE("existsClause", () => {
976
- this.CONSUME(kt), this.CONSUME(N), this.MANY(() => {
977
- this.CONSUME(S), this.CONSUME2(N);
976
+ this.CONSUME(kt), this.CONSUME(R), this.MANY(() => {
977
+ this.CONSUME(S), this.CONSUME2(R);
978
978
  }), this.CONSUME(W);
979
979
  });
980
980
  // AtomList := Atom (',' Atom)*
@@ -1003,7 +1003,7 @@ class Oe extends Cr {
1003
1003
  });
1004
1004
  // BindAtom := 'BIND' '(' Expression 'AS' variable ')'
1005
1005
  bindAtom = this.RULE("bindAtom", () => {
1006
- this.CONSUME(Q), this.CONSUME(L), this.SUBRULE(this.expression), this.CONSUME(z), this.CONSUME(N), this.CONSUME(U);
1006
+ this.CONSUME(Q), this.CONSUME(L), this.SUBRULE(this.expression), this.CONSUME(z), this.CONSUME(R), this.CONSUME(U);
1007
1007
  });
1008
1008
  // SkolemAtom := 'SKOLEM' '(' ArgumentList ')'
1009
1009
  skolemAtom = this.RULE("skolemAtom", () => {
@@ -1019,15 +1019,15 @@ class Oe extends Cr {
1019
1019
  });
1020
1020
  // OnClause := 'ON' variable+
1021
1021
  onClause = this.RULE("onClause", () => {
1022
- this.CONSUME(Ut), this.CONSUME(N), this.MANY(() => {
1023
- this.CONSUME2(N);
1022
+ this.CONSUME(Ut), this.CONSUME(R), this.MANY(() => {
1023
+ this.CONSUME2(R);
1024
1024
  });
1025
1025
  });
1026
1026
  // AggregateBind := ('BIND' AggregateFunction | AggregateFunction) 'AS' variable
1027
1027
  aggregateBind = this.RULE("aggregateBind", () => {
1028
1028
  this.OPTION(() => {
1029
1029
  this.CONSUME(Q);
1030
- }), this.SUBRULE(this.aggregateFunction), this.CONSUME(z), this.CONSUME(N);
1030
+ }), this.SUBRULE(this.aggregateFunction), this.CONSUME(z), this.CONSUME(R);
1031
1031
  });
1032
1032
  // AggregateFunction := AggregateFunction1 | AggregateFunction2
1033
1033
  aggregateFunction = this.RULE("aggregateFunction", () => {
@@ -1195,7 +1195,7 @@ class Oe extends Cr {
1195
1195
  },
1196
1196
  { ALT: () => this.SUBRULE(this.functionCall) },
1197
1197
  { ALT: () => this.SUBRULE(this.literal) },
1198
- { ALT: () => this.CONSUME(N) },
1198
+ { ALT: () => this.CONSUME(R) },
1199
1199
  { ALT: () => this.SUBRULE(this.iri) }
1200
1200
  ]);
1201
1201
  });
@@ -1246,7 +1246,7 @@ class bi extends Oe {
1246
1246
  });
1247
1247
  // Each rule below records this once, so the default occurrence index is unambiguous.
1248
1248
  variableOrGroundedTarget() {
1249
- this.OR([{ ALT: () => this.CONSUME(N) }, { ALT: () => this.SUBRULE(this.groundedAsTarget) }]);
1249
+ this.OR([{ ALT: () => this.CONSUME(R) }, { ALT: () => this.SUBRULE(this.groundedAsTarget) }]);
1250
1250
  }
1251
1251
  // OnClause := 'ON' (variable | GroundedAsTarget)*
1252
1252
  // Grounding substitutes the grouping variables as well, and an aggregate
@@ -1289,7 +1289,7 @@ class bi extends Oe {
1289
1289
  },
1290
1290
  { ALT: () => this.SUBRULE(this.functionCall) },
1291
1291
  { ALT: () => this.SUBRULE(this.literal) },
1292
- { ALT: () => this.CONSUME(N) },
1292
+ { ALT: () => this.CONSUME(R) },
1293
1293
  { ALT: () => this.CONSUME(J) },
1294
1294
  { ALT: () => this.SUBRULE(this.iri) }
1295
1295
  ]);
@@ -1305,13 +1305,13 @@ function vi(e) {
1305
1305
  function Ci(e) {
1306
1306
  ir(e.body);
1307
1307
  const t = e.body.filter((s) => s.type !== "negation"), r = We(e.body) ? t.filter(
1308
- (s) => p(s).with({ type: l.union("triple", "property", "class") }, () => !0).otherwise(() => !1)
1308
+ (s) => p(s).with({ type: u.union("triple", "property", "class") }, () => !0).otherwise(() => !1)
1309
1309
  ) : t, { query: i } = fi(r);
1310
1310
  return `${i}
1311
1311
  LIMIT 1`;
1312
1312
  }
1313
1313
  function fs(e) {
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: l.string }, (t) => `"${t.value}"@${t.language}`).with({ type: "literal", datatype: l.string }, (t) => `"${t.value}"^^${er(t.datatype)}`).with({ type: "literal" }, (t) => `"${t.value}"`).with({ type: "blank" }, (t) => `_:${t.label}`).exhaustive();
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();
1315
1315
  }
1316
1316
  function Ii(e) {
1317
1317
  const t = e.head[0];
@@ -1330,7 +1330,7 @@ function Ii(e) {
1330
1330
  })).with({ type: "general" }, () => null).exhaustive() : null;
1331
1331
  }
1332
1332
  function G(e) {
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: l.string }, (t) => `"${t.value}"^^${t.datatype}`).with({ type: "literal" }, (t) => `"${t.value}"`).with({ type: "blank" }, (t) => `_:${t.label}`).exhaustive();
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();
1334
1334
  }
1335
1335
  const Mi = j.object({
1336
1336
  results: j.object({
@@ -1352,13 +1352,13 @@ async function gs(e, t, r, i, s) {
1352
1352
  verified: !1,
1353
1353
  error: "Could not generate test triple from rule head"
1354
1354
  };
1355
- const u = Ci(e), f = await Fi(u, t, r, i);
1356
- if (f)
1355
+ const l = Ci(e), g = await Fi(l, t, r, i);
1356
+ if (g)
1357
1357
  return {
1358
1358
  verified: !1,
1359
1359
  testTriple: a,
1360
- candidateQuery: u,
1361
- error: f
1360
+ candidateQuery: l,
1361
+ error: g
1362
1362
  };
1363
1363
  const y = Pi(a), m = new URL(`datastores/${r}/sparql`, t), h = await fetch(m.toString(), {
1364
1364
  method: "POST",
@@ -1375,7 +1375,7 @@ async function gs(e, t, r, i, s) {
1375
1375
  verified: Bi.parse(await h.json()).boolean,
1376
1376
  testTriple: a,
1377
1377
  sparqlQuery: y,
1378
- candidateQuery: u
1378
+ candidateQuery: l
1379
1379
  };
1380
1380
  } catch (a) {
1381
1381
  return {
@@ -1397,13 +1397,13 @@ async function Fi(e, t, r, i) {
1397
1397
  body: e
1398
1398
  });
1399
1399
  if (!o.ok) {
1400
- let u = "";
1400
+ let l = "";
1401
1401
  try {
1402
- u = await o.text();
1402
+ l = await o.text();
1403
1403
  } catch {
1404
1404
  }
1405
- const f = u || o.statusText;
1406
- return `Candidate query failed: ${o.status}${f ? ` - ${f}` : ""}`;
1405
+ const g = l || o.statusText;
1406
+ return `Candidate query failed: ${o.status}${g ? ` - ${g}` : ""}`;
1407
1407
  }
1408
1408
  return Mi.parse(await o.json()).results.bindings.length > 0 ? void 0 : "No candidate variable bindings found for rule body - rule cannot fire";
1409
1409
  } catch (s) {
@@ -1421,7 +1421,7 @@ function Pi(e) {
1421
1421
  `.trim();
1422
1422
  }
1423
1423
  function ms(e) {
1424
- return p(e).with({ verified: !0 }, () => "Inference verification succeeded").with({ error: l.string }, (t) => t.error).with({ testTriple: l.nullish }, () => "Could not determine what triple should be inferred by this rule").with({ testTriple: l.not(l.nullish) }, (t) => {
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) => {
1425
1425
  const { subject: r, predicate: i, object: s } = t.testTriple;
1426
1426
  return `Expected inference was not produced:
1427
1427
 
@@ -1467,13 +1467,13 @@ function pr(e) {
1467
1467
  } : cr();
1468
1468
  }
1469
1469
  function Ct(e) {
1470
- return p(e).with({ type: l.union("triple", "property", "class", "general") }, pr).with(
1470
+ return p(e).with({ type: u.union("triple", "property", "class", "general") }, pr).with(
1471
1471
  { type: "negation" },
1472
1472
  ({ formulas: t }) => gt(t.map(Ct))
1473
1473
  ).with(
1474
1474
  { type: "aggregate" },
1475
1475
  ({ atoms: t }) => gt(t.map(Ct))
1476
- ).with({ type: l.union("filter", "bind", "skolem") }, cr).exhaustive();
1476
+ ).with({ type: u.union("filter", "bind", "skolem") }, cr).exhaustive();
1477
1477
  }
1478
1478
  function Di(e) {
1479
1479
  return {
@@ -1798,10 +1798,10 @@ function Ls(e) {
1798
1798
  return { allowed: !1, error: "Empty SPARQL update -- no operations found." };
1799
1799
  const i = r.filter((a) => !Ge(a.subType));
1800
1800
  if (i.length > 0) {
1801
- const a = i.map((f) => f.subType);
1801
+ const a = i.map((g) => g.subType);
1802
1802
  return {
1803
1803
  allowed: !1,
1804
- error: `Blocked operations: ${i.map((f) => nn[f.subType]).join(", ")}. Only INSERT DATA, DELETE DATA, and DELETE/INSERT WHERE are permitted.`,
1804
+ error: `Blocked operations: ${i.map((g) => nn[g.subType]).join(", ")}. Only INSERT DATA, DELETE DATA, and DELETE/INSERT WHERE are permitted.`,
1805
1805
  blockedOperations: a
1806
1806
  };
1807
1807
  }
@@ -1821,8 +1821,8 @@ async function ln(e) {
1821
1821
  }
1822
1822
  });
1823
1823
  if (!o.ok) {
1824
- const u = await o.text();
1825
- throw new Error(`Failed to create connection: ${o.status} - ${u}`);
1824
+ const l = await o.text();
1825
+ throw new Error(`Failed to create connection: ${o.status} - ${l}`);
1826
1826
  }
1827
1827
  const a = o.headers.get("Location");
1828
1828
  if (!a)
@@ -1839,8 +1839,8 @@ async function un(e) {
1839
1839
  }
1840
1840
  });
1841
1841
  if (!a.ok) {
1842
- const u = await a.text();
1843
- throw new Error(`Failed to begin transaction: ${a.status} - ${u}`);
1842
+ const l = await a.text();
1843
+ throw new Error(`Failed to begin transaction: ${a.status} - ${l}`);
1844
1844
  }
1845
1845
  }
1846
1846
  async function cn(e) {
@@ -1853,8 +1853,8 @@ async function cn(e) {
1853
1853
  }
1854
1854
  });
1855
1855
  if (!a.ok) {
1856
- const u = await a.text();
1857
- throw new Error(`Failed to commit transaction: ${a.status} - ${u}`);
1856
+ const l = await a.text();
1857
+ throw new Error(`Failed to commit transaction: ${a.status} - ${l}`);
1858
1858
  }
1859
1859
  }
1860
1860
  async function pn(e) {
@@ -1867,8 +1867,8 @@ async function pn(e) {
1867
1867
  }
1868
1868
  });
1869
1869
  if (!a.ok) {
1870
- const u = await a.text();
1871
- throw new Error(`Failed to rollback transaction: ${a.status} - ${u}`);
1870
+ const l = await a.text();
1871
+ throw new Error(`Failed to rollback transaction: ${a.status} - ${l}`);
1872
1872
  }
1873
1873
  }
1874
1874
  async function hn(e) {
@@ -1879,8 +1879,8 @@ async function hn(e) {
1879
1879
  }
1880
1880
  });
1881
1881
  if (!a.ok) {
1882
- const u = await a.text();
1883
- throw new Error(`Failed to delete connection: ${a.status} - ${u}`);
1882
+ const l = await a.text();
1883
+ throw new Error(`Failed to delete connection: ${a.status} - ${l}`);
1884
1884
  }
1885
1885
  }
1886
1886
  async function Us(e, t) {
@@ -1914,12 +1914,12 @@ function ws(e) {
1914
1914
  return a || (a = { variable: o, predicateEvidence: [] }, t.set(o, a)), a;
1915
1915
  }
1916
1916
  function i(o) {
1917
- const { atom: a, fromBody: u = !1 } = o, f = Ye(a);
1918
- if (f) {
1919
- const C = St(f.instance);
1920
- if (C) {
1921
- const T = r(C);
1922
- T.classTerm ??= f.className, u && (T.bodyClassTerm ??= f.className);
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);
1923
1923
  }
1924
1924
  return;
1925
1925
  }
@@ -1957,7 +1957,7 @@ function dn(e, t) {
1957
1957
  }
1958
1958
  }
1959
1959
  const En = new Oe({ selfAnalysis: !1 }).getBaseCstVisitorConstructor();
1960
- function O(e, t) {
1960
+ function x(e, t) {
1961
1961
  if (e === void 0)
1962
1962
  throw new Error(t);
1963
1963
  return e;
@@ -1986,10 +1986,10 @@ function _(e, t, r = e.image) {
1986
1986
  }
1987
1987
  function je(e) {
1988
1988
  return p(e).returnType().with(
1989
- { IRI_REF: l.when(d) },
1989
+ { IRI_REF: u.when(d) },
1990
1990
  ({ IRI_REF: t }) => _(t[0], !1, t[0].image.slice(1, -1))
1991
- ).with({ PREFIXED_NAME: l.when(d) }, ({ PREFIXED_NAME: t }) => _(t[0], !0)).with({ PREFIX_ONLY: l.when(d) }, ({ PREFIX_ONLY: t }) => _(t[0], !0)).with({ IDENTIFIER: l.when(d) }, ({ IDENTIFIER: t }) => _(t[0], !1)).with({ DEFAULT_NS_IRI: l.when(d) }, ({ DEFAULT_NS_IRI: t }) => _(t[0], !0)).with(
1992
- { INTERNAL_FUNCTION: l.when(d) },
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) },
1993
1993
  ({ INTERNAL_FUNCTION: t }) => _(t[0], !1)
1994
1994
  ).otherwise(() => {
1995
1995
  throw new Error("Unknown IRI type");
@@ -2004,7 +2004,7 @@ function fn(e, t) {
2004
2004
  }
2005
2005
  class gn extends En {
2006
2006
  rule(t) {
2007
- const r = this.visit(O(t.ruleHead, "Rule missing head")), i = t.ruleBody?.[0] ? this.visit(t.ruleBody) : [];
2007
+ const r = this.visit(x(t.ruleHead, "Rule missing head")), i = t.ruleBody?.[0] ? this.visit(t.ruleBody) : [];
2008
2008
  return { head: r, body: i };
2009
2009
  }
2010
2010
  ruleHead(t) {
@@ -2112,13 +2112,13 @@ class gn extends En {
2112
2112
  stringLiteral(t) {
2113
2113
  const r = t.STRING_LITERAL_LONG?.[0], i = t.STRING_LITERAL?.[0], s = r ?? i;
2114
2114
  if (!s) throw new Error("Unknown string literal format");
2115
- const o = r ? this.unquoteTripleString(s.image) : this.unquoteString(s.image), a = K(s), u = t.LANGTAG?.[0], f = t.iri?.[0] ? je(t.iri[0].children) : void 0, y = u ? K(u).end : f ? K(f.token).end : a.end, m = {
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 = {
2116
2116
  type: "literal",
2117
2117
  value: o,
2118
2118
  termSpan: { start: a.start, end: y },
2119
2119
  valueSpan: fn(s, r ? 3 : 1)
2120
2120
  };
2121
- return u ? m.language = u.image.substring(1) : f && (m.datatype = f.term.value), m;
2121
+ return l ? m.language = l.image.substring(1) : g && (m.datatype = g.term.value), m;
2122
2122
  }
2123
2123
  negation(t) {
2124
2124
  const r = [];
@@ -2154,13 +2154,13 @@ class gn extends En {
2154
2154
  filterAtom(t) {
2155
2155
  return {
2156
2156
  type: "filter",
2157
- expression: this.visit(O(t.expression, "Filter missing expression"))
2157
+ expression: this.visit(x(t.expression, "Filter missing expression"))
2158
2158
  };
2159
2159
  }
2160
2160
  bindAtom(t) {
2161
2161
  return {
2162
2162
  type: "bind",
2163
- expression: this.visit(O(t.expression, "Bind missing expression")),
2163
+ expression: this.visit(x(t.expression, "Bind missing expression")),
2164
2164
  ...this.asTarget(t, "Bind missing variable")
2165
2165
  };
2166
2166
  }
@@ -2169,8 +2169,8 @@ class gn extends En {
2169
2169
  asTarget(t, r) {
2170
2170
  const i = t.VARIABLE?.[0];
2171
2171
  if (i) return { variable: i.image.substring(1) };
2172
- const s = this.visit(O(t.groundedAsTarget, r));
2173
- return { variable: b(s, { stripSimpleLiteralDatatypes: !0 }), groundedTarget: s };
2172
+ const s = this.visit(x(t.groundedAsTarget, r));
2173
+ return { variable: O(s, { stripSimpleLiteralDatatypes: !0 }), groundedTarget: s };
2174
2174
  }
2175
2175
  // A variable-free `term`, so it visits identically.
2176
2176
  groundedAsTarget(t) {
@@ -2179,7 +2179,7 @@ class gn extends En {
2179
2179
  skolemAtom(t) {
2180
2180
  return {
2181
2181
  type: "skolem",
2182
- args: this.visit(O(t.argumentList, "Skolem missing argument list"))
2182
+ args: this.visit(x(t.argumentList, "Skolem missing argument list"))
2183
2183
  };
2184
2184
  }
2185
2185
  aggregate(t) {
@@ -2198,7 +2198,7 @@ class gn extends En {
2198
2198
  // variables ahead of any substituted values preserves source order in practice.
2199
2199
  onClause(t) {
2200
2200
  const r = t.VARIABLE?.map((o) => o.image.substring(1)) ?? [], i = t.groundedAsTarget?.map((o) => this.visit(o)) ?? [], s = i.map(
2201
- (o) => b(o, { stripSimpleLiteralDatatypes: !0 })
2201
+ (o) => O(o, { stripSimpleLiteralDatatypes: !0 })
2202
2202
  );
2203
2203
  return {
2204
2204
  onVars: [...r, ...s],
@@ -2208,12 +2208,12 @@ class gn extends En {
2208
2208
  aggregateBind(t) {
2209
2209
  const r = this.asTarget(t, "AggregateBind missing variable");
2210
2210
  return t.aggregateFunction?.[0] ? { ...this.visit(t.aggregateFunction), ...r } : {
2211
- expression: this.visit(O(t.expression, "AggregateBind missing expression")),
2211
+ expression: this.visit(x(t.expression, "AggregateBind missing expression")),
2212
2212
  ...r
2213
2213
  };
2214
2214
  }
2215
2215
  aggregateFunction(t) {
2216
- return p(t).with({ aggregateFunction1: l.when(d) }, (r) => this.visit(r.aggregateFunction1[0])).with({ aggregateFunction2: l.when(d) }, (r) => this.visit(r.aggregateFunction2[0])).otherwise(() => {
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(() => {
2217
2217
  throw new Error("Unknown aggregate function arity");
2218
2218
  });
2219
2219
  }
@@ -2267,9 +2267,9 @@ class gn extends En {
2267
2267
  ).otherwise(() => {
2268
2268
  throw new Error("Unknown aggregate function");
2269
2269
  }),
2270
- expression: this.visit(O(t.firstExpr?.[0], "AggregateFunction2 missing first expression")),
2270
+ expression: this.visit(x(t.firstExpr?.[0], "AggregateFunction2 missing first expression")),
2271
2271
  secondExpression: this.visit(
2272
- O(t.secondExpr?.[0], "AggregateFunction2 missing second expression")
2272
+ x(t.secondExpr?.[0], "AggregateFunction2 missing second expression")
2273
2273
  ),
2274
2274
  ...t.DISTINCT && { distinct: !0 }
2275
2275
  };
@@ -2312,7 +2312,7 @@ class gn extends En {
2312
2312
  }
2313
2313
  return t.additiveExpression.length > 1 ? {
2314
2314
  type: "binary",
2315
- operator: p(t).with({ EQUALS: l.when(Boolean) }, () => "=").with({ NOT_EQUALS: l.when(Boolean) }, () => "!=").with({ LESS_THAN: l.when(Boolean) }, () => "<").with({ GREATER_THAN: l.when(Boolean) }, () => ">").with({ LESS_THAN_OR_EQUAL: l.when(Boolean) }, () => "<=").with({ GREATER_THAN_OR_EQUAL: l.when(Boolean) }, () => ">=").otherwise(() => "="),
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(() => "="),
2316
2316
  left: r,
2317
2317
  right: t.additiveExpression[1] ? this.visit(t.additiveExpression[1]) : r
2318
2318
  } : r;
@@ -2349,21 +2349,21 @@ class gn extends En {
2349
2349
  }
2350
2350
  unaryExpression(t) {
2351
2351
  return p(t).with(
2352
- { EXCLAMATION: l.when(Boolean) },
2352
+ { EXCLAMATION: u.when(Boolean) },
2353
2353
  () => ({
2354
2354
  type: "unary",
2355
2355
  operator: "!",
2356
2356
  operand: this.visit(t.primaryExpression)
2357
2357
  })
2358
2358
  ).with(
2359
- { PLUS: l.when(Boolean) },
2359
+ { PLUS: u.when(Boolean) },
2360
2360
  () => ({
2361
2361
  type: "unary",
2362
2362
  operator: "+",
2363
2363
  operand: this.visit(t.primaryExpression)
2364
2364
  })
2365
2365
  ).with(
2366
- { MINUS: l.when(Boolean) },
2366
+ { MINUS: u.when(Boolean) },
2367
2367
  () => ({
2368
2368
  type: "unary",
2369
2369
  operator: "-",
@@ -2372,7 +2372,7 @@ class gn extends En {
2372
2372
  ).otherwise(() => this.visit(t.primaryExpression));
2373
2373
  }
2374
2374
  functionCall(t) {
2375
- return p(t).with({ concatFunction: l.when(d) }, (r) => this.visit(r.concatFunction[0])).with({ strFunction: l.when(d) }, (r) => this.visit(r.strFunction[0])).with({ ifFunction: l.when(d) }, (r) => this.visit(r.ifFunction[0])).with({ iriFunction: l.when(d) }, (r) => this.visit(r.iriFunction[0])).with({ skolemFunction: l.when(d) }, (r) => this.visit(r.skolemFunction[0])).with({ roundFunction: l.when(d) }, (r) => this.visit(r.roundFunction[0])).with({ regexFunction: l.when(d) }, (r) => this.visit(r.regexFunction[0])).with({ iri: l.when(d), LPAREN: l.when(d) }, (r) => {
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) => {
2376
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]) : [];
2377
2377
  return { type: "function", name: s, args: o };
2378
2378
  }).otherwise(() => {
@@ -2424,8 +2424,8 @@ class gn extends En {
2424
2424
  }
2425
2425
  regexFunction(t) {
2426
2426
  const r = [
2427
- this.visit(O(t.textExpr, "REGEX missing text expression")),
2428
- this.visit(O(t.patternExpr, "REGEX missing pattern expression"))
2427
+ this.visit(x(t.textExpr, "REGEX missing text expression")),
2428
+ this.visit(x(t.patternExpr, "REGEX missing pattern expression"))
2429
2429
  ];
2430
2430
  return t.flagsExpr?.[0] && r.push(this.visit(t.flagsExpr)), {
2431
2431
  type: "function",
@@ -2437,13 +2437,13 @@ class gn extends En {
2437
2437
  return t.expression.map((r) => this.visit(r));
2438
2438
  }
2439
2439
  primaryExpression(t) {
2440
- return p(t).with({ expression: l.when(d) }, (r) => this.visit(r.expression[0])).with({ functionCall: l.when(d) }, (r) => this.visit(r.functionCall[0])).with({ literal: l.when(d) }, (r) => ({ type: "term", term: this.visit(r.literal[0]) })).with({ VARIABLE: l.when(d) }, (r) => ({
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) => ({
2441
2441
  type: "term",
2442
2442
  term: { type: "variable", name: r.VARIABLE[0].image.substring(1) }
2443
- })).with({ BLANK_NODE: l.when(d) }, (r) => ({
2443
+ })).with({ BLANK_NODE: u.when(d) }, (r) => ({
2444
2444
  type: "term",
2445
2445
  term: { type: "blank", label: r.BLANK_NODE[0].image.substring(2) }
2446
- })).with({ iri: l.when(d) }, (r) => ({ type: "term", term: this.visit(r.iri[0]) })).otherwise(() => {
2446
+ })).with({ iri: u.when(d) }, (r) => ({ type: "term", term: this.visit(r.iri[0]) })).otherwise(() => {
2447
2447
  throw new Error("Unknown primary expression type");
2448
2448
  });
2449
2449
  }
@@ -2480,7 +2480,7 @@ function B(e, t, r) {
2480
2480
  });
2481
2481
  }
2482
2482
  function yt(e, t) {
2483
- p(e).with({ type: l.union("triple", "property", "class", "general") }, (r) => {
2483
+ p(e).with({ type: u.union("triple", "property", "class", "general") }, (r) => {
2484
2484
  I(t, rt(r));
2485
2485
  }).with({ type: "filter" }, (r) => {
2486
2486
  I(t, w(r.expression));
@@ -2498,12 +2498,12 @@ function yt(e, t) {
2498
2498
  }).exhaustive();
2499
2499
  }
2500
2500
  function yr(e, t) {
2501
- p(e).with({ type: l.union("triple", "property", "class", "general") }, (r) => {
2501
+ p(e).with({ type: u.union("triple", "property", "class", "general") }, (r) => {
2502
2502
  I(t, rt(r));
2503
2503
  }).with({ type: "skolem" }, (r) => {
2504
2504
  const i = Kr(r);
2505
2505
  i && t.add(i);
2506
- }).with({ type: l.union("bind", "filter", "negation", "aggregate") }, () => {
2506
+ }).with({ type: u.union("bind", "filter", "negation", "aggregate") }, () => {
2507
2507
  }).exhaustive();
2508
2508
  }
2509
2509
  function yn(e, t, r, i) {
@@ -2537,7 +2537,7 @@ function Ur(e, t, r) {
2537
2537
  });
2538
2538
  }
2539
2539
  function wr(e, t, r) {
2540
- p(e).with({ type: l.union("triple", "property", "class", "general") }, () => {
2540
+ p(e).with({ type: u.union("triple", "property", "class", "general") }, () => {
2541
2541
  }).with({ type: "filter" }, (i) => {
2542
2542
  B(t, w(i.expression), r);
2543
2543
  }).with({ type: "bind" }, (i) => {
@@ -2729,7 +2729,7 @@ export {
2729
2729
  Te as STRING_LITERAL_LONG,
2730
2730
  Vt as SUM,
2731
2731
  ie as TRUE,
2732
- N as VARIABLE,
2732
+ R as VARIABLE,
2733
2733
  Ui as WHITESPACE,
2734
2734
  or as allTokens,
2735
2735
  bs as areRulesEquivalent,
@@ -2798,7 +2798,7 @@ export {
2798
2798
  Vn as isTermExpression,
2799
2799
  xn as isTripleAtom,
2800
2800
  _n as isUnaryExpression,
2801
- v as isVariableTerm,
2801
+ C as isVariableTerm,
2802
2802
  et as isXsdDatatype,
2803
2803
  wi as keywordTokenTypes,
2804
2804
  ns as literalSetComparisonFromExpression,
@@ -2824,7 +2824,7 @@ export {
2824
2824
  Kr as skolemMintedVariable,
2825
2825
  Si as stringLiteralTokenTypes,
2826
2826
  Ns as termTextsEqual,
2827
- b as termToDatalogText,
2827
+ O as termToDatalogText,
2828
2828
  fs as termToSparql,
2829
2829
  ds as termTokenTypes,
2830
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.5",
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",