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.
- package/dist/index.browser.js +47 -27
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +47 -27
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +47 -27
- package/dist/index.js.map +1 -1
- package/dist/patterns/Expression.d.ts +4 -3
- package/package.json +1 -1
- package/src/patterns/Expression.ts +54 -29
|
@@ -17,8 +17,8 @@ export declare class Expression implements Pattern {
|
|
|
17
17
|
private _prefixNames;
|
|
18
18
|
private _postfixPatterns;
|
|
19
19
|
private _postfixNames;
|
|
20
|
-
private
|
|
21
|
-
private
|
|
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
|
|
51
|
+
private _extractInfix;
|
|
51
52
|
private _unwrapAssociationIfNecessary;
|
|
52
53
|
private _referenceCount;
|
|
53
54
|
private _isRecursiveReference;
|
package/package.json
CHANGED
|
@@ -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
|
|
30
|
-
private
|
|
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.
|
|
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.
|
|
104
|
-
this.
|
|
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
|
|
150
|
-
|
|
154
|
+
const infix = this._extractInfix(pattern);
|
|
155
|
+
infix.parent = this;
|
|
151
156
|
|
|
152
157
|
this._precedenceMap[name] = index;
|
|
153
|
-
this.
|
|
154
|
-
this.
|
|
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(
|
|
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
|
|
254
|
+
private _extractInfix(pattern: Pattern) {
|
|
250
255
|
pattern = this._unwrapAssociationIfNecessary(pattern);
|
|
251
256
|
const children = pattern.children.slice(1, -1);
|
|
252
|
-
const
|
|
257
|
+
const infixSequence = new Sequence(`${pattern.name}-delimiter`, children);
|
|
253
258
|
|
|
254
|
-
return
|
|
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.
|
|
460
|
+
if (this.infixPatterns.length === 0) {
|
|
456
461
|
this._shouldStopParsing = true;
|
|
457
462
|
}
|
|
458
463
|
|
|
459
|
-
for (let i = 0; i < this.
|
|
464
|
+
for (let i = 0; i < this._infixPatterns.length; i++) {
|
|
460
465
|
cursor.moveTo(onIndex);
|
|
461
466
|
|
|
462
|
-
const pattern = this.
|
|
463
|
-
const name = this.
|
|
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.
|
|
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 (
|
|
517
|
-
return
|
|
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
|
|
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, ...
|
|
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.
|
|
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 (
|
|
562
|
-
return
|
|
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
|
|
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, ...
|
|
597
|
+
return [...postfixPatterns, ...infixPatterns];
|
|
573
598
|
}
|
|
574
599
|
|
|
575
600
|
return [];
|