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