@traqula/generator-sparql-1-2 0.0.19 → 0.0.21

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/lib/index.cjs CHANGED
@@ -42,7 +42,7 @@ var AstCoreFactory = class {
42
42
  if (filtered.length === 0) {
43
43
  return this.gen();
44
44
  }
45
- const first2 = filtered[0];
45
+ const first2 = filtered.at(0);
46
46
  const last2 = filtered.at(-1);
47
47
  return {
48
48
  sourceLocationType: "source",
@@ -9379,13 +9379,16 @@ var DynamicGenerator = class {
9379
9379
  __context = void 0;
9380
9380
  origSource = "";
9381
9381
  generatedUntil = 0;
9382
- expectsSpace;
9382
+ toEnsure = [];
9383
+ /**
9384
+ * Should not contain empty strings
9385
+ * @protected
9386
+ */
9383
9387
  stringBuilder = [];
9384
9388
  constructor(rules) {
9385
9389
  this.rules = rules;
9386
9390
  for (const rule of Object.values(rules)) {
9387
9391
  this[rule.name] = ((input, context, args) => {
9388
- this.expectsSpace = false;
9389
9392
  this.stringBuilder.length = 0;
9390
9393
  this.origSource = context.origSource;
9391
9394
  this.generatedUntil = context?.offset ?? 0;
@@ -9410,12 +9413,15 @@ var DynamicGenerator = class {
9410
9413
  const generate = () => def.gImpl({
9411
9414
  SUBRULE: this.subrule,
9412
9415
  PRINT: this.print,
9413
- PRINT_SPACE_LEFT: this.printSpaceLeft,
9416
+ ENSURE: this.ensure,
9417
+ ENSURE_EITHER: this.ensureEither,
9418
+ NEW_LINE: this.newLine,
9419
+ HANDLE_LOC: this.handleLoc,
9420
+ CATCHUP: this.catchup,
9414
9421
  PRINT_WORD: this.printWord,
9415
9422
  PRINT_WORDS: this.printWords,
9416
9423
  PRINT_ON_EMPTY: this.printOnEmpty,
9417
- CATCHUP: this.catchup,
9418
- HANDLE_LOC: this.handleLoc
9424
+ PRINT_ON_OWN_LINE: this.printOnOwnLine
9419
9425
  })(ast, this.getSafeContext(), ...arg);
9420
9426
  if (this.factory.isLocalized(ast)) {
9421
9427
  this.handleLoc(ast, generate);
@@ -9453,43 +9459,82 @@ var DynamicGenerator = class {
9453
9459
  }
9454
9460
  this.generatedUntil = Math.max(this.generatedUntil, until);
9455
9461
  };
9462
+ handeEnsured(toPrint) {
9463
+ for (const callBack of this.toEnsure) {
9464
+ callBack(toPrint);
9465
+ }
9466
+ this.toEnsure.length = 0;
9467
+ }
9456
9468
  print = (...args) => {
9457
- const pureArgs = args.filter((x) => x.length > 0);
9458
- if (pureArgs.length > 0) {
9459
- const head2 = pureArgs[0];
9460
- if (this.expectsSpace) {
9461
- this.expectsSpace = false;
9462
- const blanks = /* @__PURE__ */ new Set(["\n", " ", " "]);
9463
- if (this.stringBuilder.length > 0 && !(blanks.has(head2[0]) || blanks.has(this.stringBuilder.at(-1).at(-1)))) {
9464
- this.stringBuilder.push(" ");
9469
+ const joined = args.join("");
9470
+ this.handeEnsured(joined);
9471
+ this.stringBuilder.push(joined);
9472
+ };
9473
+ doesEndWith(subsStr) {
9474
+ const len = subsStr.length;
9475
+ let temp = "";
9476
+ while (temp.length < len && this.stringBuilder.length > 0) {
9477
+ temp = this.stringBuilder.pop() + temp;
9478
+ }
9479
+ this.stringBuilder.push(temp);
9480
+ return temp.endsWith(subsStr);
9481
+ }
9482
+ ensure = (...args) => {
9483
+ const toEnsure = args.join("");
9484
+ if (!this.doesEndWith(toEnsure)) {
9485
+ this.toEnsure.push((willPrint) => {
9486
+ if (!willPrint.startsWith(toEnsure) && !this.doesEndWith(toEnsure)) {
9487
+ this.stringBuilder.push(toEnsure);
9465
9488
  }
9466
- }
9467
- const context = this.getSafeContext();
9468
- if (context[traqulaIndentation] && typeof context[traqulaIndentation] === "number") {
9469
- const indent = context[traqulaIndentation];
9470
- for (const str2 of pureArgs) {
9471
- const [noNl, ...postNl] = str2.split("\n");
9472
- this.stringBuilder.push(noNl);
9473
- for (const subStr of postNl.map((line) => line.trimStart())) {
9474
- this.stringBuilder.push("\n", " ".repeat(indent));
9475
- if (subStr.length > 0) {
9476
- this.stringBuilder.push(subStr);
9477
- }
9478
- }
9489
+ });
9490
+ }
9491
+ };
9492
+ ensureEither = (...args) => {
9493
+ if (args.length === 1) {
9494
+ this.ensure(...args);
9495
+ } else if (args.length > 1 && // Not already matched?
9496
+ !args.some((subStr) => this.doesEndWith(subStr))) {
9497
+ this.toEnsure.push((willPrint) => {
9498
+ if (!args.some((subStr) => willPrint.startsWith(subStr)) && !args.some((subStr) => this.doesEndWith(subStr))) {
9499
+ this.stringBuilder.push(args[0]);
9479
9500
  }
9501
+ });
9502
+ }
9503
+ };
9504
+ pruneEndingBlanks() {
9505
+ let temp = "";
9506
+ while (/^[ \t]*$/u.test(temp) && this.stringBuilder.length > 0) {
9507
+ temp = this.stringBuilder.pop() + temp;
9508
+ }
9509
+ this.print(temp.trimEnd());
9510
+ }
9511
+ newLine = (arg) => {
9512
+ const indentation = this.getSafeContext()[traqulaIndentation] ?? 0;
9513
+ if (indentation === -1) {
9514
+ return;
9515
+ }
9516
+ const force = arg?.force ?? false;
9517
+ this.pruneEndingBlanks();
9518
+ if (force) {
9519
+ this.print("\n", " ".repeat(indentation));
9520
+ } else {
9521
+ let temp = "";
9522
+ while (!temp.includes("\n") && this.stringBuilder.length > 0) {
9523
+ temp = this.stringBuilder.pop() + temp;
9524
+ }
9525
+ if (/\n[ \t]*$/u.test(temp)) {
9526
+ temp = temp.replace(/\n[ \t]*$/u, `
9527
+ ${" ".repeat(indentation)}`);
9528
+ this.print(temp);
9480
9529
  } else {
9481
- this.stringBuilder.push(...pureArgs);
9530
+ this.print(temp, "\n", " ".repeat(indentation));
9482
9531
  }
9483
9532
  }
9484
9533
  };
9485
9534
  printWord = (...args) => {
9486
- this.expectsSpace = true;
9487
- this.print(...args);
9488
- this.expectsSpace = true;
9489
- };
9490
- printSpaceLeft = (...args) => {
9491
- this.expectsSpace = true;
9535
+ this.ensureEither(" ", "\n");
9492
9536
  this.print(...args);
9537
+ this.ensureEither(" ", "\n");
9493
9538
  };
9494
9539
  printWords = (...args) => {
9495
9540
  for (const arg of args) {
@@ -9497,28 +9542,13 @@ var DynamicGenerator = class {
9497
9542
  }
9498
9543
  };
9499
9544
  printOnEmpty = (...args) => {
9500
- let counter = this.stringBuilder.length - 1;
9501
- let onEmpty = true;
9502
- const isEmptyTest = /^[ \t\n]*$/u;
9503
- while (counter >= 0 && onEmpty) {
9504
- const cur = this.stringBuilder[counter];
9505
- const indexOfNl = cur.lastIndexOf("\n");
9506
- if (indexOfNl >= 0) {
9507
- onEmpty = isEmptyTest.test(cur.slice(indexOfNl));
9508
- if (onEmpty) {
9509
- const newVal = cur.slice(0, indexOfNl);
9510
- if (newVal) {
9511
- this.stringBuilder[counter] = cur.slice(0, indexOfNl);
9512
- } else {
9513
- this.stringBuilder.splice(counter, 1);
9514
- }
9515
- }
9516
- break;
9517
- }
9518
- onEmpty = isEmptyTest.test(cur);
9519
- counter--;
9520
- }
9521
- this.print("\n", ...args);
9545
+ this.newLine();
9546
+ this.print(...args);
9547
+ };
9548
+ printOnOwnLine = (...args) => {
9549
+ this.newLine();
9550
+ this.print(...args);
9551
+ this.newLine();
9522
9552
  };
9523
9553
  };
9524
9554
 
@@ -9584,6 +9614,9 @@ var GeneratorBuilder = class _GeneratorBuilder {
9584
9614
  delete this.rules[ruleName];
9585
9615
  return this;
9586
9616
  }
9617
+ getRule(ruleName) {
9618
+ return this.rules[ruleName];
9619
+ }
9587
9620
  /**
9588
9621
  * Merge this grammar GeneratorBuilder with another.
9589
9622
  * It is best to merge the bigger grammar with the smaller one.
@@ -9716,21 +9749,34 @@ var LexerBuilder = class _LexerBuilder {
9716
9749
  }
9717
9750
  };
9718
9751
 
9719
- // ../../packages/core/lib/Transformers.js
9720
- var TransformerType = class {
9721
- clone(obj) {
9722
- const newObj = Object.create(Object.getPrototypeOf(obj));
9723
- Object.defineProperties(newObj, Object.getOwnPropertyDescriptors(obj));
9724
- return newObj;
9752
+ // ../../packages/core/lib/TransformerObject.js
9753
+ var TransformerObject = class _TransformerObject {
9754
+ defaultContext;
9755
+ maxStackSize = 1e6;
9756
+ /**
9757
+ * Creates stateless transformer.
9758
+ * @param defaultContext
9759
+ */
9760
+ constructor(defaultContext = {}) {
9761
+ this.defaultContext = defaultContext;
9725
9762
  }
9726
- safeObjectVisit(value, mapper) {
9727
- if (value && typeof value === "object") {
9728
- if (Array.isArray(value)) {
9729
- return value.map((x) => this.safeObjectVisit(x, mapper));
9730
- }
9731
- return mapper(value);
9763
+ clone(newDefaultContext = {}) {
9764
+ return new _TransformerObject({ ...this.defaultContext, ...newDefaultContext });
9765
+ }
9766
+ /**
9767
+ * Function to shallow clone any type.
9768
+ * @param obj
9769
+ * @protected
9770
+ */
9771
+ cloneObj(obj) {
9772
+ if (obj === null || typeof obj !== "object") {
9773
+ return obj;
9732
9774
  }
9733
- return value;
9775
+ const proto = Object.getPrototypeOf(obj);
9776
+ if (proto === Object.prototype || proto === null) {
9777
+ return { ...obj };
9778
+ }
9779
+ return Object.assign(Object.create(proto), obj);
9734
9780
  }
9735
9781
  /**
9736
9782
  * Recursively transforms all objects that are not arrays. Mapper is called on deeper objects first.
@@ -9742,90 +9788,231 @@ var TransformerType = class {
9742
9788
  * - Default false
9743
9789
  */
9744
9790
  transformObject(startObject, mapper, preVisitor = () => ({})) {
9791
+ const defaults2 = this.defaultContext;
9792
+ const defaultCopyFlag = defaults2.copy ?? true;
9793
+ const defaultContinues = defaults2.continue ?? true;
9794
+ const defaultIgnoreKeys = defaults2.ignoreKeys;
9795
+ const defaultShallowKeys = defaults2.shallowKeys;
9796
+ const defaultDidShortCut = defaults2.shortcut ?? false;
9745
9797
  let didShortCut = false;
9746
- const recurse = (curObject) => {
9747
- const copy3 = this.clone(curObject);
9748
- const context = preVisitor(copy3);
9749
- didShortCut = context.shortcut ?? false;
9750
- const continues = context.continue ?? true;
9751
- if (continues && !didShortCut) {
9752
- for (const [key, value] of Object.entries(copy3)) {
9753
- if (didShortCut) {
9754
- return copy3;
9798
+ const resultWrap = { res: startObject };
9799
+ const stack = [startObject];
9800
+ const stackParent = [resultWrap];
9801
+ const stackParentKey = ["res"];
9802
+ const handleMapperOnLen = [];
9803
+ const mapperCopyStack = [];
9804
+ const mapperOrigStack = [];
9805
+ const mapperParent = [];
9806
+ const mapperParentKey = [];
9807
+ function handleMapper() {
9808
+ while (stack.length === handleMapperOnLen.at(-1)) {
9809
+ handleMapperOnLen.pop();
9810
+ const copyToMap = mapperCopyStack.pop();
9811
+ const origToMap = mapperOrigStack.pop();
9812
+ const parent = mapperParent.pop();
9813
+ const parentKey = mapperParentKey.pop();
9814
+ parent[parentKey] = mapper(copyToMap, origToMap);
9815
+ }
9816
+ }
9817
+ while (stack.length > 0 && stack.length < this.maxStackSize) {
9818
+ const curObject = stack.pop();
9819
+ const curParent = stackParent.pop();
9820
+ const curKey = stackParentKey.pop();
9821
+ if (!didShortCut) {
9822
+ if (Array.isArray(curObject)) {
9823
+ const newArr = [...curObject];
9824
+ handleMapperOnLen.push(stack.length);
9825
+ mapperCopyStack.push(newArr);
9826
+ mapperOrigStack.push(curObject);
9827
+ mapperParent.push(curParent);
9828
+ mapperParentKey.push(curKey);
9829
+ for (let index = curObject.length - 1; index >= 0; index--) {
9830
+ const val = curObject[index];
9831
+ if (val !== null && typeof val === "object") {
9832
+ stack.push(val);
9833
+ stackParent.push(newArr);
9834
+ stackParentKey.push(index.toString());
9835
+ }
9836
+ }
9837
+ handleMapper();
9838
+ continue;
9839
+ }
9840
+ const context = preVisitor(curObject);
9841
+ const copyFlag = context.copy ?? defaultCopyFlag;
9842
+ const continues = context.continue ?? defaultContinues;
9843
+ const ignoreKeys = context.ignoreKeys ?? defaultIgnoreKeys;
9844
+ const shallowKeys = context.shallowKeys ?? defaultShallowKeys;
9845
+ didShortCut = context.shortcut ?? defaultDidShortCut;
9846
+ const copy3 = copyFlag ? this.cloneObj(curObject) : curObject;
9847
+ handleMapperOnLen.push(stack.length);
9848
+ mapperCopyStack.push(copy3);
9849
+ mapperOrigStack.push(curObject);
9850
+ mapperParent.push(curParent);
9851
+ mapperParentKey.push(curKey);
9852
+ if (continues && !didShortCut) {
9853
+ for (const key in copy3) {
9854
+ if (!Object.hasOwn(copy3, key)) {
9855
+ continue;
9856
+ }
9857
+ const val = copy3[key];
9858
+ const onlyShallow = shallowKeys && shallowKeys?.has(key);
9859
+ if (onlyShallow) {
9860
+ copy3[key] = this.cloneObj(val);
9861
+ }
9862
+ if (ignoreKeys && ignoreKeys.has(key)) {
9863
+ continue;
9864
+ }
9865
+ if (!onlyShallow && val !== null && typeof val === "object") {
9866
+ stack.push(val);
9867
+ stackParentKey.push(key);
9868
+ stackParent.push(copy3);
9869
+ }
9755
9870
  }
9756
- copy3[key] = this.safeObjectVisit(value, (obj) => recurse(obj));
9757
9871
  }
9758
9872
  }
9759
- return mapper(copy3);
9760
- };
9761
- return recurse(startObject);
9873
+ handleMapper();
9874
+ }
9875
+ if (stack.length >= this.maxStackSize) {
9876
+ throw new Error("Transform object stack overflowed");
9877
+ }
9878
+ handleMapper();
9879
+ return resultWrap.res;
9762
9880
  }
9763
9881
  /**
9764
9882
  * Visitor that visits all objects. Visits deeper objects first.
9765
9883
  */
9766
9884
  visitObject(startObject, visitor, preVisitor = () => ({})) {
9885
+ const defaults2 = this.defaultContext;
9886
+ const defaultContinues = defaults2.continue ?? true;
9887
+ const defaultIgnoreKeys = defaults2.ignoreKeys;
9888
+ const defaultShortcut = defaults2.shortcut ?? false;
9767
9889
  let didShortCut = false;
9768
- const recurse = (curObject) => {
9769
- const context = preVisitor(curObject);
9770
- didShortCut = context.shortcut ?? false;
9771
- const continues = context.continue ?? true;
9772
- if (continues && !didShortCut) {
9773
- for (const value of Object.values(curObject)) {
9774
- if (didShortCut) {
9775
- return;
9890
+ const stack = [startObject];
9891
+ const handleVisitorOnLen = [];
9892
+ const visitorStack = [];
9893
+ function handleVisitor() {
9894
+ while (stack.length === handleVisitorOnLen.at(-1)) {
9895
+ handleVisitorOnLen.pop();
9896
+ const toVisit = visitorStack.pop();
9897
+ visitor(toVisit);
9898
+ }
9899
+ }
9900
+ while (stack.length > 0 && stack.length < this.maxStackSize) {
9901
+ const curObject = stack.pop();
9902
+ if (!didShortCut) {
9903
+ if (Array.isArray(curObject)) {
9904
+ for (let i = curObject.length - 1; i >= 0; i--) {
9905
+ stack.push(curObject[i]);
9906
+ }
9907
+ handleVisitor();
9908
+ continue;
9909
+ }
9910
+ const context = preVisitor(curObject);
9911
+ didShortCut = context.shortcut ?? defaultShortcut;
9912
+ const continues = context.continue ?? defaultContinues;
9913
+ const ignoreKeys = context.ignoreKeys ?? defaultIgnoreKeys;
9914
+ handleVisitorOnLen.push(stack.length);
9915
+ visitorStack.push(curObject);
9916
+ if (continues && !didShortCut) {
9917
+ for (const key in curObject) {
9918
+ if (!Object.hasOwn(curObject, key)) {
9919
+ continue;
9920
+ }
9921
+ if (ignoreKeys && ignoreKeys.has(key)) {
9922
+ continue;
9923
+ }
9924
+ const val = curObject[key];
9925
+ if (val && typeof val === "object") {
9926
+ stack.push(val);
9927
+ }
9776
9928
  }
9777
- this.safeObjectVisit(value, (obj) => recurse(obj));
9778
9929
  }
9779
9930
  }
9780
- visitor(curObject);
9781
- };
9782
- recurse(startObject);
9931
+ handleVisitor();
9932
+ }
9933
+ if (stack.length >= this.maxStackSize) {
9934
+ throw new Error("Transform object stack overflowed");
9935
+ }
9936
+ handleVisitor();
9937
+ }
9938
+ };
9939
+
9940
+ // ../../packages/core/lib/TransformerTyped.js
9941
+ var TransformerTyped = class _TransformerTyped extends TransformerObject {
9942
+ defaultNodePreVisitor;
9943
+ constructor(defaultContext = {}, defaultNodePreVisitor = {}) {
9944
+ super(defaultContext);
9945
+ this.defaultNodePreVisitor = defaultNodePreVisitor;
9946
+ }
9947
+ clone(newDefaultContext = {}, newDefaultNodePreVisitor = {}) {
9948
+ return new _TransformerTyped({ ...this.defaultContext, ...newDefaultContext }, { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor });
9783
9949
  }
9950
+ /**
9951
+ * Transform a single node.
9952
+ * The transformation calls the preVisitor from starting from the startObject.
9953
+ * The preVisitor can dictate whether transformation should be stopped.
9954
+ * Note that stopping the transformation also prevets further copying.
9955
+ * The transformer itself transforms object starting with the deepest one that can be visited.
9956
+ * The transformer callback is performed on a copy of the original.
9957
+ * @param startObject
9958
+ * @param nodeCallBacks
9959
+ */
9784
9960
  transformNode(startObject, nodeCallBacks) {
9785
- const transformWrapper = (curObject) => {
9786
- const casted = curObject;
9961
+ const transformWrapper = (copy3, orig) => {
9962
+ let ogTransform;
9963
+ const casted = copy3;
9787
9964
  if (casted.type) {
9788
- const ogFunc = nodeCallBacks[casted.type]?.transform;
9789
- if (ogFunc) {
9790
- return ogFunc(casted);
9791
- }
9965
+ ogTransform = nodeCallBacks[casted.type]?.transform;
9792
9966
  }
9793
- return curObject;
9967
+ return ogTransform ? ogTransform(casted, orig) : copy3;
9794
9968
  };
9795
- const preTransformWrapper = (curObject) => {
9969
+ const nodeDefaults = this.defaultNodePreVisitor;
9970
+ const preVisitWrapper = (curObject) => {
9971
+ let ogPreVisit;
9972
+ let nodeContext = {};
9796
9973
  const casted = curObject;
9797
9974
  if (casted.type) {
9798
- const ogFunc = nodeCallBacks[casted.type]?.preVisitor;
9799
- if (ogFunc) {
9800
- return ogFunc(casted);
9801
- }
9975
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
9976
+ nodeContext = nodeDefaults[casted.type] ?? nodeContext;
9802
9977
  }
9803
- return {};
9978
+ return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;
9804
9979
  };
9805
- return this.transformObject(startObject, transformWrapper, preTransformWrapper);
9980
+ return this.transformObject(startObject, transformWrapper, preVisitWrapper);
9806
9981
  }
9982
+ /**
9983
+ * Similar to {@link this.transformNode}, but without copying the startObject.
9984
+ * The pre-visitor visits starting from the root, going deeper, while the actual visitor goes in reverse.
9985
+ * @param startObject
9986
+ * @param nodeCallBacks
9987
+ */
9807
9988
  visitNode(startObject, nodeCallBacks) {
9808
- const visitWrapper = (curObject) => {
9989
+ const visitorWrapper = (curObject) => {
9809
9990
  const casted = curObject;
9810
9991
  if (casted.type) {
9811
- const ogFunc = nodeCallBacks[casted.type]?.visitor;
9812
- if (ogFunc) {
9813
- ogFunc(casted);
9992
+ const ogTransform = nodeCallBacks[casted.type]?.visitor;
9993
+ if (ogTransform) {
9994
+ ogTransform(casted);
9814
9995
  }
9815
9996
  }
9816
9997
  };
9998
+ const nodeDefaults = this.defaultNodePreVisitor;
9817
9999
  const preVisitWrapper = (curObject) => {
10000
+ let ogPreVisit;
10001
+ let nodeContext = {};
9818
10002
  const casted = curObject;
9819
10003
  if (casted.type) {
9820
- const ogFunc = nodeCallBacks[casted.type]?.preVisitor;
9821
- if (ogFunc) {
9822
- return ogFunc(casted);
9823
- }
10004
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
10005
+ nodeContext = nodeDefaults[casted.type] ?? nodeContext;
9824
10006
  }
9825
- return {};
10007
+ return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;
9826
10008
  };
9827
- this.visitObject(startObject, visitWrapper, preVisitWrapper);
10009
+ return this.visitObject(startObject, visitorWrapper, preVisitWrapper);
9828
10010
  }
10011
+ /**
10012
+ * Traverses only selected nodes as returned by the function.
10013
+ * @param currentNode
10014
+ * @param traverse
10015
+ */
9829
10016
  traverseNodes(currentNode, traverse) {
9830
10017
  let didShortCut = false;
9831
10018
  const recurse = (curNode) => {
@@ -9846,11 +10033,27 @@ var TransformerType = class {
9846
10033
  recurse(currentNode);
9847
10034
  }
9848
10035
  };
9849
- var TransformerSubType = class extends TransformerType {
10036
+
10037
+ // ../../packages/core/lib/TransformerSubTyped.js
10038
+ var TransformerSubTyped = class _TransformerSubTyped extends TransformerTyped {
10039
+ constructor(defaultContext = {}, defaultNodePreVisitor = {}) {
10040
+ super(defaultContext, defaultNodePreVisitor);
10041
+ }
10042
+ clone(newDefaultContext = {}, newDefaultNodePreVisitor = {}) {
10043
+ return new _TransformerSubTyped({ ...this.defaultContext, ...newDefaultContext }, { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor });
10044
+ }
10045
+ /**
10046
+ * Shares the functionality and first two arguments with {@link this.transformNode}.
10047
+ * The third argument allows you to also transform based on the subType of objects.
10048
+ * Note that when a callback for the subtype is provided, the callback for the general type is **NOT** executed.
10049
+ * @param startObject
10050
+ * @param nodeCallBacks
10051
+ * @param nodeSpecificCallBacks
10052
+ */
9850
10053
  transformNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
9851
- const transformWrapper = (curObject) => {
10054
+ const transformWrapper = (copy3, orig) => {
9852
10055
  let ogTransform;
9853
- const casted = curObject;
10056
+ const casted = copy3;
9854
10057
  if (casted.type && casted.subType) {
9855
10058
  const specific = nodeSpecificCallBacks[casted.type];
9856
10059
  if (specific) {
@@ -9860,7 +10063,7 @@ var TransformerSubType = class extends TransformerType {
9860
10063
  ogTransform = nodeCallBacks[casted.type]?.transform;
9861
10064
  }
9862
10065
  }
9863
- return ogTransform ? ogTransform(casted) : curObject;
10066
+ return ogTransform ? ogTransform(casted, orig) : copy3;
9864
10067
  };
9865
10068
  const preVisitWrapper = (curObject) => {
9866
10069
  let ogPreVisit;
@@ -9874,12 +10077,13 @@ var TransformerSubType = class extends TransformerType {
9874
10077
  ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
9875
10078
  }
9876
10079
  }
9877
- return ogPreVisit ? ogPreVisit(casted) : curObject;
10080
+ return ogPreVisit ? ogPreVisit(casted) : {};
9878
10081
  };
9879
10082
  return this.transformObject(startObject, transformWrapper, preVisitWrapper);
9880
10083
  }
9881
10084
  /**
9882
- * When both nodeCallBack and NodeSpecific callBack are matched, will only look at nodeSpecifCallback
10085
+ * Similar to {@link this.visitNode} but also allows you to match based on the subtype of objects.
10086
+ * When both nodeCallBack and NodeSpecific callBack are matched, will only visit nodeSpecifCallback
9883
10087
  */
9884
10088
  visitNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
9885
10089
  const visitWrapper = (curObject) => {
@@ -9910,10 +10114,16 @@ var TransformerSubType = class extends TransformerType {
9910
10114
  ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
9911
10115
  }
9912
10116
  }
9913
- return ogPreVisit ? ogPreVisit(casted) : curObject;
10117
+ return ogPreVisit ? ogPreVisit(casted) : {};
9914
10118
  };
9915
10119
  this.visitObject(startObject, visitWrapper, preVisitWrapper);
9916
10120
  }
10121
+ /**
10122
+ * Similar to {@link this.traverseNodes} but also allows you to match based on the subtype of objects.
10123
+ * @param currentNode
10124
+ * @param traverseNode
10125
+ * @param traverseSubNode
10126
+ */
9917
10127
  traverseSubNodes(currentNode, traverseNode, traverseSubNode) {
9918
10128
  let didShortCut = false;
9919
10129
  const recurse = (curNode) => {
@@ -10986,8 +11196,8 @@ function PatternFactoryMixin(Base) {
10986
11196
  isPatternOptional(obj) {
10987
11197
  return this.isOfSubType(obj, nodeType5, "optional");
10988
11198
  }
10989
- patternValues(values3, loc) {
10990
- return { type: nodeType5, subType: "values", values: values3, loc };
11199
+ patternValues(variables, values3, loc) {
11200
+ return { type: nodeType5, subType: "values", variables, values: values3, loc };
10991
11201
  }
10992
11202
  isPatternValues(obj) {
10993
11203
  return this.isOfSubType(obj, nodeType5, "values");
@@ -11162,7 +11372,7 @@ function TermFactoryMixin(Base) {
11162
11372
  isTerm(x) {
11163
11373
  return this.isOfType(x, "term");
11164
11374
  }
11165
- blankNode(label, loc) {
11375
+ termBlank(label, loc) {
11166
11376
  const base = {
11167
11377
  type: "term",
11168
11378
  subType: "blankNode",
@@ -11176,7 +11386,7 @@ function TermFactoryMixin(Base) {
11176
11386
  isTermBlank(obj) {
11177
11387
  return this.isOfSubType(obj, nodeType8, "blankNode");
11178
11388
  }
11179
- literalTerm(loc, value, langOrIri) {
11389
+ termLiteral(loc, value, langOrIri) {
11180
11390
  return {
11181
11391
  type: nodeType8,
11182
11392
  subType: "literal",
@@ -11198,7 +11408,7 @@ function TermFactoryMixin(Base) {
11198
11408
  const casted = obj;
11199
11409
  return this.isTermLiteral(obj) && typeof casted.langOrIri === "object" && casted.langOrIri !== null && this.isTermNamed(casted.langOrIri);
11200
11410
  }
11201
- variable(value, loc) {
11411
+ termVariable(value, loc) {
11202
11412
  return {
11203
11413
  type: nodeType8,
11204
11414
  subType: "variable",
@@ -11209,7 +11419,7 @@ function TermFactoryMixin(Base) {
11209
11419
  isTermVariable(obj) {
11210
11420
  return this.isOfSubType(obj, nodeType8, "variable");
11211
11421
  }
11212
- namedNode(loc, value, prefix) {
11422
+ termNamed(loc, value, prefix) {
11213
11423
  const base = {
11214
11424
  type: nodeType8,
11215
11425
  subType: "namedNode",
@@ -11454,7 +11664,7 @@ var CommonIRIs;
11454
11664
  CommonIRIs2["NIL"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil";
11455
11665
  CommonIRIs2["TYPE"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
11456
11666
  })(CommonIRIs || (CommonIRIs = {}));
11457
- var AstTransformer = class extends TransformerSubType {
11667
+ var AstTransformer = class extends TransformerSubTyped {
11458
11668
  };
11459
11669
 
11460
11670
  // ../../packages/rules-sparql-1-1/lib/validation/validators.js
@@ -11582,8 +11792,7 @@ function findPatternBoundedVars(iter, boundedVars) {
11582
11792
  optional: (op) => ({ next: op.patterns }),
11583
11793
  service: (op) => ({ next: [op.name, ...op.patterns] }),
11584
11794
  bind: (op) => ({ next: [op.variable] }),
11585
- graph: (op) => ({ next: [op.name, ...op.patterns] }),
11586
- minus: (op) => ({ next: op.patterns.slice(0, 1) })
11795
+ graph: (op) => ({ next: [op.name, ...op.patterns] })
11587
11796
  },
11588
11797
  term: {
11589
11798
  variable: (op) => {
@@ -11670,17 +11879,20 @@ var rdfLiteral = {
11670
11879
  return OPTION(() => OR([
11671
11880
  { ALT: () => {
11672
11881
  const lang2 = CONSUME(terminals_exports.langTag);
11673
- return ACTION(() => C.astFactory.literalTerm(C.astFactory.sourceLocation(value, lang2), value.value, lang2.image.slice(1).toLowerCase()));
11882
+ return ACTION(() => C.astFactory.termLiteral(C.astFactory.sourceLocation(value, lang2), value.value, lang2.image.slice(1).toLowerCase()));
11674
11883
  } },
11675
11884
  { ALT: () => {
11676
11885
  CONSUME(symbols_exports.hathat);
11677
11886
  const iriVal = SUBRULE1(iri2);
11678
- return ACTION(() => C.astFactory.literalTerm(C.astFactory.sourceLocation(value, iriVal), value.value, iriVal));
11887
+ return ACTION(() => C.astFactory.termLiteral(C.astFactory.sourceLocation(value, iriVal), value.value, iriVal));
11679
11888
  } }
11680
11889
  ])) ?? value;
11681
11890
  },
11682
- gImpl: ({ SUBRULE, PRINT, PRINT_SPACE_LEFT }) => (ast, { astFactory }) => {
11683
- astFactory.printFilter(ast, () => PRINT_SPACE_LEFT(stringEscapedLexical(ast.value)));
11891
+ gImpl: ({ SUBRULE, PRINT, PRINT_WORD }) => (ast, { astFactory }) => {
11892
+ astFactory.printFilter(ast, () => {
11893
+ PRINT_WORD("");
11894
+ PRINT(stringEscapedLexical(ast.value));
11895
+ });
11684
11896
  if (ast.langOrIri) {
11685
11897
  if (typeof ast.langOrIri === "string") {
11686
11898
  astFactory.printFilter(ast, () => PRINT("@", ast.langOrIri));
@@ -11707,7 +11919,7 @@ var numericLiteralUnsigned = {
11707
11919
  { ALT: () => [CONSUME(terminals_exports.decimal), CommonIRIs.DECIMAL] },
11708
11920
  { ALT: () => [CONSUME(terminals_exports.double), CommonIRIs.DOUBLE] }
11709
11921
  ]);
11710
- return ACTION(() => C.astFactory.literalTerm(C.astFactory.sourceLocation(parsed[0]), parsed[0].image, C.astFactory.namedNode(C.astFactory.sourceLocationNoMaterialize(), parsed[1])));
11922
+ return ACTION(() => C.astFactory.termLiteral(C.astFactory.sourceLocation(parsed[0]), parsed[0].image, C.astFactory.termNamed(C.astFactory.sourceLocationNoMaterialize(), parsed[1])));
11711
11923
  }
11712
11924
  };
11713
11925
  var numericLiteralPositive = {
@@ -11718,7 +11930,7 @@ var numericLiteralPositive = {
11718
11930
  { ALT: () => [CONSUME(terminals_exports.decimalPositive), CommonIRIs.DECIMAL] },
11719
11931
  { ALT: () => [CONSUME(terminals_exports.doublePositive), CommonIRIs.DOUBLE] }
11720
11932
  ]);
11721
- return ACTION(() => C.astFactory.literalTerm(C.astFactory.sourceLocation(parsed[0]), parsed[0].image, C.astFactory.namedNode(C.astFactory.sourceLocationNoMaterialize(), parsed[1])));
11933
+ return ACTION(() => C.astFactory.termLiteral(C.astFactory.sourceLocation(parsed[0]), parsed[0].image, C.astFactory.termNamed(C.astFactory.sourceLocationNoMaterialize(), parsed[1])));
11722
11934
  }
11723
11935
  };
11724
11936
  var numericLiteralNegative = {
@@ -11729,7 +11941,7 @@ var numericLiteralNegative = {
11729
11941
  { ALT: () => [CONSUME(terminals_exports.decimalNegative), CommonIRIs.DECIMAL] },
11730
11942
  { ALT: () => [CONSUME(terminals_exports.doubleNegative), CommonIRIs.DOUBLE] }
11731
11943
  ]);
11732
- return ACTION(() => C.astFactory.literalTerm(C.astFactory.sourceLocation(parsed[0]), parsed[0].image, C.astFactory.namedNode(C.astFactory.sourceLocationNoMaterialize(), parsed[1])));
11944
+ return ACTION(() => C.astFactory.termLiteral(C.astFactory.sourceLocation(parsed[0]), parsed[0].image, C.astFactory.termNamed(C.astFactory.sourceLocationNoMaterialize(), parsed[1])));
11733
11945
  }
11734
11946
  };
11735
11947
  var booleanLiteral = {
@@ -11739,7 +11951,7 @@ var booleanLiteral = {
11739
11951
  { ALT: () => CONSUME(true_) },
11740
11952
  { ALT: () => CONSUME(false_) }
11741
11953
  ]);
11742
- return ACTION(() => C.astFactory.literalTerm(C.astFactory.sourceLocation(token), token.image.toLowerCase(), C.astFactory.namedNode(C.astFactory.sourceLocationNoMaterialize(), CommonIRIs.BOOLEAN)));
11954
+ return ACTION(() => C.astFactory.termLiteral(C.astFactory.sourceLocation(token), token.image.toLowerCase(), C.astFactory.termNamed(C.astFactory.sourceLocationNoMaterialize(), CommonIRIs.BOOLEAN)));
11743
11955
  }
11744
11956
  };
11745
11957
  var string = {
@@ -11781,7 +11993,7 @@ var string = {
11781
11993
  return char;
11782
11994
  }
11783
11995
  });
11784
- return F3.literalTerm(F3.sourceLocation(x[0]), value);
11996
+ return F3.termLiteral(F3.sourceLocation(x[0]), value);
11785
11997
  });
11786
11998
  }
11787
11999
  };
@@ -11797,7 +12009,7 @@ var iriFull = {
11797
12009
  name: "iriFull",
11798
12010
  impl: ({ ACTION, CONSUME }) => (C) => {
11799
12011
  const iriToken = CONSUME(terminals_exports.iriRef);
11800
- return ACTION(() => C.astFactory.namedNode(C.astFactory.sourceLocation(iriToken), iriToken.image.slice(1, -1)));
12012
+ return ACTION(() => C.astFactory.termNamed(C.astFactory.sourceLocation(iriToken), iriToken.image.slice(1, -1)));
11801
12013
  },
11802
12014
  gImpl: ({ PRINT }) => (ast, { astFactory: F3 }) => {
11803
12015
  F3.printFilter(ast, () => PRINT("<", ast.value, ">"));
@@ -11810,16 +12022,16 @@ var prefixedName = {
11810
12022
  const longName = CONSUME(terminals_exports.pNameLn);
11811
12023
  return ACTION(() => {
11812
12024
  const [prefix, localName] = longName.image.split(":");
11813
- return C.astFactory.namedNode(C.astFactory.sourceLocation(longName), localName, prefix);
12025
+ return C.astFactory.termNamed(C.astFactory.sourceLocation(longName), localName, prefix);
11814
12026
  });
11815
12027
  } },
11816
12028
  { ALT: () => {
11817
12029
  const shortName = CONSUME(terminals_exports.pNameNs);
11818
- return ACTION(() => C.astFactory.namedNode(C.astFactory.sourceLocation(shortName), "", shortName.image.slice(0, -1)));
12030
+ return ACTION(() => C.astFactory.termNamed(C.astFactory.sourceLocation(shortName), "", shortName.image.slice(0, -1)));
11819
12031
  } }
11820
12032
  ]),
11821
- gImpl: ({ PRINT_WORD }) => (ast, { astFactory: F3 }) => {
11822
- F3.printFilter(ast, () => PRINT_WORD(ast.prefix, ":", ast.value));
12033
+ gImpl: ({ PRINT }) => (ast, { astFactory: F3 }) => {
12034
+ F3.printFilter(ast, () => PRINT(ast.prefix, ":", ast.value));
11823
12035
  }
11824
12036
  };
11825
12037
  var canCreateBlankNodes = Symbol("canCreateBlankNodes");
@@ -11829,11 +12041,11 @@ var blankNode = {
11829
12041
  const result = OR([
11830
12042
  { ALT: () => {
11831
12043
  const labelToken = CONSUME(terminals_exports.blankNodeLabel);
11832
- return ACTION(() => C.astFactory.blankNode(labelToken.image.slice(2), C.astFactory.sourceLocation(labelToken)));
12044
+ return ACTION(() => C.astFactory.termBlank(labelToken.image.slice(2), C.astFactory.sourceLocation(labelToken)));
11833
12045
  } },
11834
12046
  { ALT: () => {
11835
12047
  const anonToken = CONSUME(terminals_exports.anon);
11836
- return ACTION(() => C.astFactory.blankNode(void 0, C.astFactory.sourceLocation(anonToken)));
12048
+ return ACTION(() => C.astFactory.termBlank(void 0, C.astFactory.sourceLocation(anonToken)));
11837
12049
  } }
11838
12050
  ]);
11839
12051
  ACTION(() => {
@@ -11843,15 +12055,15 @@ var blankNode = {
11843
12055
  });
11844
12056
  return result;
11845
12057
  },
11846
- gImpl: ({ PRINT_WORD }) => (ast, { astFactory }) => {
11847
- astFactory.printFilter(ast, () => PRINT_WORD("_:", ast.label.replace(/^e_/u, "")));
12058
+ gImpl: ({ PRINT }) => (ast, { astFactory }) => {
12059
+ astFactory.printFilter(ast, () => PRINT("_:", ast.label.replace(/^e_/u, "")));
11848
12060
  }
11849
12061
  };
11850
12062
  var verbA = {
11851
12063
  name: "VerbA",
11852
12064
  impl: ({ ACTION, CONSUME }) => (C) => {
11853
12065
  const token = CONSUME(a);
11854
- return ACTION(() => C.astFactory.namedNode(C.astFactory.sourceLocation(token), CommonIRIs.TYPE, void 0));
12066
+ return ACTION(() => C.astFactory.termNamed(C.astFactory.sourceLocation(token), CommonIRIs.TYPE, void 0));
11855
12067
  }
11856
12068
  };
11857
12069
 
@@ -11885,10 +12097,10 @@ var baseDecl2 = {
11885
12097
  const val = SUBRULE(iriFull);
11886
12098
  return ACTION(() => C.astFactory.contextDefinitionBase(C.astFactory.sourceLocation(base, val), val));
11887
12099
  },
11888
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F3 }) => {
11889
- F3.printFilter(ast, () => PRINT_WORD("BASE"));
12100
+ gImpl: ({ SUBRULE, PRINT_ON_EMPTY, NEW_LINE }) => (ast, { astFactory: F3 }) => {
12101
+ F3.printFilter(ast, () => PRINT_ON_EMPTY("BASE "));
11890
12102
  SUBRULE(iri2, ast.value);
11891
- F3.printFilter(ast, () => PRINT_WORD("\n"));
12103
+ F3.printFilter(ast, () => NEW_LINE());
11892
12104
  }
11893
12105
  };
11894
12106
  var prefixDecl2 = {
@@ -11899,12 +12111,12 @@ var prefixDecl2 = {
11899
12111
  const value = SUBRULE(iriFull);
11900
12112
  return ACTION(() => C.astFactory.contextDefinitionPrefix(C.astFactory.sourceLocation(prefix, value), name, value));
11901
12113
  },
11902
- gImpl: ({ SUBRULE, PRINT_WORDS }) => (ast, { astFactory: F3 }) => {
12114
+ gImpl: ({ SUBRULE, PRINT_ON_EMPTY, NEW_LINE }) => (ast, { astFactory: F3 }) => {
11903
12115
  F3.printFilter(ast, () => {
11904
- PRINT_WORDS("PREFIX", `${ast.key}:`);
12116
+ PRINT_ON_EMPTY("PREFIX ", `${ast.key}: `);
11905
12117
  });
11906
12118
  SUBRULE(iri2, ast.value);
11907
- F3.printFilter(ast, () => PRINT_WORDS("\n"));
12119
+ F3.printFilter(ast, () => NEW_LINE());
11908
12120
  }
11909
12121
  };
11910
12122
  var verb = {
@@ -11941,10 +12153,10 @@ var var_ = {
11941
12153
  { ALT: () => CONSUME(terminals_exports.var1) },
11942
12154
  { ALT: () => CONSUME(terminals_exports.var2) }
11943
12155
  ]);
11944
- return ACTION(() => C.astFactory.variable(varToken.image.slice(1), C.astFactory.sourceLocation(varToken)));
12156
+ return ACTION(() => C.astFactory.termVariable(varToken.image.slice(1), C.astFactory.sourceLocation(varToken)));
11945
12157
  },
11946
- gImpl: ({ PRINT_WORD }) => (ast, { astFactory: F3 }) => {
11947
- F3.printFilter(ast, () => PRINT_WORD(`?${ast.value}`));
12158
+ gImpl: ({ PRINT }) => (ast, { astFactory: F3 }) => {
12159
+ F3.printFilter(ast, () => PRINT(`?${ast.value}`));
11948
12160
  }
11949
12161
  };
11950
12162
  var graphTerm = {
@@ -11957,7 +12169,7 @@ var graphTerm = {
11957
12169
  { GATE: () => C.parseMode.has("canCreateBlankNodes"), ALT: () => SUBRULE(blankNode) },
11958
12170
  { ALT: () => {
11959
12171
  const tokenNil = CONSUME(terminals_exports.nil);
11960
- return ACTION(() => C.astFactory.namedNode(C.astFactory.sourceLocation(tokenNil), CommonIRIs.NIL));
12172
+ return ACTION(() => C.astFactory.termNamed(C.astFactory.sourceLocation(tokenNil), CommonIRIs.NIL));
11961
12173
  } }
11962
12174
  ]),
11963
12175
  gImpl: ({ SUBRULE }) => (ast, { astFactory: F3 }) => {
@@ -12587,13 +12799,16 @@ function triplesDotSeperated(triplesSameSubjectSubrule) {
12587
12799
  var triplesBlock = {
12588
12800
  name: "triplesBlock",
12589
12801
  impl: (implArgs) => (C) => triplesDotSeperated(triplesSameSubjectPath)(implArgs)(C),
12590
- gImpl: ({ SUBRULE, PRINT_WORD, HANDLE_LOC }) => (ast, { astFactory: F3 }) => {
12802
+ gImpl: ({ SUBRULE, PRINT_WORD, HANDLE_LOC, NEW_LINE }) => (ast, { astFactory: F3 }) => {
12591
12803
  for (const [index, triple] of ast.triples.entries()) {
12592
12804
  HANDLE_LOC(triple, () => {
12593
12805
  const nextTriple = ast.triples.at(index);
12594
12806
  if (F3.isTripleCollection(triple)) {
12595
12807
  SUBRULE(graphNodePath, triple);
12596
- F3.printFilter(triple, () => PRINT_WORD(".\n"));
12808
+ F3.printFilter(triple, () => {
12809
+ PRINT_WORD(".");
12810
+ NEW_LINE();
12811
+ });
12597
12812
  } else {
12598
12813
  SUBRULE(graphNodePath, triple.subject);
12599
12814
  F3.printFilter(triple, () => PRINT_WORD(""));
@@ -12605,11 +12820,17 @@ var triplesBlock = {
12605
12820
  F3.printFilter(triple, () => PRINT_WORD(""));
12606
12821
  SUBRULE(graphNodePath, triple.object);
12607
12822
  if (nextTriple === void 0 || F3.isTripleCollection(nextTriple) || !F3.isSourceLocationNoMaterialize(nextTriple.subject.loc)) {
12608
- F3.printFilter(ast, () => PRINT_WORD(".\n"));
12823
+ F3.printFilter(ast, () => {
12824
+ PRINT_WORD(".");
12825
+ NEW_LINE();
12826
+ });
12609
12827
  } else if (F3.isSourceLocationNoMaterialize(nextTriple.predicate.loc)) {
12610
12828
  F3.printFilter(ast, () => PRINT_WORD(","));
12611
12829
  } else {
12612
- F3.printFilter(ast, () => PRINT_WORD(";\n"));
12830
+ F3.printFilter(ast, () => {
12831
+ PRINT_WORD(";");
12832
+ NEW_LINE();
12833
+ });
12613
12834
  }
12614
12835
  }
12615
12836
  });
@@ -12742,10 +12963,10 @@ function collectionImpl(name, allowPaths) {
12742
12963
  return ACTION(() => {
12743
12964
  const F3 = C.astFactory;
12744
12965
  const triples = [];
12745
- const predFirst = F3.namedNode(F3.sourceLocationNoMaterialize(), CommonIRIs.FIRST, void 0);
12746
- const predRest = F3.namedNode(F3.sourceLocationNoMaterialize(), CommonIRIs.REST, void 0);
12747
- const predNil = F3.namedNode(F3.sourceLocationNoMaterialize(), CommonIRIs.NIL, void 0);
12748
- const listHead = F3.blankNode(void 0, F3.sourceLocationNoMaterialize());
12966
+ const predFirst = F3.termNamed(F3.sourceLocationNoMaterialize(), CommonIRIs.FIRST, void 0);
12967
+ const predRest = F3.termNamed(F3.sourceLocationNoMaterialize(), CommonIRIs.REST, void 0);
12968
+ const predNil = F3.termNamed(F3.sourceLocationNoMaterialize(), CommonIRIs.NIL, void 0);
12969
+ const listHead = F3.termBlank(void 0, F3.sourceLocationNoMaterialize());
12749
12970
  let iterHead = listHead;
12750
12971
  for (const [index, term] of terms.entries()) {
12751
12972
  const lastInList = index === terms.length - 1;
@@ -12755,7 +12976,7 @@ function collectionImpl(name, allowPaths) {
12755
12976
  const nilTriple = F3.triple(iterHead, predRest, predNil);
12756
12977
  triples.push(nilTriple);
12757
12978
  } else {
12758
- const tail = F3.blankNode(void 0, F3.sourceLocationNoMaterialize());
12979
+ const tail = F3.termBlank(void 0, F3.sourceLocationNoMaterialize());
12759
12980
  const linkTriple = F3.triple(iterHead, predRest, tail);
12760
12981
  triples.push(linkTriple);
12761
12982
  iterHead = tail;
@@ -12795,16 +13016,17 @@ function blankNodePropertyListImpl(name, allowPaths) {
12795
13016
  name,
12796
13017
  impl: ({ ACTION, SUBRULE, CONSUME }) => (C) => {
12797
13018
  const startToken = CONSUME(symbols_exports.LSquare);
12798
- const blankNode2 = ACTION(() => C.astFactory.blankNode(void 0, C.astFactory.sourceLocationNoMaterialize()));
13019
+ const blankNode2 = ACTION(() => C.astFactory.termBlank(void 0, C.astFactory.sourceLocationNoMaterialize()));
12799
13020
  const propList = SUBRULE(propertyPathNotEmptyImpl, blankNode2);
12800
13021
  const endToken = CONSUME(symbols_exports.RSquare);
12801
13022
  return ACTION(() => C.astFactory.tripleCollectionBlankNodeProperties(blankNode2, propList, C.astFactory.sourceLocation(startToken, endToken)));
12802
13023
  },
12803
- gImpl: ({ SUBRULE, PRINT, PRINT_WORD, HANDLE_LOC, PRINT_ON_EMPTY }) => (ast, c) => {
13024
+ gImpl: ({ SUBRULE, PRINT, PRINT_WORD, HANDLE_LOC, PRINT_ON_EMPTY, NEW_LINE }) => (ast, c) => {
12804
13025
  const { astFactory: F3, indentInc } = c;
12805
13026
  F3.printFilter(ast, () => {
12806
13027
  c[traqulaIndentation] += indentInc;
12807
- PRINT("[\n");
13028
+ PRINT("[");
13029
+ NEW_LINE();
12808
13030
  });
12809
13031
  for (const triple of ast.triples) {
12810
13032
  HANDLE_LOC(triple, () => {
@@ -12815,7 +13037,10 @@ function blankNodePropertyListImpl(name, allowPaths) {
12815
13037
  }
12816
13038
  F3.printFilter(triple, () => PRINT_WORD(""));
12817
13039
  SUBRULE(graphNodePath, triple.object);
12818
- F3.printFilter(ast, () => PRINT_WORD(";\n"));
13040
+ F3.printFilter(ast, () => {
13041
+ PRINT_WORD(";");
13042
+ NEW_LINE();
13043
+ });
12819
13044
  });
12820
13045
  }
12821
13046
  F3.printFilter(ast, () => {
@@ -12874,18 +13099,19 @@ var groupGraphPattern = {
12874
13099
  const close = CONSUME(symbols_exports.RCurly);
12875
13100
  return ACTION(() => C.astFactory.patternGroup(patterns, C.astFactory.sourceLocation(open, close)));
12876
13101
  },
12877
- gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY }) => (ast, C) => {
13102
+ gImpl: ({ SUBRULE, PRINT_WORD, NEW_LINE, PRINT_ON_OWN_LINE }) => (ast, C) => {
12878
13103
  const { astFactory: F3, indentInc } = C;
12879
13104
  F3.printFilter(ast, () => {
12880
13105
  C[traqulaIndentation] += indentInc;
12881
- PRINT_WORD("{\n");
13106
+ PRINT_WORD("{");
13107
+ NEW_LINE();
12882
13108
  });
12883
13109
  for (const pattern of ast.patterns) {
12884
13110
  SUBRULE(generatePattern, pattern);
12885
13111
  }
12886
13112
  F3.printFilter(ast, () => {
12887
13113
  C[traqulaIndentation] -= indentInc;
12888
- PRINT_ON_EMPTY("}\n");
13114
+ PRINT_ON_OWN_LINE("}");
12889
13115
  });
12890
13116
  }
12891
13117
  };
@@ -13035,12 +13261,15 @@ var bind2 = {
13035
13261
  const close = CONSUME(symbols_exports.RParen);
13036
13262
  return ACTION(() => C.astFactory.patternBind(expressionVal, variable, C.astFactory.sourceLocation(bind3, close)));
13037
13263
  },
13038
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F3 }) => {
13264
+ gImpl: ({ SUBRULE, PRINT_WORD, NEW_LINE }) => (ast, { astFactory: F3 }) => {
13039
13265
  F3.printFilter(ast, () => PRINT_WORD("BIND", "("));
13040
13266
  SUBRULE(expression, ast.expression);
13041
13267
  F3.printFilter(ast, () => PRINT_WORD("AS"));
13042
13268
  SUBRULE(var_, ast.variable);
13043
- F3.printFilter(ast, () => PRINT_WORD(")\n"));
13269
+ F3.printFilter(ast, () => {
13270
+ PRINT_WORD(")");
13271
+ NEW_LINE();
13272
+ });
13044
13273
  }
13045
13274
  };
13046
13275
  var inlineData = {
@@ -13048,34 +13277,46 @@ var inlineData = {
13048
13277
  impl: ({ ACTION, SUBRULE, CONSUME }) => (C) => {
13049
13278
  const values3 = CONSUME(values2);
13050
13279
  const datablock = SUBRULE(dataBlock);
13051
- return ACTION(() => C.astFactory.patternValues(datablock.val, C.astFactory.sourceLocation(values3, datablock)));
13280
+ return ACTION(() => {
13281
+ datablock.loc = C.astFactory.sourceLocation(values3, datablock);
13282
+ return datablock;
13283
+ });
13052
13284
  },
13053
- gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY }) => (ast, C) => {
13285
+ gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY, NEW_LINE, PRINT_ON_OWN_LINE }) => (ast, C) => {
13054
13286
  const { astFactory: F3, indentInc } = C;
13055
- const variables = Object.keys(ast.values.at(0) ?? {});
13287
+ const variables = ast.variables;
13288
+ const singleVar = variables.length === 1;
13289
+ F3.printFilter(ast, () => {
13290
+ PRINT_ON_EMPTY("VALUES", singleVar ? "" : "( ");
13291
+ });
13292
+ for (const variable of variables) {
13293
+ F3.printFilter(ast, () => PRINT_WORD(""));
13294
+ SUBRULE(varOrTerm, variable);
13295
+ F3.printFilter(ast, () => PRINT_WORD(""));
13296
+ }
13056
13297
  F3.printFilter(ast, () => {
13057
- PRINT_ON_EMPTY("");
13058
- PRINT_WORD("VALUES", "(");
13059
- for (const variable of variables) {
13060
- PRINT_WORD(`?${variable}`);
13061
- }
13062
13298
  C[traqulaIndentation] += indentInc;
13063
- PRINT_WORD(")", "{\n");
13299
+ PRINT_WORD(singleVar ? "" : ")", "{");
13300
+ NEW_LINE();
13064
13301
  });
13065
13302
  for (const mapping of ast.values) {
13066
- F3.printFilter(ast, () => PRINT_WORD("("));
13303
+ F3.printFilter(ast, () => !singleVar && PRINT_WORD("("));
13067
13304
  for (const variable of variables) {
13068
- if (mapping[variable] === void 0) {
13305
+ const var_2 = variable.value;
13306
+ if (mapping[var_2] === void 0) {
13069
13307
  F3.printFilter(ast, () => PRINT_WORD("UNDEF"));
13070
13308
  } else {
13071
- SUBRULE(graphNodePath, mapping[variable]);
13309
+ SUBRULE(graphNodePath, mapping[var_2]);
13072
13310
  }
13073
13311
  }
13074
- F3.printFilter(ast, () => PRINT_WORD(")\n"));
13312
+ F3.printFilter(ast, () => {
13313
+ PRINT_WORD(singleVar ? "" : ")");
13314
+ NEW_LINE();
13315
+ });
13075
13316
  }
13076
13317
  F3.printFilter(ast, () => {
13077
13318
  C[traqulaIndentation] -= indentInc;
13078
- PRINT_ON_EMPTY("}\n");
13319
+ PRINT_ON_OWN_LINE("}");
13079
13320
  });
13080
13321
  }
13081
13322
  };
@@ -13099,7 +13340,7 @@ var inlineDataOneVar = {
13099
13340
  });
13100
13341
  });
13101
13342
  const close = CONSUME(symbols_exports.RCurly);
13102
- return ACTION(() => C.astFactory.wrap(res, C.astFactory.sourceLocation(varVal, close)));
13343
+ return ACTION(() => C.astFactory.patternValues([varVal], res, C.astFactory.sourceLocation(varVal, close)));
13103
13344
  }
13104
13345
  };
13105
13346
  var inlineDataFull = {
@@ -13116,7 +13357,7 @@ var inlineDataFull = {
13116
13357
  res.push({});
13117
13358
  });
13118
13359
  const close = CONSUME1(symbols_exports.RCurly);
13119
- return ACTION(() => C.astFactory.wrap(res, C.astFactory.sourceLocation(nil2, close)));
13360
+ return ACTION(() => C.astFactory.patternValues(vars, res, C.astFactory.sourceLocation(nil2, close)));
13120
13361
  } },
13121
13362
  { ALT: () => {
13122
13363
  const open = CONSUME1(symbols_exports.LParen);
@@ -13148,7 +13389,7 @@ var inlineDataFull = {
13148
13389
  });
13149
13390
  });
13150
13391
  const close = CONSUME2(symbols_exports.RCurly);
13151
- return ACTION(() => C.astFactory.wrap(res, C.astFactory.sourceLocation(open, close)));
13392
+ return ACTION(() => C.astFactory.patternValues(vars, res, C.astFactory.sourceLocation(open, close)));
13152
13393
  } }
13153
13394
  ]);
13154
13395
  }
@@ -13211,10 +13452,13 @@ var filter3 = {
13211
13452
  const expression2 = SUBRULE(constraint);
13212
13453
  return ACTION(() => C.astFactory.patternFilter(expression2, C.astFactory.sourceLocation(filterToken, expression2)));
13213
13454
  },
13214
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F3 }) => {
13455
+ gImpl: ({ SUBRULE, PRINT_WORD, NEW_LINE }) => (ast, { astFactory: F3 }) => {
13215
13456
  F3.printFilter(ast, () => PRINT_WORD("FILTER ("));
13216
13457
  SUBRULE(expression, ast.expression);
13217
- F3.printFilter(ast, () => PRINT_WORD(")\n"));
13458
+ F3.printFilter(ast, () => {
13459
+ PRINT_WORD(")");
13460
+ NEW_LINE();
13461
+ });
13218
13462
  }
13219
13463
  };
13220
13464
  var constraint = {
@@ -13600,8 +13844,7 @@ var groupClause = {
13600
13844
  },
13601
13845
  gImpl: ({ PRINT_WORDS, SUBRULE, PRINT_ON_EMPTY }) => (ast, { astFactory: F3 }) => {
13602
13846
  F3.printFilter(ast, () => {
13603
- PRINT_ON_EMPTY("");
13604
- PRINT_WORDS("GROUP", "BY");
13847
+ PRINT_ON_EMPTY("GROUP BY ");
13605
13848
  });
13606
13849
  for (const grouping of ast.groupings) {
13607
13850
  if (F3.isExpression(grouping)) {
@@ -13657,10 +13900,9 @@ var havingClause = {
13657
13900
  ACTION(() => !couldParseAgg && C.parseMode.delete("canParseAggregate"));
13658
13901
  return ACTION(() => C.astFactory.solutionModifierHaving(expressions, C.astFactory.sourceLocation(having2, expressions.at(-1))));
13659
13902
  },
13660
- gImpl: ({ PRINT_WORD, PRINT_ON_EMPTY, SUBRULE }) => (ast, { astFactory: F3 }) => {
13903
+ gImpl: ({ PRINT_ON_EMPTY, SUBRULE }) => (ast, { astFactory: F3 }) => {
13661
13904
  F3.printFilter(ast, () => {
13662
- PRINT_ON_EMPTY("");
13663
- PRINT_WORD("HAVING");
13905
+ PRINT_ON_EMPTY("HAVING ");
13664
13906
  });
13665
13907
  for (const having2 of ast.having) {
13666
13908
  SUBRULE(expression, having2);
@@ -13686,8 +13928,7 @@ var orderClause = {
13686
13928
  },
13687
13929
  gImpl: ({ PRINT_WORDS, PRINT_ON_EMPTY, SUBRULE }) => (ast, { astFactory: F3 }) => {
13688
13930
  F3.printFilter(ast, () => {
13689
- PRINT_ON_EMPTY("");
13690
- PRINT_WORDS("ORDER", "BY");
13931
+ PRINT_ON_EMPTY("ORDER BY ");
13691
13932
  });
13692
13933
  for (const ordering of ast.orderDefs) {
13693
13934
  if (ordering.descending) {
@@ -13746,9 +13987,9 @@ var limitOffsetClauses = {
13746
13987
  return ACTION(() => C.astFactory.solutionModifierLimitOffset(limit2?.val, offset2.val, C.astFactory.sourceLocation(offset2, limit2)));
13747
13988
  } }
13748
13989
  ]),
13749
- gImpl: ({ PRINT_WORDS, PRINT_ON_EMPTY }) => (ast, { astFactory: F3 }) => {
13990
+ gImpl: ({ PRINT_WORDS, NEW_LINE }) => (ast, { astFactory: F3 }) => {
13750
13991
  F3.printFilter(ast, () => {
13751
- PRINT_ON_EMPTY("");
13992
+ NEW_LINE();
13752
13993
  if (ast.limit) {
13753
13994
  PRINT_WORDS("LIMIT", String(ast.limit));
13754
13995
  }
@@ -13933,9 +14174,9 @@ var selectClause = {
13933
14174
  ACTION(() => !couldParseAgg && C.parseMode.delete("canParseAggregate"));
13934
14175
  return ACTION(() => C.astFactory.wrap(val, C.astFactory.sourceLocation(select2, last2)));
13935
14176
  },
13936
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F3 }) => {
14177
+ gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY }) => (ast, { astFactory: F3 }) => {
13937
14178
  F3.printFilter(ast, () => {
13938
- PRINT_WORD("SELECT");
14179
+ PRINT_ON_EMPTY("SELECT ");
13939
14180
  if (ast.val.distinct) {
13940
14181
  PRINT_WORD("DISTINCT");
13941
14182
  } else if (ast.val.reduced) {
@@ -13954,7 +14195,9 @@ var selectClause = {
13954
14195
  SUBRULE(var_, variable.variable);
13955
14196
  F3.printFilter(ast, () => PRINT_WORD(")"));
13956
14197
  }
14198
+ F3.printFilter(ast, () => PRINT_WORD(""));
13957
14199
  }
14200
+ F3.printFilter(ast, () => PRINT_WORD(""));
13958
14201
  }
13959
14202
  };
13960
14203
  var constructQuery = {
@@ -13992,18 +14235,19 @@ var constructQuery = {
13992
14235
  } }
13993
14236
  ]);
13994
14237
  },
13995
- gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY }) => (ast, C) => {
14238
+ gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY, PRINT_ON_OWN_LINE, NEW_LINE }) => (ast, C) => {
13996
14239
  const { astFactory: F3, indentInc } = C;
13997
- F3.printFilter(ast, () => PRINT_WORD("CONSTRUCT"));
14240
+ F3.printFilter(ast, () => PRINT_ON_EMPTY("CONSTRUCT "));
13998
14241
  if (!F3.isSourceLocationNoMaterialize(ast.where.loc)) {
13999
14242
  F3.printFilter(ast, () => {
14000
14243
  C[traqulaIndentation] += indentInc;
14001
- PRINT_WORD("{\n");
14244
+ PRINT_WORD("{");
14245
+ NEW_LINE();
14002
14246
  });
14003
14247
  SUBRULE(triplesBlock, ast.template);
14004
14248
  F3.printFilter(ast, () => {
14005
14249
  C[traqulaIndentation] -= indentInc;
14006
- PRINT_ON_EMPTY("}\n");
14250
+ PRINT_ON_OWN_LINE("}");
14007
14251
  });
14008
14252
  }
14009
14253
  SUBRULE(datasetClauseStar, ast.datasets);
@@ -14044,8 +14288,8 @@ var describeQuery = {
14044
14288
  loc: C.astFactory.sourceLocation(describe2, ...variables, from2, where2, modifiers.group, modifiers.having, modifiers.order, modifiers.limitOffset)
14045
14289
  }));
14046
14290
  },
14047
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F3 }) => {
14048
- F3.printFilter(ast, () => PRINT_WORD("DESCRIBE"));
14291
+ gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY }) => (ast, { astFactory: F3 }) => {
14292
+ F3.printFilter(ast, () => PRINT_ON_EMPTY("DESCRIBE "));
14049
14293
  if (F3.isWildcard(ast.variables[0])) {
14050
14294
  F3.printFilter(ast, () => PRINT_WORD("*"));
14051
14295
  } else {
@@ -14075,8 +14319,8 @@ var askQuery = {
14075
14319
  loc: C.astFactory.sourceLocation(ask2, from2, where2, modifiers.group, modifiers.having, modifiers.order, modifiers.limitOffset)
14076
14320
  }));
14077
14321
  },
14078
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F3 }) => {
14079
- F3.printFilter(ast, () => PRINT_WORD("ASK"));
14322
+ gImpl: ({ SUBRULE, PRINT_ON_EMPTY }) => (ast, { astFactory: F3 }) => {
14323
+ F3.printFilter(ast, () => PRINT_ON_EMPTY("ASK "));
14080
14324
  SUBRULE(datasetClauseStar, ast.datasets);
14081
14325
  SUBRULE(whereClause, F3.wrap(ast.where, ast.loc));
14082
14326
  SUBRULE(solutionModifier, ast.solutionModifiers);
@@ -14135,7 +14379,7 @@ var update = {
14135
14379
  return update2;
14136
14380
  });
14137
14381
  },
14138
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F3 }) => {
14382
+ gImpl: ({ SUBRULE, PRINT, NEW_LINE }) => (ast, { astFactory: F3 }) => {
14139
14383
  const [head2, ...tail] = ast.updates;
14140
14384
  if (head2) {
14141
14385
  SUBRULE(prologue, head2.context);
@@ -14144,7 +14388,10 @@ var update = {
14144
14388
  }
14145
14389
  }
14146
14390
  for (const update2 of tail) {
14147
- F3.printFilter(ast, () => PRINT_WORD(";\n"));
14391
+ F3.printFilter(ast, () => {
14392
+ PRINT(";");
14393
+ NEW_LINE();
14394
+ });
14148
14395
  SUBRULE(prologue, update2.context);
14149
14396
  if (update2.operation) {
14150
14397
  SUBRULE(update1, update2.operation);
@@ -14217,9 +14464,9 @@ var load2 = {
14217
14464
  });
14218
14465
  return ACTION(() => C.astFactory.updateOperationLoad(C.astFactory.sourceLocation(loadToken, source, destination), source, Boolean(silent2), destination));
14219
14466
  },
14220
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F3 }) => {
14467
+ gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY }) => (ast, { astFactory: F3 }) => {
14221
14468
  F3.printFilter(ast, () => {
14222
- PRINT_WORD("LOAD");
14469
+ PRINT_ON_EMPTY("LOAD ");
14223
14470
  if (ast.silent) {
14224
14471
  PRINT_WORD("SILENT");
14225
14472
  }
@@ -14240,9 +14487,9 @@ function clearOrDrop(operation) {
14240
14487
  const destination = SUBRULE1(graphRefAll);
14241
14488
  return ACTION(() => C.astFactory.updateOperationClearDrop(unCapitalize(operation.name), Boolean(silent2), destination, C.astFactory.sourceLocation(opToken, destination)));
14242
14489
  },
14243
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F3 }) => {
14490
+ gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY }) => (ast, { astFactory: F3 }) => {
14244
14491
  F3.printFilter(ast, () => {
14245
- PRINT_WORD(operation.name.toUpperCase());
14492
+ PRINT_ON_EMPTY(operation.name.toUpperCase(), " ");
14246
14493
  if (ast.silent) {
14247
14494
  PRINT_WORD("SILENT");
14248
14495
  }
@@ -14261,9 +14508,9 @@ var create2 = {
14261
14508
  const destination = SUBRULE1(graphRef);
14262
14509
  return ACTION(() => C.astFactory.updateOperationCreate(destination, Boolean(silent2), C.astFactory.sourceLocation(createToken3, destination)));
14263
14510
  },
14264
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F3 }) => {
14511
+ gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY }) => (ast, { astFactory: F3 }) => {
14265
14512
  F3.printFilter(ast, () => {
14266
- PRINT_WORD("CREATE");
14513
+ PRINT_ON_EMPTY("CREATE ");
14267
14514
  if (ast.silent) {
14268
14515
  PRINT_WORD("SILENT");
14269
14516
  }
@@ -14282,9 +14529,9 @@ function copyMoveAddOperation(operation) {
14282
14529
  const destination = SUBRULE2(graphOrDefault);
14283
14530
  return ACTION(() => C.astFactory.updateOperationAddMoveCopy(unCapitalize(operation.name), source, destination, Boolean(silent2), C.astFactory.sourceLocation(op, destination)));
14284
14531
  },
14285
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F3 }) => {
14532
+ gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY }) => (ast, { astFactory: F3 }) => {
14286
14533
  F3.printFilter(ast, () => {
14287
- PRINT_WORD(operation.name.toUpperCase());
14534
+ PRINT_ON_EMPTY(operation.name.toUpperCase(), " ");
14288
14535
  if (ast.silent) {
14289
14536
  PRINT_WORD("SILENT");
14290
14537
  }
@@ -14333,23 +14580,24 @@ function insertDeleteDelWhere(name, subType, cons1, dataRule) {
14333
14580
  }
14334
14581
  return ACTION(() => C.astFactory.updateOperationInsDelDataWhere(subType, data.val, C.astFactory.sourceLocation(insDelToken, data)));
14335
14582
  },
14336
- gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY }) => (ast, C) => {
14583
+ gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY, PRINT_ON_OWN_LINE, NEW_LINE }) => (ast, C) => {
14337
14584
  const { astFactory: F3, indentInc } = C;
14338
14585
  F3.printFilter(ast, () => {
14339
- C[traqulaIndentation] += indentInc;
14340
14586
  if (subType === "insertdata") {
14341
- PRINT_WORD("INSERT DATA");
14587
+ PRINT_ON_EMPTY("INSERT DATA ");
14342
14588
  } else if (subType === "deletedata") {
14343
- PRINT_WORD("DELETE DATA");
14589
+ PRINT_ON_EMPTY("DELETE DATA ");
14344
14590
  } else if (subType === "deletewhere") {
14345
- PRINT_WORD("DELETE WHERE");
14591
+ PRINT_ON_EMPTY("DELETE WHERE ");
14346
14592
  }
14347
- PRINT_WORD("{\n");
14593
+ C[traqulaIndentation] += indentInc;
14594
+ PRINT_WORD("{");
14595
+ NEW_LINE();
14348
14596
  });
14349
14597
  SUBRULE(quads, F3.wrap(ast.data, ast.loc));
14350
14598
  F3.printFilter(ast, () => {
14351
14599
  C[traqulaIndentation] -= indentInc;
14352
- PRINT_ON_EMPTY("}\n");
14600
+ PRINT_ON_OWN_LINE("}");
14353
14601
  });
14354
14602
  }
14355
14603
  };
@@ -14381,36 +14629,40 @@ var modify = {
14381
14629
  const where2 = SUBRULE1(groupGraphPattern);
14382
14630
  return ACTION(() => C.astFactory.updateOperationModify(C.astFactory.sourceLocation(graph2?.withToken, del, insert, where2), insert?.val ?? [], del?.val ?? [], where2, using, graph2?.graph));
14383
14631
  },
14384
- gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY }) => (ast, C) => {
14632
+ gImpl: ({ SUBRULE, PRINT_WORDS, PRINT_ON_EMPTY, NEW_LINE }) => (ast, C) => {
14385
14633
  const { astFactory: F3, indentInc } = C;
14386
14634
  if (ast.graph) {
14387
- F3.printFilter(ast, () => PRINT_WORD("WITH"));
14635
+ F3.printFilter(ast, () => PRINT_WORDS("WITH"));
14388
14636
  SUBRULE(iri2, ast.graph);
14389
14637
  }
14390
14638
  if (ast.delete.length > 0) {
14391
14639
  F3.printFilter(ast, () => {
14392
14640
  C[traqulaIndentation] += indentInc;
14393
- PRINT_WORD("DELETE", "{\n");
14641
+ PRINT_WORDS("DELETE", "{");
14642
+ NEW_LINE();
14394
14643
  });
14395
14644
  SUBRULE(quads, F3.wrap(ast.delete, ast.loc));
14396
14645
  F3.printFilter(ast, () => {
14397
14646
  C[traqulaIndentation] -= indentInc;
14398
- PRINT_ON_EMPTY("}\n");
14647
+ PRINT_ON_EMPTY("}");
14648
+ NEW_LINE();
14399
14649
  });
14400
14650
  }
14401
14651
  if (ast.insert.length > 0) {
14402
14652
  F3.printFilter(ast, () => {
14403
14653
  C[traqulaIndentation] += indentInc;
14404
- PRINT_WORD("INSERT", "{\n");
14654
+ PRINT_WORDS("INSERT", "{");
14655
+ NEW_LINE();
14405
14656
  });
14406
14657
  SUBRULE(quads, F3.wrap(ast.insert, ast.loc));
14407
14658
  F3.printFilter(ast, () => {
14408
14659
  C[traqulaIndentation] -= indentInc;
14409
- PRINT_ON_EMPTY("}\n");
14660
+ PRINT_ON_EMPTY("} ");
14661
+ NEW_LINE();
14410
14662
  });
14411
14663
  }
14412
14664
  SUBRULE(usingClauseStar, ast.from);
14413
- F3.printFilter(ast, () => PRINT_WORD("WHERE"));
14665
+ F3.printFilter(ast, () => PRINT_WORDS("WHERE"));
14414
14666
  SUBRULE(groupGraphPattern, ast.where);
14415
14667
  }
14416
14668
  };
@@ -14534,18 +14786,19 @@ var quadsNotTriples = {
14534
14786
  const close = CONSUME(symbols_exports.RCurly);
14535
14787
  return ACTION(() => C.astFactory.graphQuads(name, triples ?? C.astFactory.patternBgp([], C.astFactory.sourceLocationNoMaterialize()), C.astFactory.sourceLocation(graph2, close)));
14536
14788
  },
14537
- gImpl: ({ SUBRULE, PRINT_WORD, PRINT_ON_EMPTY }) => (ast, C) => {
14789
+ gImpl: ({ SUBRULE, PRINT_WORD, NEW_LINE, PRINT_ON_OWN_LINE }) => (ast, C) => {
14538
14790
  const { astFactory: F3, indentInc } = C;
14539
14791
  F3.printFilter(ast, () => PRINT_WORD("GRAPH"));
14540
14792
  SUBRULE(varOrTerm, ast.graph);
14541
14793
  F3.printFilter(ast, () => {
14542
14794
  C[traqulaIndentation] += indentInc;
14543
- PRINT_WORD("{\n");
14795
+ PRINT_WORD("{");
14796
+ NEW_LINE();
14544
14797
  });
14545
14798
  SUBRULE(triplesBlock, ast.triples);
14546
14799
  F3.printFilter(ast, () => {
14547
14800
  C[traqulaIndentation] -= indentInc;
14548
- PRINT_ON_EMPTY("}\n");
14801
+ PRINT_ON_OWN_LINE("}");
14549
14802
  });
14550
14803
  }
14551
14804
  };
@@ -14725,7 +14978,7 @@ var AstFactory2 = class extends AstFactory {
14725
14978
  type: "tripleCollection",
14726
14979
  subType: "reifiedTriple",
14727
14980
  triples: [this.triple(subject, predicate, object3)],
14728
- identifier: reifier2 ?? this.blankNode(void 0, this.sourceLocationNoMaterialize()),
14981
+ identifier: reifier2 ?? this.termBlank(void 0, this.sourceLocationNoMaterialize()),
14729
14982
  loc
14730
14983
  };
14731
14984
  }
@@ -14800,9 +15053,9 @@ var versionDecl = {
14800
15053
  const identifier = SUBRULE(versionSpecifier);
14801
15054
  return ACTION(() => C.astFactory.contextDefinitionVersion(identifier.val, C.astFactory.sourceLocation(versionToken, identifier)));
14802
15055
  },
14803
- gImpl: ({ PRINT_WORDS }) => (ast, { astFactory: F3 }) => {
15056
+ gImpl: ({ PRINT_ON_OWN_LINE }) => (ast, { astFactory: F3 }) => {
14804
15057
  F3.printFilter(ast, () => {
14805
- PRINT_WORDS("VERSION", `${grammar_exports.stringEscapedLexical(ast.version)}`, "\n");
15058
+ PRINT_ON_OWN_LINE("VERSION ", `${grammar_exports.stringEscapedLexical(ast.version)}`);
14806
15059
  });
14807
15060
  }
14808
15061
  };
@@ -14869,7 +15122,7 @@ var reifier = {
14869
15122
  if (reifier2 === void 0 && !C.parseMode.has("canCreateBlankNodes")) {
14870
15123
  throw new Error("Cannot create blanknodes in current parse mode");
14871
15124
  }
14872
- return C.astFactory.wrap(reifier2 ?? C.astFactory.blankNode(void 0, C.astFactory.sourceLocation()), C.astFactory.sourceLocation(tildeToken, reifier2));
15125
+ return C.astFactory.wrap(reifier2 ?? C.astFactory.termBlank(void 0, C.astFactory.sourceLocation()), C.astFactory.sourceLocation(tildeToken, reifier2));
14873
15126
  });
14874
15127
  }
14875
15128
  };
@@ -14928,7 +15181,7 @@ function annotationImpl(name, allowPaths) {
14928
15181
  if (!currentReifier && !C.parseMode.has("canCreateBlankNodes")) {
14929
15182
  throw new Error("Cannot create blanknodes in current parse mode");
14930
15183
  }
14931
- currentReifier = currentReifier ?? C.astFactory.blankNode(void 0, C.astFactory.sourceLocation());
15184
+ currentReifier = currentReifier ?? C.astFactory.termBlank(void 0, C.astFactory.sourceLocation());
14932
15185
  });
14933
15186
  const block = SUBRULE(allowPaths ? annotationBlockPath : annotationBlock, currentReifier);
14934
15187
  ACTION(() => {
@@ -14963,13 +15216,13 @@ function annotationBlockImpl(name, allowPaths) {
14963
15216
  const close = CONSUME(annotationClose);
14964
15217
  return ACTION(() => C.astFactory.tripleCollectionBlankNodeProperties(arg, res, C.astFactory.sourceLocation(open, close)));
14965
15218
  },
14966
- gImpl: ({ SUBRULE, PRINT_WORD, HANDLE_LOC, PRINT_ON_EMPTY }) => (ast, C) => {
15219
+ gImpl: ({ SUBRULE, PRINT_WORD, HANDLE_LOC, NEW_LINE, PRINT_ON_OWN_LINE }) => (ast, C) => {
14967
15220
  const { astFactory: F3, indentInc } = C;
14968
15221
  F3.printFilter(ast, () => {
14969
15222
  PRINT_WORD("{|");
14970
15223
  if (ast.triples.length > 1) {
14971
15224
  C[traqulaIndentation] += indentInc;
14972
- PRINT_WORD("\n");
15225
+ NEW_LINE();
14973
15226
  }
14974
15227
  });
14975
15228
  function printTriple(triple) {
@@ -14979,18 +15232,22 @@ function annotationBlockImpl(name, allowPaths) {
14979
15232
  } else {
14980
15233
  SUBRULE(grammar_exports.pathGenerator, triple.predicate, void 0);
14981
15234
  }
15235
+ F3.printFilter(triple, () => PRINT_WORD(""));
14982
15236
  SUBRULE(graphNodePath2, triple.object);
14983
15237
  });
14984
15238
  }
14985
15239
  const [head2, ...tail] = ast.triples;
14986
15240
  printTriple(head2);
14987
15241
  for (const triple of tail) {
14988
- F3.printFilter(ast, () => PRINT_WORD(";\n"));
15242
+ F3.printFilter(ast, () => {
15243
+ PRINT_WORD(";");
15244
+ NEW_LINE();
15245
+ });
14989
15246
  printTriple(triple);
14990
15247
  }
14991
15248
  F3.printFilter(ast, () => {
14992
15249
  if (ast.triples.length > 1) {
14993
- PRINT_ON_EMPTY("|}\n");
15250
+ PRINT_ON_OWN_LINE("|}");
14994
15251
  } else {
14995
15252
  PRINT_WORD("|}");
14996
15253
  }
@@ -15032,7 +15289,7 @@ var varOrTerm2 = {
15032
15289
  { ALT: () => SUBRULE(grammar_exports.blankNode) },
15033
15290
  { ALT: () => {
15034
15291
  const token = CONSUME(lexer_exports.terminals.nil);
15035
- return ACTION(() => C.astFactory.namedNode(C.astFactory.sourceLocation(token), CommonIRIs.NIL));
15292
+ return ACTION(() => C.astFactory.termNamed(C.astFactory.sourceLocation(token), CommonIRIs.NIL));
15036
15293
  } },
15037
15294
  { ALT: () => SUBRULE(tripleTerm) }
15038
15295
  ])
@@ -15058,11 +15315,13 @@ var reifiedTriple = {
15058
15315
  F3.printFilter(ast, () => PRINT_WORD("<<"));
15059
15316
  const triple = ast.triples[0];
15060
15317
  SUBRULE(graphNodePath2, triple.subject);
15318
+ F3.printFilter(ast, () => PRINT_WORD(""));
15061
15319
  if (F3.isPathPure(triple.predicate)) {
15062
15320
  SUBRULE(grammar_exports.pathGenerator, triple.predicate, void 0);
15063
15321
  } else {
15064
15322
  SUBRULE(graphNodePath2, triple.predicate);
15065
15323
  }
15324
+ F3.printFilter(ast, () => PRINT_WORD(""));
15066
15325
  SUBRULE(graphNodePath2, triple.object);
15067
15326
  SUBRULE(annotationPath, [F3.wrap(ast.identifier, ast.identifier.loc)]);
15068
15327
  F3.printFilter(ast, () => PRINT_WORD(">>"));
@@ -15098,7 +15357,9 @@ var tripleTerm = {
15098
15357
  gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F3 }) => {
15099
15358
  F3.printFilter(ast, () => PRINT_WORD("<<("));
15100
15359
  SUBRULE(graphNodePath2, ast.subject);
15360
+ F3.printFilter(ast, () => PRINT_WORD(""));
15101
15361
  SUBRULE(graphNodePath2, ast.predicate);
15362
+ F3.printFilter(ast, () => PRINT_WORD(""));
15102
15363
  SUBRULE(graphNodePath2, ast.object);
15103
15364
  F3.printFilter(ast, () => PRINT_WORD(")>>"));
15104
15365
  }
@@ -15128,7 +15389,7 @@ var tripleTermData = {
15128
15389
  { ALT: () => SUBRULE(grammar_exports.iri) },
15129
15390
  { ALT: () => {
15130
15391
  const token = CONSUME(lexer_exports.a);
15131
- return ACTION(() => C.astFactory.namedNode(C.astFactory.sourceLocation(token), CommonIRIs.TYPE));
15392
+ return ACTION(() => C.astFactory.termNamed(C.astFactory.sourceLocation(token), CommonIRIs.TYPE));
15132
15393
  } }
15133
15394
  ]);
15134
15395
  const object3 = SUBRULE(tripleTermDataObject);
@@ -15215,7 +15476,7 @@ var rdfLiteral2 = {
15215
15476
  { ALT: () => {
15216
15477
  const langTag2 = CONSUME(LANG_DIR);
15217
15478
  return ACTION(() => {
15218
- const literal = C.astFactory.literalTerm(C.astFactory.sourceLocation(value, langTag2), value.value, langTag2.image.slice(1).toLowerCase());
15479
+ const literal = C.astFactory.termLiteral(C.astFactory.sourceLocation(value, langTag2), value.value, langTag2.image.slice(1).toLowerCase());
15219
15480
  langTagHasCorrectRange(literal);
15220
15481
  return literal;
15221
15482
  });
@@ -15223,7 +15484,7 @@ var rdfLiteral2 = {
15223
15484
  { ALT: () => {
15224
15485
  CONSUME(lexer_exports.symbols.hathat);
15225
15486
  const iriVal = SUBRULE(grammar_exports.iri);
15226
- return ACTION(() => C.astFactory.literalTerm(C.astFactory.sourceLocation(value, iriVal), value.value, iriVal));
15487
+ return ACTION(() => C.astFactory.termLiteral(C.astFactory.sourceLocation(value, iriVal), value.value, iriVal));
15227
15488
  } }
15228
15489
  ])) ?? value;
15229
15490
  }
@@ -15249,13 +15510,16 @@ var unaryExpression2 = {
15249
15510
  };
15250
15511
  var generateTriplesBlock = {
15251
15512
  name: "triplesBlock",
15252
- gImpl: ({ SUBRULE, PRINT_WORD, HANDLE_LOC }) => (ast, { astFactory: F3 }) => {
15513
+ gImpl: ({ SUBRULE, PRINT_WORD, NEW_LINE, HANDLE_LOC }) => (ast, { astFactory: F3 }) => {
15253
15514
  for (const [index, triple] of ast.triples.entries()) {
15254
15515
  HANDLE_LOC(triple, () => {
15255
15516
  const nextTriple = ast.triples.at(index);
15256
15517
  if (F3.isTripleCollection(triple)) {
15257
15518
  SUBRULE(graphNodePath2, triple);
15258
- F3.printFilter(triple, () => PRINT_WORD(".\n"));
15519
+ F3.printFilter(triple, () => {
15520
+ PRINT_WORD(".");
15521
+ NEW_LINE();
15522
+ });
15259
15523
  } else {
15260
15524
  SUBRULE(graphNodePath2, triple.subject);
15261
15525
  F3.printFilter(ast, () => PRINT_WORD(""));
@@ -15268,11 +15532,17 @@ var generateTriplesBlock = {
15268
15532
  SUBRULE(graphNodePath2, triple.object);
15269
15533
  SUBRULE(annotationPath, triple.annotations ?? []);
15270
15534
  if (nextTriple === void 0 || F3.isTripleCollection(nextTriple) || !F3.isSourceLocationNoMaterialize(nextTriple.subject.loc)) {
15271
- F3.printFilter(ast, () => PRINT_WORD(".\n"));
15535
+ F3.printFilter(ast, () => {
15536
+ PRINT_WORD(".");
15537
+ NEW_LINE();
15538
+ });
15272
15539
  } else if (F3.isSourceLocationNoMaterialize(nextTriple.predicate.loc)) {
15273
15540
  F3.printFilter(ast, () => PRINT_WORD(","));
15274
15541
  } else {
15275
- F3.printFilter(ast, () => PRINT_WORD(";\n"));
15542
+ F3.printFilter(ast, () => {
15543
+ PRINT_WORD(";");
15544
+ NEW_LINE();
15545
+ });
15276
15546
  }
15277
15547
  }
15278
15548
  });
@@ -15308,13 +15578,16 @@ function completeParseContext2(context) {
15308
15578
  // lib/index.ts
15309
15579
  var sparql12GeneratorBuilder = GeneratorBuilder.create(sparql11GeneratorBuilder).widenContext().typePatch().addRule(grammar_exports2.tripleTerm).addRule(grammar_exports2.reifiedTriple).patchRule(grammar_exports2.graphNodePath).addRule(grammar_exports2.annotationBlockPath).addRule(grammar_exports2.annotationPath).addRule(grammar_exports2.versionDecl).patchRule(grammar_exports2.prologue).patchRule(grammar_exports2.generateTriplesBlock).patchRule(grammar_exports2.generateGraphTerm);
15310
15580
  var Generator = class {
15581
+ constructor(defaultContext = {}) {
15582
+ this.defaultContext = defaultContext;
15583
+ }
15311
15584
  generator = sparql12GeneratorBuilder.build();
15312
15585
  F = new AstFactory2();
15313
15586
  generate(ast, context = {}) {
15314
- return this.generator.queryOrUpdate(ast, completeParseContext2(context));
15587
+ return this.generator.queryOrUpdate(ast, completeParseContext2({ ...this.defaultContext, ...context })).trim();
15315
15588
  }
15316
15589
  generatePath(ast, context = {}) {
15317
- return this.generator.path(ast, completeParseContext2(context), void 0);
15590
+ return this.generator.path(ast, completeParseContext2({ ...this.defaultContext, ...context }), void 0).trim();
15318
15591
  }
15319
15592
  };
15320
15593
  /*! Bundled license information: