clarity-pattern-parser 11.5.3 → 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.esm.js CHANGED
@@ -2879,6 +2879,10 @@ 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
2887
  return this._infixPatterns;
2884
2888
  }
@@ -2905,7 +2909,7 @@ class Expression {
2905
2909
  this._postfixPatterns = [];
2906
2910
  this._postfixNames = [];
2907
2911
  this._infixPatterns = [];
2908
- this._binaryNames = [];
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 binary = this._extractBinary(pattern);
2948
- binary.parent = this;
2951
+ const infix = this._extractInfix(pattern);
2952
+ infix.parent = this;
2949
2953
  this._precedenceMap[name] = index;
2950
- this._infixPatterns.push(binary);
2951
- this._binaryNames.push(name);
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(binary);
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
- _extractBinary(pattern) {
3028
+ _extractInfix(pattern) {
3025
3029
  pattern = this._unwrapAssociationIfNecessary(pattern);
3026
3030
  const children = pattern.children.slice(1, -1);
3027
- const binarySequence = new Sequence(`${pattern.name}-delimiter`, children);
3028
- return binarySequence;
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.binaryPatterns.length === 0) {
3192
+ if (this.infixPatterns.length === 0) {
3189
3193
  this._shouldStopParsing = true;
3190
3194
  }
3191
3195
  for (let i = 0; i < this._infixPatterns.length; i++) {
3192
3196
  cursor.moveTo(onIndex);
3193
3197
  const pattern = this._infixPatterns[i];
3194
- const name = this._binaryNames[i];
3198
+ const name = this._infixNames[i];
3195
3199
  const node = pattern.parse(cursor);
3196
3200
  if (node != null) {
3197
3201
  foundMatch = true;
@@ -3240,6 +3244,10 @@ class Expression {
3240
3244
  }
3241
3245
  return [...postfixTokens, ...infixTokens];
3242
3246
  }
3247
+ if (this._infixPatterns.includes(childReference)) {
3248
+ const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
3249
+ return atomTokens;
3250
+ }
3243
3251
  if (this._postfixPatterns.includes(childReference)) {
3244
3252
  const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
3245
3253
  const infixTokens = this._infixPatterns.map(p => p.getTokens()).flat();
@@ -3277,6 +3285,10 @@ class Expression {
3277
3285
  }
3278
3286
  return [...postfixPatterns, ...infixPatterns];
3279
3287
  }
3288
+ if (this._infixPatterns.includes(childReference)) {
3289
+ const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
3290
+ return atomPatterns;
3291
+ }
3280
3292
  if (this._postfixPatterns.includes(childReference)) {
3281
3293
  const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
3282
3294
  const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();