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.
@@ -2885,8 +2885,12 @@
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
- return this._binaryPatterns;
2893
+ return this._infixPatterns;
2890
2894
  }
2891
2895
  get originalPatterns() {
2892
2896
  return this._originalPatterns;
@@ -2910,8 +2914,8 @@
2910
2914
  this._prefixNames = [];
2911
2915
  this._postfixPatterns = [];
2912
2916
  this._postfixNames = [];
2913
- this._binaryPatterns = [];
2914
- this._binaryNames = [];
2917
+ this._infixPatterns = [];
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._binaryPatterns.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
- for (let i = 0; i < this._binaryPatterns.length; i++) {
3201
+ for (let i = 0; i < this._infixPatterns.length; i++) {
3198
3202
  cursor.moveTo(onIndex);
3199
- const pattern = this._binaryPatterns[i];
3200
- const name = this._binaryNames[i];
3203
+ const pattern = this._infixPatterns[i];
3204
+ const name = this._infixNames[i];
3201
3205
  const node = pattern.parse(cursor);
3202
3206
  if (node != null) {
3203
3207
  foundMatch = true;
@@ -3233,22 +3237,30 @@
3233
3237
  }
3234
3238
  getTokensAfter(childReference) {
3235
3239
  this.build();
3236
- if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
3240
+ if (this._prefixPatterns.includes(childReference) || this._infixPatterns.includes(childReference)) {
3237
3241
  const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
3238
3242
  const prefixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
3239
3243
  return [...prefixTokens, ...atomTokens];
3240
3244
  }
3241
3245
  if (this._atomPatterns.includes(childReference)) {
3242
3246
  const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
3243
- if (postfixTokens.length === 0) {
3244
- return this._binaryPatterns.map(p => p.getTokens()).flat();
3247
+ const infixTokens = this._infixPatterns.map(p => p.getTokens()).flat();
3248
+ if (this._parent != null) {
3249
+ return [...postfixTokens, ...infixTokens, ...this._parent.getNextTokens()];
3245
3250
  }
3246
- return postfixTokens;
3251
+ return [...postfixTokens, ...infixTokens];
3252
+ }
3253
+ if (this._infixPatterns.includes(childReference)) {
3254
+ const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
3255
+ return atomTokens;
3247
3256
  }
3248
3257
  if (this._postfixPatterns.includes(childReference)) {
3249
3258
  const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
3250
- const binaryTokens = this._binaryPatterns.map(p => p.getTokens()).flat();
3251
- return [...postfixTokens, ...binaryTokens];
3259
+ const infixTokens = this._infixPatterns.map(p => p.getTokens()).flat();
3260
+ if (this._parent != null) {
3261
+ return [...postfixTokens, ...infixTokens, ...this._parent.getNextTokens()];
3262
+ }
3263
+ return [...postfixTokens, ...infixTokens];
3252
3264
  }
3253
3265
  return [];
3254
3266
  }
@@ -3266,22 +3278,30 @@
3266
3278
  }
3267
3279
  getPatternsAfter(childReference) {
3268
3280
  this.build();
3269
- if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
3281
+ if (this._prefixPatterns.includes(childReference) || this._infixPatterns.includes(childReference)) {
3270
3282
  const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
3271
3283
  const prefixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
3272
3284
  return [...prefixPatterns, ...atomPatterns];
3273
3285
  }
3274
3286
  if (this._atomPatterns.includes(childReference)) {
3275
3287
  const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
3276
- if (postfixPatterns.length === 0) {
3277
- return this._binaryPatterns.map(p => p.getPatterns()).flat();
3288
+ const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();
3289
+ if (this._parent != null) {
3290
+ return [...postfixPatterns, ...infixPatterns, ...this._parent.getNextPatterns()];
3278
3291
  }
3279
- return postfixPatterns;
3292
+ return [...postfixPatterns, ...infixPatterns];
3293
+ }
3294
+ if (this._infixPatterns.includes(childReference)) {
3295
+ const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
3296
+ return atomPatterns;
3280
3297
  }
3281
3298
  if (this._postfixPatterns.includes(childReference)) {
3282
3299
  const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
3283
- const binaryPatterns = this._binaryPatterns.map(p => p.getPatterns()).flat();
3284
- return [...postfixPatterns, ...binaryPatterns];
3300
+ const infixPatterns = this._infixPatterns.map(p => p.getPatterns()).flat();
3301
+ if (this._parent != null) {
3302
+ return [...postfixPatterns, ...infixPatterns, ...this._parent.getNextPatterns()];
3303
+ }
3304
+ return [...postfixPatterns, ...infixPatterns];
3285
3305
  }
3286
3306
  return [];
3287
3307
  }