clarity-pattern-parser 11.5.2 → 11.5.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.browser.js +25 -17
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +25 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +25 -17
- package/dist/index.js.map +1 -1
- package/dist/patterns/Expression.d.ts +1 -1
- package/package.json +1 -1
- package/src/patterns/Expression.ts +28 -18
|
@@ -17,7 +17,7 @@ export declare class Expression implements Pattern {
|
|
|
17
17
|
private _prefixNames;
|
|
18
18
|
private _postfixPatterns;
|
|
19
19
|
private _postfixNames;
|
|
20
|
-
private
|
|
20
|
+
private _infixPatterns;
|
|
21
21
|
private _binaryNames;
|
|
22
22
|
private _associationMap;
|
|
23
23
|
private _precedenceMap;
|
package/package.json
CHANGED
|
@@ -26,7 +26,7 @@ export class Expression implements Pattern {
|
|
|
26
26
|
private _prefixNames: string[];
|
|
27
27
|
private _postfixPatterns: Pattern[];
|
|
28
28
|
private _postfixNames: string[];
|
|
29
|
-
private
|
|
29
|
+
private _infixPatterns: Pattern[];
|
|
30
30
|
private _binaryNames: string[];
|
|
31
31
|
private _associationMap: Record<string, Association>;
|
|
32
32
|
private _precedenceMap: Record<string, number>;
|
|
@@ -72,7 +72,7 @@ export class Expression implements Pattern {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
get binaryPatterns(): readonly Pattern[] {
|
|
75
|
-
return this.
|
|
75
|
+
return this._infixPatterns;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
get originalPatterns(): readonly Pattern[] {
|
|
@@ -100,7 +100,7 @@ export class Expression implements Pattern {
|
|
|
100
100
|
this._prefixNames = [];
|
|
101
101
|
this._postfixPatterns = [];
|
|
102
102
|
this._postfixNames = [];
|
|
103
|
-
this.
|
|
103
|
+
this._infixPatterns = [];
|
|
104
104
|
this._binaryNames = [];
|
|
105
105
|
this._associationMap = {};
|
|
106
106
|
this._precedenceMap = {};
|
|
@@ -150,7 +150,7 @@ export class Expression implements Pattern {
|
|
|
150
150
|
binary.parent = this;
|
|
151
151
|
|
|
152
152
|
this._precedenceMap[name] = index;
|
|
153
|
-
this.
|
|
153
|
+
this._infixPatterns.push(binary);
|
|
154
154
|
this._binaryNames.push(name);
|
|
155
155
|
|
|
156
156
|
if (pattern.type === "right-associated") {
|
|
@@ -456,10 +456,10 @@ export class Expression implements Pattern {
|
|
|
456
456
|
this._shouldStopParsing = true;
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
-
for (let i = 0; i < this.
|
|
459
|
+
for (let i = 0; i < this._infixPatterns.length; i++) {
|
|
460
460
|
cursor.moveTo(onIndex);
|
|
461
461
|
|
|
462
|
-
const pattern = this.
|
|
462
|
+
const pattern = this._infixPatterns[i];
|
|
463
463
|
const name = this._binaryNames[i];
|
|
464
464
|
const node = pattern.parse(cursor);
|
|
465
465
|
|
|
@@ -503,7 +503,7 @@ export class Expression implements Pattern {
|
|
|
503
503
|
|
|
504
504
|
getTokensAfter(childReference: Pattern): string[] {
|
|
505
505
|
this.build();
|
|
506
|
-
if (this._prefixPatterns.includes(childReference) || this.
|
|
506
|
+
if (this._prefixPatterns.includes(childReference) || this._infixPatterns.includes(childReference)) {
|
|
507
507
|
const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
|
|
508
508
|
const prefixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
|
|
509
509
|
|
|
@@ -512,19 +512,24 @@ export class Expression implements Pattern {
|
|
|
512
512
|
|
|
513
513
|
if (this._atomPatterns.includes(childReference)) {
|
|
514
514
|
const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
|
|
515
|
+
const infixTokens = this._infixPatterns.map(p => p.getTokens()).flat();
|
|
515
516
|
|
|
516
|
-
if (
|
|
517
|
-
return
|
|
517
|
+
if (this._parent != null) {
|
|
518
|
+
return [...postfixTokens, ...infixTokens, ...this._parent.getNextTokens()];
|
|
518
519
|
}
|
|
519
520
|
|
|
520
|
-
return postfixTokens;
|
|
521
|
+
return [...postfixTokens, ...infixTokens];
|
|
521
522
|
}
|
|
522
523
|
|
|
523
524
|
if (this._postfixPatterns.includes(childReference)) {
|
|
524
525
|
const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
|
|
525
|
-
const
|
|
526
|
+
const infixTokens = this._infixPatterns.map(p => p.getTokens()).flat();
|
|
526
527
|
|
|
527
|
-
|
|
528
|
+
if (this._parent != null) {
|
|
529
|
+
return [...postfixTokens, ...infixTokens, ...this._parent.getNextTokens()];
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return [...postfixTokens, ...infixTokens];
|
|
528
533
|
}
|
|
529
534
|
|
|
530
535
|
return [];
|
|
@@ -548,7 +553,7 @@ export class Expression implements Pattern {
|
|
|
548
553
|
|
|
549
554
|
getPatternsAfter(childReference: Pattern): Pattern[] {
|
|
550
555
|
this.build();
|
|
551
|
-
if (this._prefixPatterns.includes(childReference) || this.
|
|
556
|
+
if (this._prefixPatterns.includes(childReference) || this._infixPatterns.includes(childReference)) {
|
|
552
557
|
const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
|
|
553
558
|
const prefixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
|
|
554
559
|
|
|
@@ -557,19 +562,24 @@ export class Expression implements Pattern {
|
|
|
557
562
|
|
|
558
563
|
if (this._atomPatterns.includes(childReference)) {
|
|
559
564
|
const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
|
|
565
|
+
const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();
|
|
560
566
|
|
|
561
|
-
if (
|
|
562
|
-
return this.
|
|
567
|
+
if (this._parent != null) {
|
|
568
|
+
return [...postfixPatterns, ...infixPatterns, ...this._parent.getNextPatterns()];
|
|
563
569
|
}
|
|
564
570
|
|
|
565
|
-
return postfixPatterns;
|
|
571
|
+
return [...postfixPatterns, ...infixPatterns];
|
|
566
572
|
}
|
|
567
573
|
|
|
568
574
|
if (this._postfixPatterns.includes(childReference)) {
|
|
569
575
|
const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
|
|
570
|
-
const
|
|
576
|
+
const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();
|
|
577
|
+
|
|
578
|
+
if (this._parent != null) {
|
|
579
|
+
return [...postfixPatterns, ...infixPatterns, ...this._parent.getNextPatterns()];
|
|
580
|
+
}
|
|
571
581
|
|
|
572
|
-
return [...postfixPatterns, ...
|
|
582
|
+
return [...postfixPatterns, ...infixPatterns];
|
|
573
583
|
}
|
|
574
584
|
|
|
575
585
|
return [];
|