@traqula/parser-sparql-1-2 0.0.9 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.cjs +125 -64
  2. package/package.json +7 -7
package/lib/index.cjs CHANGED
@@ -9746,58 +9746,115 @@ function createToken2(config) {
9746
9746
  return createToken(config);
9747
9747
  }
9748
9748
 
9749
- // ../../packages/core/lib/Transformer.ts
9750
- var Transformer = class {
9751
- transformNode(curObject, searchType, patch) {
9752
- const copy3 = { ...curObject };
9753
- for (const [key, value] of Object.entries(copy3)) {
9754
- copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNode(obj, searchType, patch));
9755
- }
9756
- if (copy3.type === searchType) {
9757
- return patch(copy3);
9749
+ // ../../packages/core/lib/Transformers.ts
9750
+ var TransformerType = class {
9751
+ safeObjectVisit(value, mapper) {
9752
+ if (value && typeof value === "object") {
9753
+ if (Array.isArray(value)) {
9754
+ return value.map((x) => this.safeObjectVisit(x, mapper));
9755
+ }
9756
+ return mapper(value);
9758
9757
  }
9759
- return copy3;
9758
+ return value;
9760
9759
  }
9761
- transformNodeSpecific(curObject, searchType, searchSubType, patch) {
9760
+ transformNode(curObject, nodeCallBacks) {
9761
+ let continueCheck;
9762
+ let transformation;
9763
+ const casted = curObject;
9764
+ if (casted.type) {
9765
+ continueCheck = nodeCallBacks[casted.type]?.continue;
9766
+ transformation = nodeCallBacks[casted.type]?.transform;
9767
+ }
9768
+ let shouldContinue = true;
9769
+ if (continueCheck) {
9770
+ shouldContinue = continueCheck(curObject);
9771
+ }
9772
+ if (!shouldContinue) {
9773
+ return curObject;
9774
+ }
9762
9775
  const copy3 = { ...curObject };
9763
9776
  for (const [key, value] of Object.entries(copy3)) {
9764
- copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNodeSpecific(obj, searchType, searchSubType, patch));
9777
+ copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNode(obj, nodeCallBacks));
9765
9778
  }
9766
- if (copy3.type === searchType && copy3.subType === searchSubType) {
9767
- return patch(copy3);
9779
+ if (transformation) {
9780
+ return transformation(copy3);
9768
9781
  }
9769
9782
  return copy3;
9770
9783
  }
9771
- visitObjects(curObject, visitor) {
9772
- for (const value of Object.values(curObject)) {
9773
- this.safeObjectVisit(value, (obj) => this.visitObjects(obj, visitor));
9784
+ visitNode(curObject, nodeCallBacks) {
9785
+ let callback;
9786
+ const casted = curObject;
9787
+ if (casted.type) {
9788
+ callback = nodeCallBacks[casted.type];
9774
9789
  }
9775
- }
9776
- visitNode(curObject, searchType, visitor) {
9777
- for (const value of Object.values(curObject)) {
9778
- this.safeObjectVisit(value, (obj) => this.visitNode(obj, searchType, visitor));
9790
+ let shouldIterate = true;
9791
+ if (callback) {
9792
+ shouldIterate = callback(curObject);
9779
9793
  }
9780
- if (curObject.type === searchType) {
9781
- visitor(curObject);
9794
+ if (shouldIterate) {
9795
+ for (const value of Object.values(curObject)) {
9796
+ this.safeObjectVisit(value, (obj) => this.visitNode(obj, nodeCallBacks));
9797
+ }
9782
9798
  }
9783
9799
  }
9784
- visitNodeSpecific(curObject, searchType, searchSubType, visitor) {
9785
- for (const value of Object.values(curObject)) {
9786
- this.safeObjectVisit(value, (obj) => this.visitNodeSpecific(obj, searchType, searchSubType, visitor));
9800
+ };
9801
+ var TransformerSubType = class extends TransformerType {
9802
+ // Public visitObjects(curObject: object, visitor: (current: object) => void): void {
9803
+ // for (const value of Object.values(curObject)) {
9804
+ // this.safeObjectVisit(value, obj => this.visitObjects(obj, visitor));
9805
+ // }
9806
+ // }
9807
+ transformNodeSpecific(curObject, nodeCallBacks, nodeSpecificCallBacks = {}) {
9808
+ let continueCheck;
9809
+ let transformation;
9810
+ const casted = curObject;
9811
+ if (casted.type && casted.subType) {
9812
+ const specific = nodeSpecificCallBacks[casted.type];
9813
+ if (specific) {
9814
+ continueCheck = specific[casted.subType]?.continue;
9815
+ transformation = specific[casted.subType]?.transform;
9816
+ }
9817
+ }
9818
+ let shouldContinue = true;
9819
+ if (continueCheck) {
9820
+ shouldContinue = continueCheck(curObject);
9821
+ }
9822
+ if (!shouldContinue) {
9823
+ return curObject;
9824
+ }
9825
+ const copy3 = { ...curObject };
9826
+ for (const [key, value] of Object.entries(copy3)) {
9827
+ copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));
9787
9828
  }
9788
- const cast = curObject;
9789
- if (cast.type === searchType && cast.subType === searchSubType) {
9790
- visitor(curObject);
9829
+ if (transformation) {
9830
+ return transformation(copy3);
9791
9831
  }
9832
+ return copy3;
9792
9833
  }
9793
- safeObjectVisit(value, mapper) {
9794
- if (value && typeof value === "object") {
9795
- if (Array.isArray(value)) {
9796
- return value.map((x) => this.safeObjectVisit(x, mapper));
9834
+ /**
9835
+ * When both nodeCallBack and NodeSpecific callBack are matched, will only look at nodeSpecifCallback
9836
+ */
9837
+ visitNodeSpecific(curObject, nodeCallBacks, nodeSpecificCallBacks = {}) {
9838
+ let callback;
9839
+ const casted = curObject;
9840
+ if (casted.type && casted.subType) {
9841
+ const specific = nodeSpecificCallBacks[casted.type];
9842
+ if (specific) {
9843
+ callback = specific[casted.subType];
9844
+ }
9845
+ }
9846
+ if (!callback && casted.type) {
9847
+ callback = nodeCallBacks[curObject.type];
9848
+ }
9849
+ let shouldIterate = true;
9850
+ if (callback) {
9851
+ shouldIterate = callback(curObject) ?? true;
9852
+ }
9853
+ if (shouldIterate) {
9854
+ for (const value of Object.values(curObject)) {
9855
+ this.safeObjectVisit(value, (obj) => this.visitNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));
9797
9856
  }
9798
- return mapper(value);
9799
9857
  }
9800
- return value;
9801
9858
  }
9802
9859
  };
9803
9860
 
@@ -11447,9 +11504,34 @@ var Factory = class extends asArg(CoreFactory).call(ContextFactoryMixin).call(Ex
11447
11504
  }
11448
11505
  };
11449
11506
 
11507
+ // ../../packages/rules-sparql-1-1/lib/utils.ts
11508
+ function sparqlCodepointEscape(input) {
11509
+ const sanitizedInput = input.replaceAll(
11510
+ /\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{8})/gu,
11511
+ (_, unicode4, unicode8) => {
11512
+ if (unicode4) {
11513
+ const charCode2 = Number.parseInt(unicode4, 16);
11514
+ return String.fromCodePoint(charCode2);
11515
+ }
11516
+ const charCode = Number.parseInt(unicode8, 16);
11517
+ if (charCode < 65535) {
11518
+ return String.fromCodePoint(charCode);
11519
+ }
11520
+ const substractedCharCode = charCode - 65536;
11521
+ return String.fromCodePoint(55296 + (substractedCharCode >> 10), 56320 + (substractedCharCode & 1023));
11522
+ }
11523
+ );
11524
+ if (/[\uD800-\uDBFF](?:[^\uDC00-\uDFFF]|$)/u.test(sanitizedInput)) {
11525
+ throw new Error(`Invalid unicode codepoint of surrogate pair without corresponding codepoint`);
11526
+ }
11527
+ return sanitizedInput;
11528
+ }
11529
+ var TransformerSparql11 = class extends TransformerSubType {
11530
+ };
11531
+
11450
11532
  // ../../packages/rules-sparql-1-1/lib/validation/validators.ts
11451
11533
  var F = new Factory();
11452
- var transformer = new Transformer();
11534
+ var transformer = new TransformerSparql11();
11453
11535
  function getAggregatesOfExpression(expression2) {
11454
11536
  if (F.isExpressionAggregate(expression2)) {
11455
11537
  return [expression2];
@@ -11598,7 +11680,9 @@ function checkNote13(patterns) {
11598
11680
  if (F.isPatternBind(pattern) && index > 0 && F.isPatternBgp(patterns[index - 1])) {
11599
11681
  const bgp = patterns[index - 1];
11600
11682
  const variables = [];
11601
- transformer.visitNodeSpecific(bgp, "term", "variable", (var_2) => variables.push(var_2));
11683
+ transformer.visitNodeSpecific(bgp, {}, { term: { variable: (var_2) => {
11684
+ variables.push(var_2);
11685
+ } } });
11602
11686
  if (variables.some((var_2) => var_2.value === pattern.variable.value)) {
11603
11687
  throw new Error(`Variable used to bind is already bound (?${pattern.variable.value})`);
11604
11688
  }
@@ -11624,12 +11708,12 @@ function updateNoReuseBlankNodeLabels(updateQuery) {
11624
11708
  const operation = update2.operation;
11625
11709
  if (operation.subType === "insertdata") {
11626
11710
  const blankNodesHere = /* @__PURE__ */ new Set();
11627
- transformer.visitNodeSpecific(operation, "term", "blankNode", (blankNode2) => {
11711
+ transformer.visitNodeSpecific(operation, {}, { term: { blankNode: (blankNode2) => {
11628
11712
  blankNodesHere.add(blankNode2.label);
11629
11713
  if (blankLabelsUsedInInsertData.has(blankNode2.label)) {
11630
11714
  throw new Error("Detected reuse blank node across different INSERT DATA clauses");
11631
11715
  }
11632
- });
11716
+ } } });
11633
11717
  for (const blankNode2 of blankNodesHere) {
11634
11718
  blankLabelsUsedInInsertData.add(blankNode2);
11635
11719
  }
@@ -11637,29 +11721,6 @@ function updateNoReuseBlankNodeLabels(updateQuery) {
11637
11721
  }
11638
11722
  }
11639
11723
 
11640
- // ../../packages/rules-sparql-1-1/lib/utils.ts
11641
- function sparqlCodepointEscape(input) {
11642
- const sanitizedInput = input.replaceAll(
11643
- /\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{8})/gu,
11644
- (_, unicode4, unicode8) => {
11645
- if (unicode4) {
11646
- const charCode2 = Number.parseInt(unicode4, 16);
11647
- return String.fromCodePoint(charCode2);
11648
- }
11649
- const charCode = Number.parseInt(unicode8, 16);
11650
- if (charCode < 65535) {
11651
- return String.fromCodePoint(charCode);
11652
- }
11653
- const substractedCharCode = charCode - 65536;
11654
- return String.fromCodePoint(55296 + (substractedCharCode >> 10), 56320 + (substractedCharCode & 1023));
11655
- }
11656
- );
11657
- if (/[\uD800-\uDBFF](?:[^\uDC00-\uDFFF]|$)/u.test(sanitizedInput)) {
11658
- throw new Error(`Invalid unicode codepoint of surrogate pair without corresponding codepoint`);
11659
- }
11660
- return sanitizedInput;
11661
- }
11662
-
11663
11724
  // ../../packages/rules-sparql-1-1/lib/grammar/literals.ts
11664
11725
  function stringEscapedLexical(str2) {
11665
11726
  const lexical = str2.replaceAll(/["\\\t\n\r\b\f]/gu, (char) => {
@@ -12487,7 +12548,7 @@ var aggregate = {
12487
12548
  },
12488
12549
  gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { factory: F3 }) => {
12489
12550
  F3.printFilter(ast, () => {
12490
- PRINT_WORD(ast.aggregation, "(");
12551
+ PRINT_WORD(ast.aggregation.toUpperCase(), "(");
12491
12552
  if (ast.distinct) {
12492
12553
  PRINT_WORD("DISTINCT");
12493
12554
  }
@@ -15264,7 +15325,7 @@ var sparql12LexerBuilder = LexerBuilder.create(lexer_exports.sparql11LexerBuilde
15264
15325
  buildInOBJECT
15265
15326
  ).addBefore(lexer_exports.terminals.langTag, LANG_DIR).delete(lexer_exports.terminals.langTag);
15266
15327
 
15267
- // ../../packages/rules-sparql-1-2/lib/validator.ts
15328
+ // ../../packages/rules-sparql-1-2/lib/validators.ts
15268
15329
  var F2 = new Factory();
15269
15330
  function isLangDir(dir) {
15270
15331
  return dir === "ltr" || dir === "rtl";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@traqula/parser-sparql-1-2",
3
3
  "type": "module",
4
- "version": "0.0.9",
4
+ "version": "0.0.12",
5
5
  "description": "SPARQL 1.2 parser",
6
6
  "lsd:module": true,
7
7
  "license": "MIT",
@@ -52,17 +52,17 @@
52
52
  "spec:earl": "yarn spec:earl:query-1-1 && yarn spec:earl:update-1-1"
53
53
  },
54
54
  "dependencies": {
55
- "@traqula/core": "^0.0.9",
56
- "@traqula/parser-sparql-1-1": "^0.0.9",
57
- "@traqula/rules-sparql-1-1": "^0.0.9",
58
- "@traqula/rules-sparql-1-2": "^0.0.9",
55
+ "@traqula/core": "^0.0.12",
56
+ "@traqula/parser-sparql-1-1": "^0.0.12",
57
+ "@traqula/rules-sparql-1-1": "^0.0.12",
58
+ "@traqula/rules-sparql-1-2": "^0.0.12",
59
59
  "rdf-data-factory": "^2.0.1"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@rdfjs/types": "^2.0.0",
63
- "@traqula/test-utils": "^0.0.9",
63
+ "@traqula/test-utils": "^0.0.12",
64
64
  "rdf-data-factory": "^2.0.1",
65
65
  "rdf-test-suite": "^2.0.0"
66
66
  },
67
- "gitHead": "c13cd255122c688daad98bf313a3397cbffdc45d"
67
+ "gitHead": "3517d5a5223c64dc61184b5f603f6d98c12bd166"
68
68
  }