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.js CHANGED
@@ -223,6 +223,9 @@ class Node {
223
223
  toJson(space) {
224
224
  return JSON.stringify(this.toCycleFreeObject(), null, space);
225
225
  }
226
+ isEqual(node) {
227
+ return node.toJson(0) === this.toJson(0);
228
+ }
226
229
  static createValueNode(name, value) {
227
230
  return new Node("custom-value-node", name, 0, 0, [], value);
228
231
  }
@@ -1105,7 +1108,6 @@ class FiniteRepeat {
1105
1108
  }
1106
1109
  }
1107
1110
  parse(cursor) {
1108
- var _a;
1109
1111
  cursor.startParseWith(this);
1110
1112
  const startIndex = cursor.index;
1111
1113
  const nodes = [];
@@ -1135,7 +1137,7 @@ class FiniteRepeat {
1135
1137
  }
1136
1138
  }
1137
1139
  if (this._trimDivider && this._hasDivider) {
1138
- const isDividerLastMatch = ((_a = cursor.leafMatch.pattern) === null || _a === void 0 ? void 0 : _a.id) === this.children[1].id;
1140
+ const isDividerLastMatch = this.children.length > 1 && nodes[nodes.length - 1].name === this.children[1].name;
1139
1141
  if (isDividerLastMatch) {
1140
1142
  const node = nodes.pop();
1141
1143
  cursor.moveTo(node.firstIndex);
@@ -1406,10 +1408,11 @@ class InfiniteRepeat {
1406
1408
  return passed;
1407
1409
  }
1408
1410
  _createNode(cursor) {
1411
+ var _a;
1409
1412
  const hasDivider = this._divider != null;
1410
1413
  if (hasDivider &&
1411
1414
  this._trimDivider &&
1412
- cursor.leafMatch.pattern === this._divider) {
1415
+ this._nodes[this._nodes.length - 1].name === ((_a = this._divider) === null || _a === void 0 ? void 0 : _a.name)) {
1413
1416
  const dividerNode = this._nodes.pop();
1414
1417
  cursor.moveTo(dividerNode.firstIndex);
1415
1418
  }
@@ -1521,10 +1524,10 @@ class Repeat {
1521
1524
  return this._children;
1522
1525
  }
1523
1526
  get min() {
1524
- return this.children[0].min;
1527
+ return this._options.min;
1525
1528
  }
1526
1529
  get max() {
1527
- return this.children[0].max || Infinity;
1530
+ return this._options.max;
1528
1531
  }
1529
1532
  constructor(name, pattern, options = {}) {
1530
1533
  this._id = `repeat-${idIndex$3++}`;
@@ -1760,7 +1763,7 @@ class Sequence {
1760
1763
  const tokens = [];
1761
1764
  for (const child of this._children) {
1762
1765
  tokens.push(...child.getTokens());
1763
- if (child.type !== "optional") {
1766
+ if (child.type !== "optional" && child.type !== "not") {
1764
1767
  break;
1765
1768
  }
1766
1769
  }
@@ -1782,7 +1785,7 @@ class Sequence {
1782
1785
  const patterns = [];
1783
1786
  for (const child of this._children) {
1784
1787
  patterns.push(...child.getPatterns());
1785
- if (child.type !== "optional") {
1788
+ if (child.type !== "optional" && child.type !== "not") {
1786
1789
  break;
1787
1790
  }
1788
1791
  }
@@ -2206,9 +2209,6 @@ class Not {
2206
2209
  get children() {
2207
2210
  return this._children;
2208
2211
  }
2209
- get isOptional() {
2210
- return false;
2211
- }
2212
2212
  constructor(name, pattern) {
2213
2213
  this._id = `not-${idIndex++}`;
2214
2214
  this._type = "not";
@@ -2863,7 +2863,7 @@ class Grammar {
2863
2863
  .importedPatternsByName
2864
2864
  .values());
2865
2865
  const grammar = new Grammar({
2866
- params: importedValues,
2866
+ params: [...importedValues, ...this._parseContext.paramsByName.values()],
2867
2867
  originResource: this._originResource,
2868
2868
  resolveImport: this._resolveImport
2869
2869
  });