clarity-pattern-parser 11.0.4 → 11.0.5
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 +40 -6
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +40 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +40 -6
- package/dist/index.js.map +1 -1
- package/dist/patterns/ExpressionPattern.d.ts +3 -3
- package/package.json +1 -1
- package/src/patterns/ExpressionPattern.test.ts +1 -2
- package/src/patterns/ExpressionPattern.ts +56 -8
- package/src/patterns/PrecedenceTree.test.ts +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -2924,12 +2924,12 @@ class ExpressionPattern {
|
|
|
2924
2924
|
this._postfixNames = [];
|
|
2925
2925
|
this._binaryPatterns = [];
|
|
2926
2926
|
this._binaryNames = [];
|
|
2927
|
-
this.
|
|
2927
|
+
this._associationMap = {};
|
|
2928
2928
|
this._precedenceMap = {};
|
|
2929
2929
|
this._originalPatterns = patterns;
|
|
2930
2930
|
this._patterns = this._organizePatterns(patterns);
|
|
2931
2931
|
this._shouldStopParsing = false;
|
|
2932
|
-
this._precedenceTree = new PrecedenceTree(this._precedenceMap, this.
|
|
2932
|
+
this._precedenceTree = new PrecedenceTree(this._precedenceMap, this._associationMap);
|
|
2933
2933
|
if (this._atomPatterns.length === 0) {
|
|
2934
2934
|
throw new Error("Need at least one terminating pattern with an 'expression' pattern.");
|
|
2935
2935
|
}
|
|
@@ -2967,10 +2967,10 @@ class ExpressionPattern {
|
|
|
2967
2967
|
this._binaryPatterns.push(clone);
|
|
2968
2968
|
this._binaryNames.push(name);
|
|
2969
2969
|
if (pattern.type === "right-associated") {
|
|
2970
|
-
this.
|
|
2970
|
+
this._associationMap[name] = Association.right;
|
|
2971
2971
|
}
|
|
2972
2972
|
else {
|
|
2973
|
-
this.
|
|
2973
|
+
this._associationMap[name] = Association.left;
|
|
2974
2974
|
}
|
|
2975
2975
|
finalPatterns.push(clone);
|
|
2976
2976
|
}
|
|
@@ -3215,7 +3215,24 @@ class ExpressionPattern {
|
|
|
3215
3215
|
getTokens() {
|
|
3216
3216
|
return this.atomPatterns.map(p => p.getTokens()).flat();
|
|
3217
3217
|
}
|
|
3218
|
-
getTokensAfter(
|
|
3218
|
+
getTokensAfter(childReference) {
|
|
3219
|
+
if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
|
|
3220
|
+
const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
|
|
3221
|
+
const prefixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
|
|
3222
|
+
return [...prefixTokens, ...atomTokens];
|
|
3223
|
+
}
|
|
3224
|
+
if (this._atomPatterns.includes(childReference)) {
|
|
3225
|
+
const postfixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
|
|
3226
|
+
if (postfixTokens.length === 0) {
|
|
3227
|
+
return this._binaryPatterns.map(p => p.getTokens()).flat();
|
|
3228
|
+
}
|
|
3229
|
+
return postfixTokens;
|
|
3230
|
+
}
|
|
3231
|
+
if (this._postfixPatterns.includes(childReference)) {
|
|
3232
|
+
const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
|
|
3233
|
+
const binaryTokens = this._binaryPatterns.map(p => p.getTokens()).flat();
|
|
3234
|
+
return [...postfixTokens, ...binaryTokens];
|
|
3235
|
+
}
|
|
3219
3236
|
return [];
|
|
3220
3237
|
}
|
|
3221
3238
|
getNextTokens() {
|
|
@@ -3227,7 +3244,24 @@ class ExpressionPattern {
|
|
|
3227
3244
|
getPatterns() {
|
|
3228
3245
|
return this.atomPatterns.map(p => p.getPatterns()).flat();
|
|
3229
3246
|
}
|
|
3230
|
-
getPatternsAfter(
|
|
3247
|
+
getPatternsAfter(childReference) {
|
|
3248
|
+
if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
|
|
3249
|
+
const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
|
|
3250
|
+
const prefixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
|
|
3251
|
+
return [...prefixPatterns, ...atomPatterns];
|
|
3252
|
+
}
|
|
3253
|
+
if (this._atomPatterns.includes(childReference)) {
|
|
3254
|
+
const postfixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
|
|
3255
|
+
if (postfixPatterns.length === 0) {
|
|
3256
|
+
return this._binaryPatterns.map(p => p.getPatterns()).flat();
|
|
3257
|
+
}
|
|
3258
|
+
return postfixPatterns;
|
|
3259
|
+
}
|
|
3260
|
+
if (this._postfixPatterns.includes(childReference)) {
|
|
3261
|
+
const postfixPaterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
|
|
3262
|
+
const binaryPatterns = this._binaryPatterns.map(p => p.getPatterns()).flat();
|
|
3263
|
+
return [...postfixPaterns, ...binaryPatterns];
|
|
3264
|
+
}
|
|
3231
3265
|
return [];
|
|
3232
3266
|
}
|
|
3233
3267
|
getNextPatterns() {
|