clarity-pattern-parser 10.0.2 → 10.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -219,6 +219,9 @@ class Node {
219
219
  toJson(space) {
220
220
  return JSON.stringify(this.toCycleFreeObject(), null, space);
221
221
  }
222
+ isEqual(node) {
223
+ return node.toJson(0) === this.toJson(0);
224
+ }
222
225
  static createValueNode(name, value) {
223
226
  return new Node("custom-value-node", name, 0, 0, [], value);
224
227
  }
@@ -1101,7 +1104,6 @@ class FiniteRepeat {
1101
1104
  }
1102
1105
  }
1103
1106
  parse(cursor) {
1104
- var _a;
1105
1107
  cursor.startParseWith(this);
1106
1108
  const startIndex = cursor.index;
1107
1109
  const nodes = [];
@@ -1131,7 +1133,7 @@ class FiniteRepeat {
1131
1133
  }
1132
1134
  }
1133
1135
  if (this._trimDivider && this._hasDivider) {
1134
- const isDividerLastMatch = ((_a = cursor.leafMatch.pattern) === null || _a === void 0 ? void 0 : _a.id) === this.children[1].id;
1136
+ const isDividerLastMatch = this.children.length > 1 && nodes[nodes.length - 1].name === this.children[1].name;
1135
1137
  if (isDividerLastMatch) {
1136
1138
  const node = nodes.pop();
1137
1139
  cursor.moveTo(node.firstIndex);
@@ -1402,10 +1404,11 @@ class InfiniteRepeat {
1402
1404
  return passed;
1403
1405
  }
1404
1406
  _createNode(cursor) {
1407
+ var _a;
1405
1408
  const hasDivider = this._divider != null;
1406
1409
  if (hasDivider &&
1407
1410
  this._trimDivider &&
1408
- cursor.leafMatch.pattern === this._divider) {
1411
+ this._nodes[this._nodes.length - 1].name === ((_a = this._divider) === null || _a === void 0 ? void 0 : _a.name)) {
1409
1412
  const dividerNode = this._nodes.pop();
1410
1413
  cursor.moveTo(dividerNode.firstIndex);
1411
1414
  }
@@ -1517,10 +1520,10 @@ class Repeat {
1517
1520
  return this._children;
1518
1521
  }
1519
1522
  get min() {
1520
- return this.children[0].min;
1523
+ return this._options.min;
1521
1524
  }
1522
1525
  get max() {
1523
- return this.children[0].max || Infinity;
1526
+ return this._options.max;
1524
1527
  }
1525
1528
  constructor(name, pattern, options = {}) {
1526
1529
  this._id = `repeat-${idIndex$3++}`;
@@ -1756,7 +1759,7 @@ class Sequence {
1756
1759
  const tokens = [];
1757
1760
  for (const child of this._children) {
1758
1761
  tokens.push(...child.getTokens());
1759
- if (child.type !== "optional") {
1762
+ if (child.type !== "optional" && child.type !== "not") {
1760
1763
  break;
1761
1764
  }
1762
1765
  }
@@ -1778,7 +1781,7 @@ class Sequence {
1778
1781
  const patterns = [];
1779
1782
  for (const child of this._children) {
1780
1783
  patterns.push(...child.getPatterns());
1781
- if (child.type !== "optional") {
1784
+ if (child.type !== "optional" && child.type !== "not") {
1782
1785
  break;
1783
1786
  }
1784
1787
  }
@@ -2202,9 +2205,6 @@ class Not {
2202
2205
  get children() {
2203
2206
  return this._children;
2204
2207
  }
2205
- get isOptional() {
2206
- return false;
2207
- }
2208
2208
  constructor(name, pattern) {
2209
2209
  this._id = `not-${idIndex++}`;
2210
2210
  this._type = "not";
@@ -2859,7 +2859,7 @@ class Grammar {
2859
2859
  .importedPatternsByName
2860
2860
  .values());
2861
2861
  const grammar = new Grammar({
2862
- params: importedValues,
2862
+ params: [...importedValues, ...this._parseContext.paramsByName.values()],
2863
2863
  originResource: this._originResource,
2864
2864
  resolveImport: this._resolveImport
2865
2865
  });