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
package/dist/index.esm.js
CHANGED
|
@@ -2879,8 +2879,12 @@ class Expression {
|
|
|
2879
2879
|
get postfixPatterns() {
|
|
2880
2880
|
return this._postfixPatterns;
|
|
2881
2881
|
}
|
|
2882
|
+
get infixPatterns() {
|
|
2883
|
+
return this._infixPatterns;
|
|
2884
|
+
}
|
|
2885
|
+
// @deprecated use infixPatterns instead
|
|
2882
2886
|
get binaryPatterns() {
|
|
2883
|
-
return this.
|
|
2887
|
+
return this._infixPatterns;
|
|
2884
2888
|
}
|
|
2885
2889
|
get originalPatterns() {
|
|
2886
2890
|
return this._originalPatterns;
|
|
@@ -2904,8 +2908,8 @@ class Expression {
|
|
|
2904
2908
|
this._prefixNames = [];
|
|
2905
2909
|
this._postfixPatterns = [];
|
|
2906
2910
|
this._postfixNames = [];
|
|
2907
|
-
this.
|
|
2908
|
-
this.
|
|
2911
|
+
this._infixPatterns = [];
|
|
2912
|
+
this._infixNames = [];
|
|
2909
2913
|
this._associationMap = {};
|
|
2910
2914
|
this._precedenceMap = {};
|
|
2911
2915
|
this._originalPatterns = patterns;
|
|
@@ -2944,18 +2948,18 @@ class Expression {
|
|
|
2944
2948
|
}
|
|
2945
2949
|
else if (this._isBinary(pattern)) {
|
|
2946
2950
|
const name = this._extractName(pattern);
|
|
2947
|
-
const
|
|
2948
|
-
|
|
2951
|
+
const infix = this._extractInfix(pattern);
|
|
2952
|
+
infix.parent = this;
|
|
2949
2953
|
this._precedenceMap[name] = index;
|
|
2950
|
-
this.
|
|
2951
|
-
this.
|
|
2954
|
+
this._infixPatterns.push(infix);
|
|
2955
|
+
this._infixNames.push(name);
|
|
2952
2956
|
if (pattern.type === "right-associated") {
|
|
2953
2957
|
this._associationMap[name] = Association.right;
|
|
2954
2958
|
}
|
|
2955
2959
|
else {
|
|
2956
2960
|
this._associationMap[name] = Association.left;
|
|
2957
2961
|
}
|
|
2958
|
-
finalPatterns.push(
|
|
2962
|
+
finalPatterns.push(infix);
|
|
2959
2963
|
}
|
|
2960
2964
|
});
|
|
2961
2965
|
this._patterns = finalPatterns;
|
|
@@ -3021,11 +3025,11 @@ class Expression {
|
|
|
3021
3025
|
const lastChildIsReference = this._isRecursiveReference(lastChild);
|
|
3022
3026
|
return firstChildIsReference && lastChildIsReference && pattern.children.length > 2;
|
|
3023
3027
|
}
|
|
3024
|
-
|
|
3028
|
+
_extractInfix(pattern) {
|
|
3025
3029
|
pattern = this._unwrapAssociationIfNecessary(pattern);
|
|
3026
3030
|
const children = pattern.children.slice(1, -1);
|
|
3027
|
-
const
|
|
3028
|
-
return
|
|
3031
|
+
const infixSequence = new Sequence(`${pattern.name}-delimiter`, children);
|
|
3032
|
+
return infixSequence;
|
|
3029
3033
|
}
|
|
3030
3034
|
_unwrapAssociationIfNecessary(pattern) {
|
|
3031
3035
|
if (pattern.type === "right-associated") {
|
|
@@ -3185,13 +3189,13 @@ class Expression {
|
|
|
3185
3189
|
_tryToMatchBinary(cursor) {
|
|
3186
3190
|
let onIndex = cursor.index;
|
|
3187
3191
|
let foundMatch = false;
|
|
3188
|
-
if (this.
|
|
3192
|
+
if (this.infixPatterns.length === 0) {
|
|
3189
3193
|
this._shouldStopParsing = true;
|
|
3190
3194
|
}
|
|
3191
|
-
for (let i = 0; i < this.
|
|
3195
|
+
for (let i = 0; i < this._infixPatterns.length; i++) {
|
|
3192
3196
|
cursor.moveTo(onIndex);
|
|
3193
|
-
const pattern = this.
|
|
3194
|
-
const name = this.
|
|
3197
|
+
const pattern = this._infixPatterns[i];
|
|
3198
|
+
const name = this._infixNames[i];
|
|
3195
3199
|
const node = pattern.parse(cursor);
|
|
3196
3200
|
if (node != null) {
|
|
3197
3201
|
foundMatch = true;
|
|
@@ -3227,22 +3231,30 @@ class Expression {
|
|
|
3227
3231
|
}
|
|
3228
3232
|
getTokensAfter(childReference) {
|
|
3229
3233
|
this.build();
|
|
3230
|
-
if (this._prefixPatterns.includes(childReference) || this.
|
|
3234
|
+
if (this._prefixPatterns.includes(childReference) || this._infixPatterns.includes(childReference)) {
|
|
3231
3235
|
const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
|
|
3232
3236
|
const prefixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
|
|
3233
3237
|
return [...prefixTokens, ...atomTokens];
|
|
3234
3238
|
}
|
|
3235
3239
|
if (this._atomPatterns.includes(childReference)) {
|
|
3236
3240
|
const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
|
|
3237
|
-
|
|
3238
|
-
|
|
3241
|
+
const infixTokens = this._infixPatterns.map(p => p.getTokens()).flat();
|
|
3242
|
+
if (this._parent != null) {
|
|
3243
|
+
return [...postfixTokens, ...infixTokens, ...this._parent.getNextTokens()];
|
|
3239
3244
|
}
|
|
3240
|
-
return postfixTokens;
|
|
3245
|
+
return [...postfixTokens, ...infixTokens];
|
|
3246
|
+
}
|
|
3247
|
+
if (this._infixPatterns.includes(childReference)) {
|
|
3248
|
+
const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
|
|
3249
|
+
return atomTokens;
|
|
3241
3250
|
}
|
|
3242
3251
|
if (this._postfixPatterns.includes(childReference)) {
|
|
3243
3252
|
const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
|
|
3244
|
-
const
|
|
3245
|
-
|
|
3253
|
+
const infixTokens = this._infixPatterns.map(p => p.getTokens()).flat();
|
|
3254
|
+
if (this._parent != null) {
|
|
3255
|
+
return [...postfixTokens, ...infixTokens, ...this._parent.getNextTokens()];
|
|
3256
|
+
}
|
|
3257
|
+
return [...postfixTokens, ...infixTokens];
|
|
3246
3258
|
}
|
|
3247
3259
|
return [];
|
|
3248
3260
|
}
|
|
@@ -3260,22 +3272,30 @@ class Expression {
|
|
|
3260
3272
|
}
|
|
3261
3273
|
getPatternsAfter(childReference) {
|
|
3262
3274
|
this.build();
|
|
3263
|
-
if (this._prefixPatterns.includes(childReference) || this.
|
|
3275
|
+
if (this._prefixPatterns.includes(childReference) || this._infixPatterns.includes(childReference)) {
|
|
3264
3276
|
const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
|
|
3265
3277
|
const prefixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
|
|
3266
3278
|
return [...prefixPatterns, ...atomPatterns];
|
|
3267
3279
|
}
|
|
3268
3280
|
if (this._atomPatterns.includes(childReference)) {
|
|
3269
3281
|
const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
|
|
3270
|
-
|
|
3271
|
-
|
|
3282
|
+
const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();
|
|
3283
|
+
if (this._parent != null) {
|
|
3284
|
+
return [...postfixPatterns, ...infixPatterns, ...this._parent.getNextPatterns()];
|
|
3272
3285
|
}
|
|
3273
|
-
return postfixPatterns;
|
|
3286
|
+
return [...postfixPatterns, ...infixPatterns];
|
|
3287
|
+
}
|
|
3288
|
+
if (this._infixPatterns.includes(childReference)) {
|
|
3289
|
+
const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
|
|
3290
|
+
return atomPatterns;
|
|
3274
3291
|
}
|
|
3275
3292
|
if (this._postfixPatterns.includes(childReference)) {
|
|
3276
3293
|
const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
|
|
3277
|
-
const
|
|
3278
|
-
|
|
3294
|
+
const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();
|
|
3295
|
+
if (this._parent != null) {
|
|
3296
|
+
return [...postfixPatterns, ...infixPatterns, ...this._parent.getNextPatterns()];
|
|
3297
|
+
}
|
|
3298
|
+
return [...postfixPatterns, ...infixPatterns];
|
|
3279
3299
|
}
|
|
3280
3300
|
return [];
|
|
3281
3301
|
}
|