clarity-pattern-parser 11.5.3 → 11.5.4

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.
@@ -18,7 +18,7 @@ export declare class Expression implements Pattern {
18
18
  private _postfixPatterns;
19
19
  private _postfixNames;
20
20
  private _infixPatterns;
21
- private _binaryNames;
21
+ private _infixNames;
22
22
  private _associationMap;
23
23
  private _precedenceMap;
24
24
  private _shouldStopParsing;
@@ -34,6 +34,7 @@ export declare class Expression implements Pattern {
34
34
  get prefixPatterns(): readonly Pattern[];
35
35
  get atomPatterns(): readonly Pattern[];
36
36
  get postfixPatterns(): readonly Pattern[];
37
+ get infixPatterns(): readonly Pattern[];
37
38
  get binaryPatterns(): readonly Pattern[];
38
39
  get originalPatterns(): readonly Pattern[];
39
40
  get startedOnIndex(): number;
@@ -47,7 +48,7 @@ export declare class Expression implements Pattern {
47
48
  private _isPostfix;
48
49
  private _extractPostfix;
49
50
  private _isBinary;
50
- private _extractBinary;
51
+ private _extractInfix;
51
52
  private _unwrapAssociationIfNecessary;
52
53
  private _referenceCount;
53
54
  private _isRecursiveReference;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarity-pattern-parser",
3
- "version": "11.5.3",
3
+ "version": "11.5.4",
4
4
  "description": "Parsing Library for Typescript and Javascript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -27,7 +27,7 @@ export class Expression implements Pattern {
27
27
  private _postfixPatterns: Pattern[];
28
28
  private _postfixNames: string[];
29
29
  private _infixPatterns: Pattern[];
30
- private _binaryNames: string[];
30
+ private _infixNames: string[];
31
31
  private _associationMap: Record<string, Association>;
32
32
  private _precedenceMap: Record<string, number>;
33
33
  private _shouldStopParsing: boolean;
@@ -71,6 +71,11 @@ export class Expression implements Pattern {
71
71
  return this._postfixPatterns;
72
72
  }
73
73
 
74
+ get infixPatterns(): readonly Pattern[] {
75
+ return this._infixPatterns;
76
+ }
77
+
78
+ // @deprecated use infixPatterns instead
74
79
  get binaryPatterns(): readonly Pattern[] {
75
80
  return this._infixPatterns;
76
81
  }
@@ -101,7 +106,7 @@ export class Expression implements Pattern {
101
106
  this._postfixPatterns = [];
102
107
  this._postfixNames = [];
103
108
  this._infixPatterns = [];
104
- this._binaryNames = [];
109
+ this._infixNames = [];
105
110
  this._associationMap = {};
106
111
  this._precedenceMap = {};
107
112
  this._originalPatterns = patterns;
@@ -146,12 +151,12 @@ export class Expression implements Pattern {
146
151
  finalPatterns.push(postfix);
147
152
  } else if (this._isBinary(pattern)) {
148
153
  const name = this._extractName(pattern);
149
- const binary = this._extractBinary(pattern);
150
- binary.parent = this;
154
+ const infix = this._extractInfix(pattern);
155
+ infix.parent = this;
151
156
 
152
157
  this._precedenceMap[name] = index;
153
- this._infixPatterns.push(binary);
154
- this._binaryNames.push(name);
158
+ this._infixPatterns.push(infix);
159
+ this._infixNames.push(name);
155
160
 
156
161
  if (pattern.type === "right-associated") {
157
162
  this._associationMap[name] = Association.right;
@@ -159,7 +164,7 @@ export class Expression implements Pattern {
159
164
  this._associationMap[name] = Association.left;
160
165
  }
161
166
 
162
- finalPatterns.push(binary);
167
+ finalPatterns.push(infix);
163
168
  }
164
169
  });
165
170
 
@@ -246,12 +251,12 @@ export class Expression implements Pattern {
246
251
  return firstChildIsReference && lastChildIsReference && pattern.children.length > 2;
247
252
  }
248
253
 
249
- private _extractBinary(pattern: Pattern) {
254
+ private _extractInfix(pattern: Pattern) {
250
255
  pattern = this._unwrapAssociationIfNecessary(pattern);
251
256
  const children = pattern.children.slice(1, -1);
252
- const binarySequence = new Sequence(`${pattern.name}-delimiter`, children);
257
+ const infixSequence = new Sequence(`${pattern.name}-delimiter`, children);
253
258
 
254
- return binarySequence;
259
+ return infixSequence;
255
260
  }
256
261
 
257
262
  private _unwrapAssociationIfNecessary(pattern: Pattern) {
@@ -452,7 +457,7 @@ export class Expression implements Pattern {
452
457
  let onIndex = cursor.index;
453
458
  let foundMatch = false;
454
459
 
455
- if (this.binaryPatterns.length === 0) {
460
+ if (this.infixPatterns.length === 0) {
456
461
  this._shouldStopParsing = true;
457
462
  }
458
463
 
@@ -460,7 +465,7 @@ export class Expression implements Pattern {
460
465
  cursor.moveTo(onIndex);
461
466
 
462
467
  const pattern = this._infixPatterns[i];
463
- const name = this._binaryNames[i];
468
+ const name = this._infixNames[i];
464
469
  const node = pattern.parse(cursor);
465
470
 
466
471
  if (node != null) {
@@ -521,6 +526,11 @@ export class Expression implements Pattern {
521
526
  return [...postfixTokens, ...infixTokens];
522
527
  }
523
528
 
529
+ if (this._infixPatterns.includes(childReference)) {
530
+ const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
531
+ return atomTokens;
532
+ }
533
+
524
534
  if (this._postfixPatterns.includes(childReference)) {
525
535
  const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
526
536
  const infixTokens = this._infixPatterns.map(p => p.getTokens()).flat();
@@ -565,12 +575,17 @@ export class Expression implements Pattern {
565
575
  const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();
566
576
 
567
577
  if (this._parent != null) {
568
- return [...postfixPatterns, ...infixPatterns, ...this._parent.getNextPatterns()];
578
+ return [...postfixPatterns, ...infixPatterns, ...this._parent.getNextPatterns()];
569
579
  }
570
580
 
571
581
  return [...postfixPatterns, ...infixPatterns];
572
582
  }
573
583
 
584
+ if (this._infixPatterns.includes(childReference)) {
585
+ const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
586
+ return atomPatterns;
587
+ }
588
+
574
589
  if (this._postfixPatterns.includes(childReference)) {
575
590
  const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
576
591
  const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();