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.
@@ -2885,6 +2885,10 @@
2885
2885
  get postfixPatterns() {
2886
2886
  return this._postfixPatterns;
2887
2887
  }
2888
+ get infixPatterns() {
2889
+ return this._infixPatterns;
2890
+ }
2891
+ // @deprecated use infixPatterns instead
2888
2892
  get binaryPatterns() {
2889
2893
  return this._infixPatterns;
2890
2894
  }
@@ -2911,7 +2915,7 @@
2911
2915
  this._postfixPatterns = [];
2912
2916
  this._postfixNames = [];
2913
2917
  this._infixPatterns = [];
2914
- this._binaryNames = [];
2918
+ this._infixNames = [];
2915
2919
  this._associationMap = {};
2916
2920
  this._precedenceMap = {};
2917
2921
  this._originalPatterns = patterns;
@@ -2950,18 +2954,18 @@
2950
2954
  }
2951
2955
  else if (this._isBinary(pattern)) {
2952
2956
  const name = this._extractName(pattern);
2953
- const binary = this._extractBinary(pattern);
2954
- binary.parent = this;
2957
+ const infix = this._extractInfix(pattern);
2958
+ infix.parent = this;
2955
2959
  this._precedenceMap[name] = index;
2956
- this._infixPatterns.push(binary);
2957
- this._binaryNames.push(name);
2960
+ this._infixPatterns.push(infix);
2961
+ this._infixNames.push(name);
2958
2962
  if (pattern.type === "right-associated") {
2959
2963
  this._associationMap[name] = Association.right;
2960
2964
  }
2961
2965
  else {
2962
2966
  this._associationMap[name] = Association.left;
2963
2967
  }
2964
- finalPatterns.push(binary);
2968
+ finalPatterns.push(infix);
2965
2969
  }
2966
2970
  });
2967
2971
  this._patterns = finalPatterns;
@@ -3027,11 +3031,11 @@
3027
3031
  const lastChildIsReference = this._isRecursiveReference(lastChild);
3028
3032
  return firstChildIsReference && lastChildIsReference && pattern.children.length > 2;
3029
3033
  }
3030
- _extractBinary(pattern) {
3034
+ _extractInfix(pattern) {
3031
3035
  pattern = this._unwrapAssociationIfNecessary(pattern);
3032
3036
  const children = pattern.children.slice(1, -1);
3033
- const binarySequence = new Sequence(`${pattern.name}-delimiter`, children);
3034
- return binarySequence;
3037
+ const infixSequence = new Sequence(`${pattern.name}-delimiter`, children);
3038
+ return infixSequence;
3035
3039
  }
3036
3040
  _unwrapAssociationIfNecessary(pattern) {
3037
3041
  if (pattern.type === "right-associated") {
@@ -3191,13 +3195,13 @@
3191
3195
  _tryToMatchBinary(cursor) {
3192
3196
  let onIndex = cursor.index;
3193
3197
  let foundMatch = false;
3194
- if (this.binaryPatterns.length === 0) {
3198
+ if (this.infixPatterns.length === 0) {
3195
3199
  this._shouldStopParsing = true;
3196
3200
  }
3197
3201
  for (let i = 0; i < this._infixPatterns.length; i++) {
3198
3202
  cursor.moveTo(onIndex);
3199
3203
  const pattern = this._infixPatterns[i];
3200
- const name = this._binaryNames[i];
3204
+ const name = this._infixNames[i];
3201
3205
  const node = pattern.parse(cursor);
3202
3206
  if (node != null) {
3203
3207
  foundMatch = true;
@@ -3246,6 +3250,10 @@
3246
3250
  }
3247
3251
  return [...postfixTokens, ...infixTokens];
3248
3252
  }
3253
+ if (this._infixPatterns.includes(childReference)) {
3254
+ const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
3255
+ return atomTokens;
3256
+ }
3249
3257
  if (this._postfixPatterns.includes(childReference)) {
3250
3258
  const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
3251
3259
  const infixTokens = this._infixPatterns.map(p => p.getTokens()).flat();
@@ -3283,6 +3291,10 @@
3283
3291
  }
3284
3292
  return [...postfixPatterns, ...infixPatterns];
3285
3293
  }
3294
+ if (this._infixPatterns.includes(childReference)) {
3295
+ const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
3296
+ return atomPatterns;
3297
+ }
3286
3298
  if (this._postfixPatterns.includes(childReference)) {
3287
3299
  const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
3288
3300
  const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();