clarity-pattern-parser 10.0.1 → 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
  }
@@ -1130,7 +1133,7 @@ class FiniteRepeat {
1130
1133
  }
1131
1134
  }
1132
1135
  if (this._trimDivider && this._hasDivider) {
1133
- const isDividerLastMatch = cursor.leafMatch.pattern === this.children[1];
1136
+ const isDividerLastMatch = this.children.length > 1 && nodes[nodes.length - 1].name === this.children[1].name;
1134
1137
  if (isDividerLastMatch) {
1135
1138
  const node = nodes.pop();
1136
1139
  cursor.moveTo(node.firstIndex);
@@ -1371,7 +1374,7 @@ class InfiniteRepeat {
1371
1374
  else {
1372
1375
  if (dividerNode == null) {
1373
1376
  cursor.moveTo(dividerStartIndex);
1374
- if (dividerNode == null && repeatNode == null) {
1377
+ if (repeatNode == null) {
1375
1378
  // If neither the repeat pattern or divider pattern matched get out.
1376
1379
  passed = true;
1377
1380
  break;
@@ -1401,10 +1404,11 @@ class InfiniteRepeat {
1401
1404
  return passed;
1402
1405
  }
1403
1406
  _createNode(cursor) {
1407
+ var _a;
1404
1408
  const hasDivider = this._divider != null;
1405
1409
  if (hasDivider &&
1406
1410
  this._trimDivider &&
1407
- cursor.leafMatch.pattern === this._divider) {
1411
+ this._nodes[this._nodes.length - 1].name === ((_a = this._divider) === null || _a === void 0 ? void 0 : _a.name)) {
1408
1412
  const dividerNode = this._nodes.pop();
1409
1413
  cursor.moveTo(dividerNode.firstIndex);
1410
1414
  }
@@ -1516,10 +1520,10 @@ class Repeat {
1516
1520
  return this._children;
1517
1521
  }
1518
1522
  get min() {
1519
- return this.children[0].min;
1523
+ return this._options.min;
1520
1524
  }
1521
1525
  get max() {
1522
- return this.children[0].max || Infinity;
1526
+ return this._options.max;
1523
1527
  }
1524
1528
  constructor(name, pattern, options = {}) {
1525
1529
  this._id = `repeat-${idIndex$3++}`;
@@ -1755,7 +1759,7 @@ class Sequence {
1755
1759
  const tokens = [];
1756
1760
  for (const child of this._children) {
1757
1761
  tokens.push(...child.getTokens());
1758
- if (child.type !== "optional") {
1762
+ if (child.type !== "optional" && child.type !== "not") {
1759
1763
  break;
1760
1764
  }
1761
1765
  }
@@ -1777,7 +1781,7 @@ class Sequence {
1777
1781
  const patterns = [];
1778
1782
  for (const child of this._children) {
1779
1783
  patterns.push(...child.getPatterns());
1780
- if (child.type !== "optional") {
1784
+ if (child.type !== "optional" && child.type !== "not") {
1781
1785
  break;
1782
1786
  }
1783
1787
  }
@@ -2201,9 +2205,6 @@ class Not {
2201
2205
  get children() {
2202
2206
  return this._children;
2203
2207
  }
2204
- get isOptional() {
2205
- return false;
2206
- }
2207
2208
  constructor(name, pattern) {
2208
2209
  this._id = `not-${idIndex++}`;
2209
2210
  this._type = "not";
@@ -2858,7 +2859,7 @@ class Grammar {
2858
2859
  .importedPatternsByName
2859
2860
  .values());
2860
2861
  const grammar = new Grammar({
2861
- params: importedValues,
2862
+ params: [...importedValues, ...this._parseContext.paramsByName.values()],
2862
2863
  originResource: this._originResource,
2863
2864
  resolveImport: this._resolveImport
2864
2865
  });