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.
@@ -52,6 +52,7 @@ export declare class Node {
52
52
  toString(): string;
53
53
  toCycleFreeObject(): CycleFreeNode;
54
54
  toJson(space?: number): string;
55
+ isEqual(node: Node): boolean;
55
56
  static createValueNode(name: string, value: string): Node;
56
57
  static createNode(name: string, children: Node[]): Node;
57
58
  }
@@ -225,6 +225,9 @@
225
225
  toJson(space) {
226
226
  return JSON.stringify(this.toCycleFreeObject(), null, space);
227
227
  }
228
+ isEqual(node) {
229
+ return node.toJson(0) === this.toJson(0);
230
+ }
228
231
  static createValueNode(name, value) {
229
232
  return new Node("custom-value-node", name, 0, 0, [], value);
230
233
  }
@@ -1136,7 +1139,7 @@
1136
1139
  }
1137
1140
  }
1138
1141
  if (this._trimDivider && this._hasDivider) {
1139
- const isDividerLastMatch = cursor.leafMatch.pattern === this.children[1];
1142
+ const isDividerLastMatch = this.children.length > 1 && nodes[nodes.length - 1].name === this.children[1].name;
1140
1143
  if (isDividerLastMatch) {
1141
1144
  const node = nodes.pop();
1142
1145
  cursor.moveTo(node.firstIndex);
@@ -1377,7 +1380,7 @@
1377
1380
  else {
1378
1381
  if (dividerNode == null) {
1379
1382
  cursor.moveTo(dividerStartIndex);
1380
- if (dividerNode == null && repeatNode == null) {
1383
+ if (repeatNode == null) {
1381
1384
  // If neither the repeat pattern or divider pattern matched get out.
1382
1385
  passed = true;
1383
1386
  break;
@@ -1407,10 +1410,11 @@
1407
1410
  return passed;
1408
1411
  }
1409
1412
  _createNode(cursor) {
1413
+ var _a;
1410
1414
  const hasDivider = this._divider != null;
1411
1415
  if (hasDivider &&
1412
1416
  this._trimDivider &&
1413
- cursor.leafMatch.pattern === this._divider) {
1417
+ this._nodes[this._nodes.length - 1].name === ((_a = this._divider) === null || _a === void 0 ? void 0 : _a.name)) {
1414
1418
  const dividerNode = this._nodes.pop();
1415
1419
  cursor.moveTo(dividerNode.firstIndex);
1416
1420
  }
@@ -1522,10 +1526,10 @@
1522
1526
  return this._children;
1523
1527
  }
1524
1528
  get min() {
1525
- return this.children[0].min;
1529
+ return this._options.min;
1526
1530
  }
1527
1531
  get max() {
1528
- return this.children[0].max || Infinity;
1532
+ return this._options.max;
1529
1533
  }
1530
1534
  constructor(name, pattern, options = {}) {
1531
1535
  this._id = `repeat-${idIndex$3++}`;
@@ -1761,7 +1765,7 @@
1761
1765
  const tokens = [];
1762
1766
  for (const child of this._children) {
1763
1767
  tokens.push(...child.getTokens());
1764
- if (child.type !== "optional") {
1768
+ if (child.type !== "optional" && child.type !== "not") {
1765
1769
  break;
1766
1770
  }
1767
1771
  }
@@ -1783,7 +1787,7 @@
1783
1787
  const patterns = [];
1784
1788
  for (const child of this._children) {
1785
1789
  patterns.push(...child.getPatterns());
1786
- if (child.type !== "optional") {
1790
+ if (child.type !== "optional" && child.type !== "not") {
1787
1791
  break;
1788
1792
  }
1789
1793
  }
@@ -2207,9 +2211,6 @@
2207
2211
  get children() {
2208
2212
  return this._children;
2209
2213
  }
2210
- get isOptional() {
2211
- return false;
2212
- }
2213
2214
  constructor(name, pattern) {
2214
2215
  this._id = `not-${idIndex++}`;
2215
2216
  this._type = "not";
@@ -2864,7 +2865,7 @@
2864
2865
  .importedPatternsByName
2865
2866
  .values());
2866
2867
  const grammar = new Grammar({
2867
- params: importedValues,
2868
+ params: [...importedValues, ...this._parseContext.paramsByName.values()],
2868
2869
  originResource: this._originResource,
2869
2870
  resolveImport: this._resolveImport
2870
2871
  });