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.js CHANGED
@@ -2883,6 +2883,10 @@ 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
2891
  return this._infixPatterns;
2888
2892
  }
@@ -2909,7 +2913,7 @@ class Expression {
2909
2913
  this._postfixPatterns = [];
2910
2914
  this._postfixNames = [];
2911
2915
  this._infixPatterns = [];
2912
- this._binaryNames = [];
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._infixPatterns.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
3199
  for (let i = 0; i < this._infixPatterns.length; i++) {
3196
3200
  cursor.moveTo(onIndex);
3197
3201
  const pattern = this._infixPatterns[i];
3198
- const name = this._binaryNames[i];
3202
+ const name = this._infixNames[i];
3199
3203
  const node = pattern.parse(cursor);
3200
3204
  if (node != null) {
3201
3205
  foundMatch = true;
@@ -3244,6 +3248,10 @@ class Expression {
3244
3248
  }
3245
3249
  return [...postfixTokens, ...infixTokens];
3246
3250
  }
3251
+ if (this._infixPatterns.includes(childReference)) {
3252
+ const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
3253
+ return atomTokens;
3254
+ }
3247
3255
  if (this._postfixPatterns.includes(childReference)) {
3248
3256
  const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
3249
3257
  const infixTokens = this._infixPatterns.map(p => p.getTokens()).flat();
@@ -3281,6 +3289,10 @@ class Expression {
3281
3289
  }
3282
3290
  return [...postfixPatterns, ...infixPatterns];
3283
3291
  }
3292
+ if (this._infixPatterns.includes(childReference)) {
3293
+ const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
3294
+ return atomPatterns;
3295
+ }
3284
3296
  if (this._postfixPatterns.includes(childReference)) {
3285
3297
  const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
3286
3298
  const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();