clarity-pattern-parser 10.1.11 → 10.1.13

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.
@@ -22,6 +22,7 @@ export declare class Options implements Pattern {
22
22
  exec(text: string, record?: boolean): ParseResult;
23
23
  parse(cursor: Cursor): Node | null;
24
24
  private _tryToParse;
25
+ private _shouldReverseOrder;
25
26
  getTokens(): string[];
26
27
  getTokensAfter(_childReference: Pattern): string[];
27
28
  getNextTokens(): string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarity-pattern-parser",
3
- "version": "10.1.11",
3
+ "version": "10.1.13",
4
4
  "description": "Parsing Library for Typescript and Javascript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -111,11 +111,14 @@ export class Options implements Pattern {
111
111
 
112
112
 
113
113
  private _tryToParse(cursor: Cursor): Node | null {
114
+ const shouldReverseOrder = this._shouldReverseOrder();
114
115
  let children = this._children;
115
116
 
116
- if (depthCache.getDepth(this._id, this._firstIndex) > 1) {
117
+ if (shouldReverseOrder) {
117
118
  children = this._children.slice().reverse();
118
- } else if (depthCache.getDepth(this._id, this._firstIndex) > 2) {
119
+ }
120
+
121
+ if (depthCache.getDepth(this._id, this._firstIndex) > 2) {
119
122
  cursor.recordErrorAt(this._firstIndex, this._firstIndex, this);
120
123
  return null;
121
124
  }
@@ -145,6 +148,20 @@ export class Options implements Pattern {
145
148
  return nonNullResults[0] || null;
146
149
  }
147
150
 
151
+ private _shouldReverseOrder() {
152
+ let count = 0;
153
+ let pattern = this._parent;
154
+
155
+ while (pattern != null) {
156
+ if (pattern.id === this.id) {
157
+ count++;
158
+ }
159
+ pattern = pattern.parent;
160
+ }
161
+
162
+ return count % 2 === 1;
163
+ }
164
+
148
165
  getTokens(): string[] {
149
166
  const tokens: string[] = [];
150
167