@traqula/rules-sparql-1-1 0.0.16 → 0.0.18

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
@@ -21,9 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AstFactory: () => AstFactory,
24
+ AstTransformer: () => AstTransformer,
24
25
  CommonIRIs: () => CommonIRIs,
25
26
  MinimalSparqlParser: () => MinimalSparqlParser,
26
- TransformerSparql11: () => TransformerSparql11,
27
27
  baseAggregateFunc: () => baseAggregateFunc,
28
28
  checkNote13: () => checkNote13,
29
29
  completeParseContext: () => completeParseContext,
@@ -284,8 +284,9 @@ __export(lexer_exports, {
284
284
  construct: () => construct,
285
285
  copy: () => copy,
286
286
  create: () => create,
287
- dataClause: () => dataClause,
288
287
  deleteClause: () => deleteClause,
288
+ deleteDataClause: () => deleteDataClause,
289
+ deleteWhereClause: () => deleteWhereClause,
289
290
  describe: () => describe,
290
291
  distinct: () => distinct,
291
292
  drop: () => drop2,
@@ -297,6 +298,7 @@ __export(lexer_exports, {
297
298
  having: () => having,
298
299
  in_: () => in_,
299
300
  insertClause: () => insertClause,
301
+ insertDataClause: () => insertDataClause,
300
302
  limit: () => limit,
301
303
  load: () => load,
302
304
  loadInto: () => loadInto,
@@ -9841,6 +9843,11 @@ var LexerBuilder = class _LexerBuilder {
9841
9843
 
9842
9844
  // ../core/lib/Transformers.js
9843
9845
  var TransformerType = class {
9846
+ clone(obj) {
9847
+ const newObj = Object.create(Object.getPrototypeOf(obj));
9848
+ Object.defineProperties(newObj, Object.getOwnPropertyDescriptors(obj));
9849
+ return newObj;
9850
+ }
9844
9851
  safeObjectVisit(value, mapper) {
9845
9852
  if (value && typeof value === "object") {
9846
9853
  if (Array.isArray(value)) {
@@ -9850,104 +9857,213 @@ var TransformerType = class {
9850
9857
  }
9851
9858
  return value;
9852
9859
  }
9853
- transformNode(curObject, nodeCallBacks) {
9854
- let continueCheck;
9855
- let transformation;
9856
- const casted = curObject;
9857
- if (casted.type) {
9858
- continueCheck = nodeCallBacks[casted.type]?.continue;
9859
- transformation = nodeCallBacks[casted.type]?.transform;
9860
- }
9861
- let shouldContinue = true;
9862
- if (continueCheck) {
9863
- shouldContinue = continueCheck(curObject);
9864
- }
9865
- if (!shouldContinue) {
9866
- return curObject;
9867
- }
9868
- const copy3 = { ...curObject };
9869
- for (const [key, value] of Object.entries(copy3)) {
9870
- copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNode(obj, nodeCallBacks));
9871
- }
9872
- if (transformation) {
9873
- return transformation(copy3);
9874
- }
9875
- return copy3;
9860
+ /**
9861
+ * Recursively transforms all objects that are not arrays. Mapper is called on deeper objects first.
9862
+ * @param startObject object to start iterating from
9863
+ * @param mapper mapper to transform the various objects - argument is a copy of the original
9864
+ * @param preVisitor callback that is evaluated before iterating deeper.
9865
+ * If continues is false, we do not iterate deeper, current object is still mapped. - default: true
9866
+ * If shortcut is true, we do not iterate deeper, nor do we branch out, this mapper will be the last one called.
9867
+ * - Default false
9868
+ */
9869
+ transformObject(startObject, mapper, preVisitor = () => ({})) {
9870
+ let didShortCut = false;
9871
+ const recurse = (curObject) => {
9872
+ const copy3 = this.clone(curObject);
9873
+ const context = preVisitor(copy3);
9874
+ didShortCut = context.shortcut ?? false;
9875
+ const continues = context.continue ?? true;
9876
+ if (continues && !didShortCut) {
9877
+ for (const [key, value] of Object.entries(copy3)) {
9878
+ if (didShortCut) {
9879
+ return copy3;
9880
+ }
9881
+ copy3[key] = this.safeObjectVisit(value, (obj) => recurse(obj));
9882
+ }
9883
+ }
9884
+ return mapper(copy3);
9885
+ };
9886
+ return recurse(startObject);
9876
9887
  }
9877
- visitNode(curObject, nodeCallBacks) {
9878
- let callback;
9879
- const casted = curObject;
9880
- if (casted.type) {
9881
- callback = nodeCallBacks[casted.type];
9882
- }
9883
- let shouldIterate = true;
9884
- if (callback) {
9885
- shouldIterate = callback(curObject);
9886
- }
9887
- if (shouldIterate) {
9888
- for (const value of Object.values(curObject)) {
9889
- this.safeObjectVisit(value, (obj) => this.visitNode(obj, nodeCallBacks));
9888
+ /**
9889
+ * Visitor that visits all objects. Visits deeper objects first.
9890
+ */
9891
+ visitObject(startObject, visitor, preVisitor = () => ({})) {
9892
+ let didShortCut = false;
9893
+ const recurse = (curObject) => {
9894
+ const context = preVisitor(curObject);
9895
+ didShortCut = context.shortcut ?? false;
9896
+ const continues = context.continue ?? true;
9897
+ if (continues && !didShortCut) {
9898
+ for (const value of Object.values(curObject)) {
9899
+ if (didShortCut) {
9900
+ return;
9901
+ }
9902
+ this.safeObjectVisit(value, (obj) => recurse(obj));
9903
+ }
9890
9904
  }
9891
- }
9905
+ visitor(curObject);
9906
+ };
9907
+ recurse(startObject);
9908
+ }
9909
+ transformNode(startObject, nodeCallBacks) {
9910
+ const transformWrapper = (curObject) => {
9911
+ const casted = curObject;
9912
+ if (casted.type) {
9913
+ const ogFunc = nodeCallBacks[casted.type]?.transform;
9914
+ if (ogFunc) {
9915
+ return ogFunc(casted);
9916
+ }
9917
+ }
9918
+ return curObject;
9919
+ };
9920
+ const preTransformWrapper = (curObject) => {
9921
+ const casted = curObject;
9922
+ if (casted.type) {
9923
+ const ogFunc = nodeCallBacks[casted.type]?.preVisitor;
9924
+ if (ogFunc) {
9925
+ return ogFunc(casted);
9926
+ }
9927
+ }
9928
+ return {};
9929
+ };
9930
+ return this.transformObject(startObject, transformWrapper, preTransformWrapper);
9931
+ }
9932
+ visitNode(startObject, nodeCallBacks) {
9933
+ const visitWrapper = (curObject) => {
9934
+ const casted = curObject;
9935
+ if (casted.type) {
9936
+ const ogFunc = nodeCallBacks[casted.type]?.visitor;
9937
+ if (ogFunc) {
9938
+ ogFunc(casted);
9939
+ }
9940
+ }
9941
+ };
9942
+ const preVisitWrapper = (curObject) => {
9943
+ const casted = curObject;
9944
+ if (casted.type) {
9945
+ const ogFunc = nodeCallBacks[casted.type]?.preVisitor;
9946
+ if (ogFunc) {
9947
+ return ogFunc(casted);
9948
+ }
9949
+ }
9950
+ return {};
9951
+ };
9952
+ this.visitObject(startObject, visitWrapper, preVisitWrapper);
9953
+ }
9954
+ traverseNodes(currentNode, traverse) {
9955
+ let didShortCut = false;
9956
+ const recurse = (curNode) => {
9957
+ const traverser = traverse[curNode.type];
9958
+ if (traverser) {
9959
+ const { next, shortcut } = traverser(curNode);
9960
+ didShortCut = shortcut ?? false;
9961
+ if (!didShortCut) {
9962
+ for (const node of next ?? []) {
9963
+ if (didShortCut) {
9964
+ return;
9965
+ }
9966
+ recurse(node);
9967
+ }
9968
+ }
9969
+ }
9970
+ };
9971
+ recurse(currentNode);
9892
9972
  }
9893
9973
  };
9894
9974
  var TransformerSubType = class extends TransformerType {
9895
- // Public visitObjects(curObject: object, visitor: (current: object) => void): void {
9896
- // for (const value of Object.values(curObject)) {
9897
- // this.safeObjectVisit(value, obj => this.visitObjects(obj, visitor));
9898
- // }
9899
- // }
9900
- transformNodeSpecific(curObject, nodeCallBacks, nodeSpecificCallBacks = {}) {
9901
- let continueCheck;
9902
- let transformation;
9903
- const casted = curObject;
9904
- if (casted.type && casted.subType) {
9905
- const specific = nodeSpecificCallBacks[casted.type];
9906
- if (specific) {
9907
- continueCheck = specific[casted.subType]?.continue;
9908
- transformation = specific[casted.subType]?.transform;
9909
- }
9910
- }
9911
- let shouldContinue = true;
9912
- if (continueCheck) {
9913
- shouldContinue = continueCheck(curObject);
9914
- }
9915
- if (!shouldContinue) {
9916
- return curObject;
9917
- }
9918
- const copy3 = { ...curObject };
9919
- for (const [key, value] of Object.entries(copy3)) {
9920
- copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));
9921
- }
9922
- if (transformation) {
9923
- return transformation(copy3);
9924
- }
9925
- return copy3;
9975
+ transformNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
9976
+ const transformWrapper = (curObject) => {
9977
+ let ogTransform;
9978
+ const casted = curObject;
9979
+ if (casted.type && casted.subType) {
9980
+ const specific = nodeSpecificCallBacks[casted.type];
9981
+ if (specific) {
9982
+ ogTransform = specific[casted.subType]?.transform;
9983
+ }
9984
+ if (!ogTransform) {
9985
+ ogTransform = nodeCallBacks[casted.type]?.transform;
9986
+ }
9987
+ }
9988
+ return ogTransform ? ogTransform(casted) : curObject;
9989
+ };
9990
+ const preVisitWrapper = (curObject) => {
9991
+ let ogPreVisit;
9992
+ const casted = curObject;
9993
+ if (casted.type && casted.subType) {
9994
+ const specific = nodeSpecificCallBacks[casted.type];
9995
+ if (specific) {
9996
+ ogPreVisit = specific[casted.subType]?.preVisitor;
9997
+ }
9998
+ if (!ogPreVisit) {
9999
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
10000
+ }
10001
+ }
10002
+ return ogPreVisit ? ogPreVisit(casted) : curObject;
10003
+ };
10004
+ return this.transformObject(startObject, transformWrapper, preVisitWrapper);
9926
10005
  }
9927
10006
  /**
9928
10007
  * When both nodeCallBack and NodeSpecific callBack are matched, will only look at nodeSpecifCallback
9929
10008
  */
9930
- visitNodeSpecific(curObject, nodeCallBacks, nodeSpecificCallBacks = {}) {
9931
- let callback;
9932
- const casted = curObject;
9933
- if (casted.type && casted.subType) {
9934
- const specific = nodeSpecificCallBacks[casted.type];
9935
- if (specific) {
9936
- callback = specific[casted.subType];
10009
+ visitNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
10010
+ const visitWrapper = (curObject) => {
10011
+ let ogTransform;
10012
+ const casted = curObject;
10013
+ if (casted.type && casted.subType) {
10014
+ const specific = nodeSpecificCallBacks[casted.type];
10015
+ if (specific) {
10016
+ ogTransform = specific[casted.subType]?.visitor;
10017
+ }
10018
+ if (!ogTransform) {
10019
+ ogTransform = nodeCallBacks[casted.type]?.visitor;
10020
+ }
9937
10021
  }
9938
- }
9939
- if (!callback && casted.type) {
9940
- callback = nodeCallBacks[curObject.type];
9941
- }
9942
- let shouldIterate = true;
9943
- if (callback) {
9944
- shouldIterate = callback(curObject) ?? true;
9945
- }
9946
- if (shouldIterate) {
9947
- for (const value of Object.values(curObject)) {
9948
- this.safeObjectVisit(value, (obj) => this.visitNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));
10022
+ if (ogTransform) {
10023
+ ogTransform(casted);
9949
10024
  }
9950
- }
10025
+ };
10026
+ const preVisitWrapper = (curObject) => {
10027
+ let ogPreVisit;
10028
+ const casted = curObject;
10029
+ if (casted.type && casted.subType) {
10030
+ const specific = nodeSpecificCallBacks[casted.type];
10031
+ if (specific) {
10032
+ ogPreVisit = specific[casted.subType]?.preVisitor;
10033
+ }
10034
+ if (!ogPreVisit) {
10035
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
10036
+ }
10037
+ }
10038
+ return ogPreVisit ? ogPreVisit(casted) : curObject;
10039
+ };
10040
+ this.visitObject(startObject, visitWrapper, preVisitWrapper);
10041
+ }
10042
+ traverseSubNodes(currentNode, traverseNode, traverseSubNode) {
10043
+ let didShortCut = false;
10044
+ const recurse = (curNode) => {
10045
+ let traverser;
10046
+ const subObj = traverseSubNode[curNode.type];
10047
+ if (subObj) {
10048
+ traverser = subObj[curNode.subType];
10049
+ }
10050
+ if (!traverser) {
10051
+ traverser = traverseNode[curNode.type];
10052
+ }
10053
+ if (traverser) {
10054
+ const { next, shortcut } = traverser(curNode);
10055
+ didShortCut = shortcut ?? false;
10056
+ if (!didShortCut) {
10057
+ for (const node of next ?? []) {
10058
+ if (didShortCut) {
10059
+ return;
10060
+ }
10061
+ recurse(node);
10062
+ }
10063
+ }
10064
+ }
10065
+ };
10066
+ recurse(currentNode);
9951
10067
  }
9952
10068
  };
9953
10069
 
@@ -10153,6 +10269,44 @@ var graph = createToken2({ name: "Graph", pattern: /graph/i, label: "GRAPH" });
10153
10269
  var graphAll = createToken2({ name: "GraphAll", pattern: /all/i, label: "ALL" });
10154
10270
  var allGraphTokens = LexerBuilder.create().add(named, default_, graph, graphAll);
10155
10271
 
10272
+ // lib/lexer/lexerPatterns.js
10273
+ var pnCharsBasePattern = /[A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]|[\uD800-\uDB7F][\uDC00-\uDFFF]/;
10274
+ var pnCharsUPattern = new RegExp(`${pnCharsBasePattern.source}|_`);
10275
+ var varNamePattern = new RegExp(`((${pnCharsUPattern.source})|[0-9])((${pnCharsUPattern.source})|[0-9]|[\xB7\u0300-\u036F\u203F-\u2040])*`);
10276
+ var iriRefPattern = /<([^\u0000-\u0020"<>\\^`{|}])*>/;
10277
+ var pnCharsPattern = new RegExp(`(${pnCharsUPattern.source})|[\\-0-9\xB7\u0300-\u036F\u203F-\u2040]`);
10278
+ var pnPrefixPattern = new RegExp(`(${pnCharsBasePattern.source})(((${pnCharsPattern.source})|\\.)*(${pnCharsPattern.source}))?`);
10279
+ var pNameNsPattern = new RegExp(`(${pnPrefixPattern.source})?:`);
10280
+ var percentPattern = /%[\dA-Fa-f]{2}/;
10281
+ var pnLocalEscPattern = /\\[!#$%&'()*+,./;=?@\\_~-]/;
10282
+ var plxPattern = new RegExp(`(${percentPattern.source})|(${pnLocalEscPattern.source})`);
10283
+ var pnLocalPattern = new RegExp(`((${pnCharsUPattern.source})|:|[0-9]|(${plxPattern.source}))(((${pnCharsPattern.source})|\\.|:|(${plxPattern.source}))*((${pnCharsPattern.source})|:|(${plxPattern.source})))?`);
10284
+ var pNameLnPattern = new RegExp(`(${pNameNsPattern.source})(${pnLocalPattern.source})`);
10285
+ var blankNodeLabelPattern = new RegExp(`_:((${pnCharsUPattern.source})|[0-9])(((${pnCharsPattern.source})|\\.)*(${pnCharsPattern.source}))?`);
10286
+ var var1Pattern = new RegExp(`\\?(${varNamePattern.source})`);
10287
+ var var2Pattern = new RegExp(`\\$(${varNamePattern.source})`);
10288
+ var langTagPattern = /@[A-Za-z]+(-[\dA-Za-z]+)*/;
10289
+ var integerPattern = /\d+/;
10290
+ var decimalPattern2 = /\d+\.\d+/;
10291
+ var exponentPattern = /[Ee][+-]?\d+/;
10292
+ var doublePattern = new RegExp(`([0-9]+\\.[0-9]*(${exponentPattern.source}))|(\\.[0-9]+(${exponentPattern.source}))|([0-9]+(${exponentPattern.source}))`);
10293
+ var interferePositivePattern = new RegExp(`\\+${integerPattern.source}`);
10294
+ var decimalPositivePattern = new RegExp(`\\+${decimalPattern2.source}`);
10295
+ var doublePositivePattern = new RegExp(`\\+${doublePattern.source}`);
10296
+ var integerNegativePattern = new RegExp(`-${integerPattern.source}`);
10297
+ var decimalNegativePattern = new RegExp(`-${decimalPattern2.source}`);
10298
+ var doubleNegativePattern = new RegExp(`-${doublePattern.source}`);
10299
+ var echarPattern = /\\[\\"'bfnrt]/u;
10300
+ var stringLiteral1Pattern = new RegExp(`'(([^\\u0027\\u005C\\u000A\r])|(${echarPattern.source}))*'`);
10301
+ var stringLiteral2Pattern = new RegExp(`"(([^\\u0022\\u005C\\u000A\\u000D])|(${echarPattern.source}))*"`);
10302
+ var stringLiteralLong1Pattern = new RegExp(`'''(('|(''))?([^'\\\\]|(${echarPattern.source})))*'''`);
10303
+ var stringLiteralLong2Pattern = new RegExp(`"""(("|(""))?([^"\\\\]|(${echarPattern.source})))*"""`);
10304
+ var wsPattern = /[\u0009\u000A\u000D ]/;
10305
+ var nilPattern = new RegExp(`\\((${wsPattern.source})*\\)`);
10306
+ var anonPattern = new RegExp(`\\[(${wsPattern.source})*\\]`);
10307
+ var commentPattern = /#[^\n]*\n/;
10308
+ var atLeastOneBlankPattern = new RegExp(`((${wsPattern.source}+)|(${commentPattern.source}))+`);
10309
+
10156
10310
  // lib/lexer/symbols.js
10157
10311
  var symbols_exports = {};
10158
10312
  __export(symbols_exports, {
@@ -10241,40 +10395,6 @@ __export(terminals_exports, {
10241
10395
  var2: () => var2,
10242
10396
  ws: () => ws
10243
10397
  });
10244
- var pnCharsBasePattern = /[A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]|[\uD800-\uDB7F][\uDC00-\uDFFF]/;
10245
- var pnCharsUPattern = new RegExp(`${pnCharsBasePattern.source}|_`);
10246
- var varNamePattern = new RegExp(`((${pnCharsUPattern.source})|[0-9])((${pnCharsUPattern.source})|[0-9]|[\xB7\u0300-\u036F\u203F-\u2040])*`);
10247
- var iriRefPattern = /<([^\u0000-\u0020"<>\\^`{|}])*>/;
10248
- var pnCharsPattern = new RegExp(`(${pnCharsUPattern.source})|[\\-0-9\xB7\u0300-\u036F\u203F-\u2040]`);
10249
- var pnPrefixPattern = new RegExp(`(${pnCharsBasePattern.source})(((${pnCharsPattern.source})|\\.)*(${pnCharsPattern.source}))?`);
10250
- var pNameNsPattern = new RegExp(`(${pnPrefixPattern.source})?:`);
10251
- var percentPattern = /%[\dA-Fa-f]{2}/;
10252
- var pnLocalEscPattern = /\\[!#$%&'()*+,./;=?@\\_~-]/;
10253
- var plxPattern = new RegExp(`(${percentPattern.source})|(${pnLocalEscPattern.source})`);
10254
- var pnLocalPattern = new RegExp(`((${pnCharsUPattern.source})|:|[0-9]|(${plxPattern.source}))(((${pnCharsPattern.source})|\\.|:|(${plxPattern.source}))*((${pnCharsPattern.source})|:|(${plxPattern.source})))?`);
10255
- var pNameLnPattern = new RegExp(`(${pNameNsPattern.source})(${pnLocalPattern.source})`);
10256
- var blankNodeLabelPattern = new RegExp(`_:((${pnCharsUPattern.source})|[0-9])(((${pnCharsPattern.source})|\\.)*(${pnCharsPattern.source}))?`);
10257
- var var1Pattern = new RegExp(`\\?(${varNamePattern.source})`);
10258
- var var2Pattern = new RegExp(`\\$(${varNamePattern.source})`);
10259
- var langTagPattern = /@[A-Za-z]+(-[\dA-Za-z]+)*/;
10260
- var integerPattern = /\d+/;
10261
- var decimalPattern2 = /\d+\.\d+/;
10262
- var exponentPattern = /[Ee][+-]?\d+/;
10263
- var doublePattern = new RegExp(`([0-9]+\\.[0-9]*(${exponentPattern.source}))|(\\.[0-9]+(${exponentPattern.source}))|([0-9]+(${exponentPattern.source}))`);
10264
- var interferePositivePattern = new RegExp(`\\+${integerPattern.source}`);
10265
- var decimalPositivePattern = new RegExp(`\\+${decimalPattern2.source}`);
10266
- var doublePositivePattern = new RegExp(`\\+${doublePattern.source}`);
10267
- var integerNegativePattern = new RegExp(`-${integerPattern.source}`);
10268
- var decimalNegativePattern = new RegExp(`-${decimalPattern2.source}`);
10269
- var doubleNegativePattern = new RegExp(`-${doublePattern.source}`);
10270
- var echarPattern = /\\[\\"'bfnrt]/u;
10271
- var stringLiteral1Pattern = new RegExp(`'(([^\\u0027\\u005C\\u000A\r])|(${echarPattern.source}))*'`);
10272
- var stringLiteral2Pattern = new RegExp(`"(([^\\u0022\\u005C\\u000A\\u000D])|(${echarPattern.source}))*"`);
10273
- var stringLiteralLong1Pattern = new RegExp(`'''(('|(''))?([^'\\\\]|(${echarPattern.source})))*'''`);
10274
- var stringLiteralLong2Pattern = new RegExp(`"""(("|(""))?([^"\\\\]|(${echarPattern.source})))*"""`);
10275
- var wsPattern = /[\u0009\u000A\u000D ]/;
10276
- var nilPattern = new RegExp(`\\((${wsPattern.source})*\\)`);
10277
- var anonPattern = new RegExp(`\\[(${wsPattern.source})*\\]`);
10278
10398
  var iriRef = createToken2({ name: "IriRef", pattern: iriRefPattern });
10279
10399
  var pNameLn = createToken2({ name: "PNameLn", pattern: pNameLnPattern });
10280
10400
  var pNameNs = createToken2({ name: "PNameNs", pattern: pNameNsPattern, longer_alt: [pNameLn] });
@@ -10296,7 +10416,7 @@ var stringLiteral2 = createToken2({ name: "StringLiteral2", pattern: stringLiter
10296
10416
  var stringLiteralLong1 = createToken2({ name: "StringLiteralLong1", pattern: stringLiteralLong1Pattern });
10297
10417
  var stringLiteralLong2 = createToken2({ name: "StringLiteralLong2", pattern: stringLiteralLong2Pattern });
10298
10418
  var ws = createToken2({ name: "Ws", pattern: wsPattern, group: Lexer.SKIPPED });
10299
- var comment = createToken2({ name: "Comment", pattern: /#[^\n]*/, group: Lexer.SKIPPED });
10419
+ var comment = createToken2({ name: "Comment", pattern: commentPattern, group: Lexer.SKIPPED });
10300
10420
  var nil = createToken2({ name: "Nil", pattern: nilPattern });
10301
10421
  var anon = createToken2({ name: "Anon", pattern: anonPattern });
10302
10422
  var allTerminals = LexerBuilder.create().add(iriRef, pNameNs, pNameLn, blankNodeLabel, var1, var2, langTag, double, decimal, integer, integerPositive, decimalPositive, doublePositive, integerNegative, decimalNegative, doubleNegative, stringLiteralLong1, stringLiteralLong2, stringLiteral1, stringLiteral2, ws, comment, nil, anon);
@@ -10333,9 +10453,23 @@ var to = createToken2({ name: "To", pattern: /to/i, label: "TO" });
10333
10453
  var move = createToken2({ name: "Move", pattern: /move/i, label: "MOVE" });
10334
10454
  var copy = createToken2({ name: "Copy", pattern: /copy/i, label: "COPY" });
10335
10455
  var modifyWith = createToken2({ name: "ModifyWith", pattern: /with/i, label: "WITH" });
10456
+ var deleteDataClause = createToken2({
10457
+ name: "DeleteDataClause",
10458
+ pattern: new RegExp(`delete(${atLeastOneBlankPattern.source})data`, "i"),
10459
+ label: "DELETE DATA"
10460
+ });
10461
+ var deleteWhereClause = createToken2({
10462
+ name: "DeleteWhereClause",
10463
+ pattern: new RegExp(`delete(${atLeastOneBlankPattern.source})where`, "i"),
10464
+ label: "DELETE WHERE"
10465
+ });
10336
10466
  var deleteClause = createToken2({ name: "DeleteClause", pattern: /delete/i, label: "DELETE" });
10337
- var insertClause = createToken2({ name: "InsertClause", pattern: /insert/i, label: "INSERT" });
10338
- var dataClause = createToken2({ name: "DataClause", pattern: /data/i, label: "DATA", longer_alt: datatype });
10467
+ var insertDataClause = createToken2({
10468
+ name: "InsertDataClause",
10469
+ pattern: new RegExp(`insert(${atLeastOneBlankPattern.source})data`, "i"),
10470
+ label: "INSERT DATA"
10471
+ });
10472
+ var insertClause = createToken2({ name: "InsertClause", pattern: /insert/i, label: "insert" });
10339
10473
  var usingClause = createToken2({ name: "UsingClause", pattern: /using/i, label: "USING" });
10340
10474
  var optional = createToken2({ name: "Optional", pattern: /optional/i, label: "OPTIONAL" });
10341
10475
  var service = createToken2({ name: "Service", pattern: /service/i, label: "SERVICE" });
@@ -10350,8 +10484,8 @@ var false_ = createToken2({ name: "False", pattern: /false/i, label: "false" });
10350
10484
  var in_ = createToken2({ name: "In", pattern: /in/i, label: "IN" });
10351
10485
  var notIn = createToken2({ name: "NotIn", pattern: /not[\u0020\u0009\u000D\u000A]+in/i, label: "NOT IN" });
10352
10486
  var separator = createToken2({ name: "Separator", pattern: /separator/i, label: "SEPARATOR" });
10353
- var allBaseTokens = LexerBuilder.create().add(baseDecl, prefixDecl, select, distinct, reduced, construct, describe, ask, from, where, having, groupByGroup, by, order, orderAsc, orderDesc, limit, offset, values2, load, silent, loadInto, clear, drop2, create, add, to, move, copy, modifyWith, deleteClause, insertClause, dataClause, usingClause, optional, service, bind, undef, minus, union, filter2, as, a, true_, false_, in_, notIn, separator);
10354
- var sparql11LexerBuilder = LexerBuilder.create(allTerminals).merge(allBaseTokens).merge(allBuiltInCalls).merge(allGraphTokens).merge(allSymbols).moveBefore(datatype, dataClause).moveAfter(avg, a).moveBefore(a, graphAll).moveAfter(groupConcat, groupByGroup);
10487
+ var allBaseTokens = LexerBuilder.create().add(baseDecl, prefixDecl, select, distinct, reduced, construct, describe, ask, from, where, having, groupByGroup, by, order, orderAsc, orderDesc, limit, offset, values2, load, silent, loadInto, clear, drop2, create, add, to, move, copy, modifyWith, deleteWhereClause, deleteDataClause, deleteClause, insertDataClause, insertClause, usingClause, optional, service, bind, undef, minus, union, filter2, as, a, true_, false_, in_, notIn, separator);
10488
+ var sparql11LexerBuilder = LexerBuilder.create(allTerminals).merge(allBaseTokens).merge(allBuiltInCalls).merge(allGraphTokens).merge(allSymbols).moveAfter(avg, a).moveBefore(a, graphAll).moveAfter(groupConcat, groupByGroup);
10355
10489
 
10356
10490
  // lib/factoryMixins/ContextFactory.js
10357
10491
  var nodeType = "contextDef";
@@ -11114,12 +11248,12 @@ var CommonIRIs;
11114
11248
  CommonIRIs2["NIL"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil";
11115
11249
  CommonIRIs2["TYPE"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
11116
11250
  })(CommonIRIs || (CommonIRIs = {}));
11117
- var TransformerSparql11 = class extends TransformerSubType {
11251
+ var AstTransformer = class extends TransformerSubType {
11118
11252
  };
11119
11253
 
11120
11254
  // lib/validation/validators.js
11121
11255
  var F = new AstFactory();
11122
- var transformer = new TransformerSparql11();
11256
+ var transformer = new AstTransformer();
11123
11257
  function getAggregatesOfExpression(expression2) {
11124
11258
  if (F.isExpressionAggregate(expression2)) {
11125
11259
  return [expression2];
@@ -11198,77 +11332,69 @@ function queryIsGood(query2) {
11198
11332
  }
11199
11333
  }
11200
11334
  }
11335
+ function notUndefined(some2) {
11336
+ return some2 !== void 0;
11337
+ }
11201
11338
  function findPatternBoundedVars(iter, boundedVars) {
11202
- if (F.isQuery(iter) || F.isUpdate(iter)) {
11203
- if (F.isQuerySelect(iter) || F.isQueryDescribe(iter)) {
11204
- if (iter.where && iter.variables.some((x) => F.isWildcard(x))) {
11205
- findPatternBoundedVars(iter.where, boundedVars);
11206
- } else {
11207
- for (const v of iter.variables) {
11208
- findPatternBoundedVars(v, boundedVars);
11209
- }
11210
- }
11211
- if (iter.solutionModifiers.group) {
11212
- const grouping = iter.solutionModifiers.group;
11213
- for (const g of grouping.groupings) {
11214
- if ("variable" in g) {
11215
- findPatternBoundedVars(g.variable, boundedVars);
11216
- }
11217
- }
11218
- }
11219
- if (iter.values?.values && iter.values.values.length > 0) {
11220
- const values3 = iter.values.values;
11221
- for (const v of Object.keys(values3[0])) {
11339
+ transformer.traverseSubNodes(iter, {
11340
+ query: (op) => ({ next: [
11341
+ op.solutionModifiers.group
11342
+ ].filter(notUndefined) }),
11343
+ triple: (op) => ({ next: [op.subject, op.predicate, op.object] }),
11344
+ path: (op) => ({ next: op.items }),
11345
+ tripleCollection: (op) => ({ next: [op.identifier, ...op.triples] })
11346
+ }, {
11347
+ query: {
11348
+ select: (op) => ({ next: [
11349
+ ...op.variables.some((x) => F.isWildcard(x)) ? [op.where] : op.variables,
11350
+ op.solutionModifiers.group,
11351
+ op.values
11352
+ ].filter(notUndefined) }),
11353
+ describe: (op) => ({ next: [
11354
+ ...op.variables.some((x) => F.isWildcard(x)) ? [op.where] : op.variables,
11355
+ op.solutionModifiers.group,
11356
+ op.values
11357
+ ].filter(notUndefined) })
11358
+ },
11359
+ solutionModifier: {
11360
+ group: (op) => ({
11361
+ next: op.groupings.filter((g) => "variable" in g).map((x) => x.variable)
11362
+ }),
11363
+ having: (op) => ({ next: op.having }),
11364
+ order: (op) => ({ next: op.orderDefs.map((x) => x.expression) })
11365
+ },
11366
+ pattern: {
11367
+ values: (op) => {
11368
+ for (const v of Object.keys(op.values.at(0) ?? {})) {
11222
11369
  boundedVars.add(v);
11223
11370
  }
11371
+ return {};
11372
+ },
11373
+ bgp: (op) => ({ next: op.triples }),
11374
+ group: (op) => ({ next: op.patterns }),
11375
+ union: (op) => ({ next: op.patterns }),
11376
+ optional: (op) => ({ next: op.patterns }),
11377
+ service: (op) => ({ next: [op.name, ...op.patterns] }),
11378
+ bind: (op) => ({ next: [op.variable] }),
11379
+ graph: (op) => ({ next: [op.name, ...op.patterns] }),
11380
+ minus: (op) => ({ next: op.patterns.slice(0, 1) })
11381
+ },
11382
+ term: {
11383
+ variable: (op) => {
11384
+ boundedVars.add(op.value);
11385
+ return {};
11224
11386
  }
11225
11387
  }
11226
- } else if (F.isTerm(iter)) {
11227
- if (F.isTermVariable(iter)) {
11228
- boundedVars.add(iter.value);
11229
- }
11230
- } else if (F.isTriple(iter)) {
11231
- findPatternBoundedVars(iter.subject, boundedVars);
11232
- findPatternBoundedVars(iter.predicate, boundedVars);
11233
- findPatternBoundedVars(iter.object, boundedVars);
11234
- } else if (F.isPath(iter)) {
11235
- if (!F.isTerm(iter)) {
11236
- for (const item of iter.items) {
11237
- findPatternBoundedVars(item, boundedVars);
11238
- }
11239
- }
11240
- } else if (F.isTripleCollection(iter) || F.isPatternBgp(iter)) {
11241
- for (const triple of iter.triples) {
11242
- findPatternBoundedVars(triple, boundedVars);
11243
- }
11244
- } else if (F.isPatternGroup(iter) || F.isPatternUnion(iter) || F.isPatternOptional(iter) || F.isPatternService(iter)) {
11245
- for (const pattern of iter.patterns) {
11246
- findPatternBoundedVars(pattern, boundedVars);
11247
- }
11248
- if (F.isPatternService(iter)) {
11249
- findPatternBoundedVars(iter.name, boundedVars);
11250
- }
11251
- } else if (F.isPatternBind(iter)) {
11252
- findPatternBoundedVars(iter.variable, boundedVars);
11253
- } else if (F.isPatternValues(iter)) {
11254
- for (const variable of Object.keys(iter.values.at(0) ?? {})) {
11255
- boundedVars.add(variable);
11256
- }
11257
- } else if (F.isPatternGraph(iter)) {
11258
- findPatternBoundedVars(iter.name, boundedVars);
11259
- for (const pattern of iter.patterns) {
11260
- findPatternBoundedVars(pattern, boundedVars);
11261
- }
11262
- }
11388
+ });
11263
11389
  }
11264
11390
  function checkNote13(patterns) {
11265
11391
  for (const [index, pattern] of patterns.entries()) {
11266
11392
  if (F.isPatternBind(pattern) && index > 0 && F.isPatternBgp(patterns[index - 1])) {
11267
11393
  const bgp = patterns[index - 1];
11268
11394
  const variables = [];
11269
- transformer.visitNodeSpecific(bgp, {}, { term: { variable: (var_2) => {
11395
+ transformer.visitNodeSpecific(bgp, {}, { term: { variable: { visitor: (var_2) => {
11270
11396
  variables.push(var_2);
11271
- } } });
11397
+ } } } });
11272
11398
  if (variables.some((var_2) => var_2.value === pattern.variable.value)) {
11273
11399
  throw new Error(`Variable used to bind is already bound (?${pattern.variable.value})`);
11274
11400
  }
@@ -11294,12 +11420,12 @@ function updateNoReuseBlankNodeLabels(updateQuery) {
11294
11420
  const operation = update2.operation;
11295
11421
  if (operation.subType === "insertdata") {
11296
11422
  const blankNodesHere = /* @__PURE__ */ new Set();
11297
- transformer.visitNodeSpecific(operation, {}, { term: { blankNode: (blankNode2) => {
11423
+ transformer.visitNodeSpecific(operation, {}, { term: { blankNode: { visitor: (blankNode2) => {
11298
11424
  blankNodesHere.add(blankNode2.label);
11299
11425
  if (blankLabelsUsedInInsertData.has(blankNode2.label)) {
11300
11426
  throw new Error("Detected reuse blank node across different INSERT DATA clauses");
11301
11427
  }
11302
- } } });
11428
+ } } } });
11303
11429
  for (const blankNode2 of blankNodesHere) {
11304
11430
  blankLabelsUsedInInsertData.add(blankNode2);
11305
11431
  }
@@ -13986,12 +14112,11 @@ var quadData = {
13986
14112
  return ACTION(() => C.astFactory.wrap(val.val, C.astFactory.sourceLocation(open, close)));
13987
14113
  }
13988
14114
  };
13989
- function insertDeleteDelWhere(name, subType, cons1, cons2, dataRule) {
14115
+ function insertDeleteDelWhere(name, subType, cons1, dataRule) {
13990
14116
  return {
13991
14117
  name,
13992
14118
  impl: ({ ACTION, SUBRULE1, CONSUME }) => (C) => {
13993
14119
  const insDelToken = CONSUME(cons1);
13994
- CONSUME(cons2);
13995
14120
  let couldCreateBlankNodes = true;
13996
14121
  if (name !== "insertData") {
13997
14122
  couldCreateBlankNodes = ACTION(() => C.parseMode.delete("canCreateBlankNodes"));
@@ -14023,9 +14148,9 @@ function insertDeleteDelWhere(name, subType, cons1, cons2, dataRule) {
14023
14148
  }
14024
14149
  };
14025
14150
  }
14026
- var insertData = insertDeleteDelWhere("insertData", "insertdata", insertClause, dataClause, quadData);
14027
- var deleteData = insertDeleteDelWhere("deleteData", "deletedata", deleteClause, dataClause, quadData);
14028
- var deleteWhere = insertDeleteDelWhere("deleteWhere", "deletewhere", deleteClause, where, quadPattern);
14151
+ var insertData = insertDeleteDelWhere("insertData", "insertdata", insertDataClause, quadData);
14152
+ var deleteData = insertDeleteDelWhere("deleteData", "deletedata", deleteDataClause, quadData);
14153
+ var deleteWhere = insertDeleteDelWhere("deleteWhere", "deletewhere", deleteWhereClause, quadPattern);
14029
14154
  var modify = {
14030
14155
  name: "modify",
14031
14156
  impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, OPTION1, OPTION2, OR }) => (C) => {