clarity-pattern-parser 11.5.2 → 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.
@@ -17,8 +17,8 @@ export declare class Expression implements Pattern {
17
17
  private _prefixNames;
18
18
  private _postfixPatterns;
19
19
  private _postfixNames;
20
- private _binaryPatterns;
21
- private _binaryNames;
20
+ private _infixPatterns;
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.2",
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",
@@ -26,8 +26,8 @@ export class Expression implements Pattern {
26
26
  private _prefixNames: string[];
27
27
  private _postfixPatterns: Pattern[];
28
28
  private _postfixNames: string[];
29
- private _binaryPatterns: Pattern[];
30
- private _binaryNames: string[];
29
+ private _infixPatterns: Pattern[];
30
+ private _infixNames: string[];
31
31
  private _associationMap: Record<string, Association>;
32
32
  private _precedenceMap: Record<string, number>;
33
33
  private _shouldStopParsing: boolean;
@@ -71,8 +71,13 @@ 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
- return this._binaryPatterns;
80
+ return this._infixPatterns;
76
81
  }
77
82
 
78
83
  get originalPatterns(): readonly Pattern[] {
@@ -100,8 +105,8 @@ export class Expression implements Pattern {
100
105
  this._prefixNames = [];
101
106
  this._postfixPatterns = [];
102
107
  this._postfixNames = [];
103
- this._binaryPatterns = [];
104
- this._binaryNames = [];
108
+ this._infixPatterns = [];
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._binaryPatterns.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,15 +457,15 @@ 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
 
459
- for (let i = 0; i < this._binaryPatterns.length; i++) {
464
+ for (let i = 0; i < this._infixPatterns.length; i++) {
460
465
  cursor.moveTo(onIndex);
461
466
 
462
- const pattern = this._binaryPatterns[i];
463
- const name = this._binaryNames[i];
467
+ const pattern = this._infixPatterns[i];
468
+ const name = this._infixNames[i];
464
469
  const node = pattern.parse(cursor);
465
470
 
466
471
  if (node != null) {
@@ -503,7 +508,7 @@ export class Expression implements Pattern {
503
508
 
504
509
  getTokensAfter(childReference: Pattern): string[] {
505
510
  this.build();
506
- if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
511
+ if (this._prefixPatterns.includes(childReference) || this._infixPatterns.includes(childReference)) {
507
512
  const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
508
513
  const prefixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
509
514
 
@@ -512,19 +517,29 @@ export class Expression implements Pattern {
512
517
 
513
518
  if (this._atomPatterns.includes(childReference)) {
514
519
  const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
520
+ const infixTokens = this._infixPatterns.map(p => p.getTokens()).flat();
515
521
 
516
- if (postfixTokens.length === 0) {
517
- return this._binaryPatterns.map(p => p.getTokens()).flat();
522
+ if (this._parent != null) {
523
+ return [...postfixTokens, ...infixTokens, ...this._parent.getNextTokens()];
518
524
  }
519
525
 
520
- return postfixTokens;
526
+ return [...postfixTokens, ...infixTokens];
527
+ }
528
+
529
+ if (this._infixPatterns.includes(childReference)) {
530
+ const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
531
+ return atomTokens;
521
532
  }
522
533
 
523
534
  if (this._postfixPatterns.includes(childReference)) {
524
535
  const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
525
- const binaryTokens = this._binaryPatterns.map(p => p.getTokens()).flat();
536
+ const infixTokens = this._infixPatterns.map(p => p.getTokens()).flat();
537
+
538
+ if (this._parent != null) {
539
+ return [...postfixTokens, ...infixTokens, ...this._parent.getNextTokens()];
540
+ }
526
541
 
527
- return [...postfixTokens, ...binaryTokens];
542
+ return [...postfixTokens, ...infixTokens];
528
543
  }
529
544
 
530
545
  return [];
@@ -548,7 +563,7 @@ export class Expression implements Pattern {
548
563
 
549
564
  getPatternsAfter(childReference: Pattern): Pattern[] {
550
565
  this.build();
551
- if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
566
+ if (this._prefixPatterns.includes(childReference) || this._infixPatterns.includes(childReference)) {
552
567
  const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
553
568
  const prefixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
554
569
 
@@ -557,19 +572,29 @@ export class Expression implements Pattern {
557
572
 
558
573
  if (this._atomPatterns.includes(childReference)) {
559
574
  const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
575
+ const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();
560
576
 
561
- if (postfixPatterns.length === 0) {
562
- return this._binaryPatterns.map(p => p.getPatterns()).flat();
577
+ if (this._parent != null) {
578
+ return [...postfixPatterns, ...infixPatterns, ...this._parent.getNextPatterns()];
563
579
  }
564
580
 
565
- return postfixPatterns;
581
+ return [...postfixPatterns, ...infixPatterns];
582
+ }
583
+
584
+ if (this._infixPatterns.includes(childReference)) {
585
+ const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
586
+ return atomPatterns;
566
587
  }
567
588
 
568
589
  if (this._postfixPatterns.includes(childReference)) {
569
590
  const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
570
- const binaryPatterns = this._binaryPatterns.map(p => p.getPatterns()).flat();
591
+ const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();
592
+
593
+ if (this._parent != null) {
594
+ return [...postfixPatterns, ...infixPatterns, ...this._parent.getNextPatterns()];
595
+ }
571
596
 
572
- return [...postfixPatterns, ...binaryPatterns];
597
+ return [...postfixPatterns, ...infixPatterns];
573
598
  }
574
599
 
575
600
  return [];