clarity-pattern-parser 11.0.4 → 11.0.6

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
@@ -2928,12 +2928,12 @@ class ExpressionPattern {
2928
2928
  this._postfixNames = [];
2929
2929
  this._binaryPatterns = [];
2930
2930
  this._binaryNames = [];
2931
- this.associationMap = {};
2931
+ this._associationMap = {};
2932
2932
  this._precedenceMap = {};
2933
2933
  this._originalPatterns = patterns;
2934
2934
  this._patterns = this._organizePatterns(patterns);
2935
2935
  this._shouldStopParsing = false;
2936
- this._precedenceTree = new PrecedenceTree(this._precedenceMap, this.associationMap);
2936
+ this._precedenceTree = new PrecedenceTree(this._precedenceMap, this._associationMap);
2937
2937
  if (this._atomPatterns.length === 0) {
2938
2938
  throw new Error("Need at least one terminating pattern with an 'expression' pattern.");
2939
2939
  }
@@ -2971,10 +2971,10 @@ class ExpressionPattern {
2971
2971
  this._binaryPatterns.push(clone);
2972
2972
  this._binaryNames.push(name);
2973
2973
  if (pattern.type === "right-associated") {
2974
- this.associationMap[name] = Association.right;
2974
+ this._associationMap[name] = Association.right;
2975
2975
  }
2976
2976
  else {
2977
- this.associationMap[name] = Association.left;
2977
+ this._associationMap[name] = Association.left;
2978
2978
  }
2979
2979
  finalPatterns.push(clone);
2980
2980
  }
@@ -3002,7 +3002,7 @@ class ExpressionPattern {
3002
3002
  _isAtom(pattern) {
3003
3003
  pattern = this._unwrapAssociationIfNecessary(pattern);
3004
3004
  const firstChild = pattern.children[0];
3005
- const lastChild = pattern.children[1];
3005
+ const lastChild = pattern.children[pattern.children.length - 1];
3006
3006
  const firstChildIsReference = this._isRecursiveReference(firstChild);
3007
3007
  const lastChildIsReference = this._isRecursiveReference(lastChild);
3008
3008
  return !firstChildIsReference && !lastChildIsReference;
@@ -3219,7 +3219,24 @@ class ExpressionPattern {
3219
3219
  getTokens() {
3220
3220
  return this.atomPatterns.map(p => p.getTokens()).flat();
3221
3221
  }
3222
- getTokensAfter(_childReference) {
3222
+ getTokensAfter(childReference) {
3223
+ if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
3224
+ const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
3225
+ const prefixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
3226
+ return [...prefixTokens, ...atomTokens];
3227
+ }
3228
+ if (this._atomPatterns.includes(childReference)) {
3229
+ const postfixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
3230
+ if (postfixTokens.length === 0) {
3231
+ return this._binaryPatterns.map(p => p.getTokens()).flat();
3232
+ }
3233
+ return postfixTokens;
3234
+ }
3235
+ if (this._postfixPatterns.includes(childReference)) {
3236
+ const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
3237
+ const binaryTokens = this._binaryPatterns.map(p => p.getTokens()).flat();
3238
+ return [...postfixTokens, ...binaryTokens];
3239
+ }
3223
3240
  return [];
3224
3241
  }
3225
3242
  getNextTokens() {
@@ -3231,7 +3248,24 @@ class ExpressionPattern {
3231
3248
  getPatterns() {
3232
3249
  return this.atomPatterns.map(p => p.getPatterns()).flat();
3233
3250
  }
3234
- getPatternsAfter(_childReference) {
3251
+ getPatternsAfter(childReference) {
3252
+ if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
3253
+ const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
3254
+ const prefixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
3255
+ return [...prefixPatterns, ...atomPatterns];
3256
+ }
3257
+ if (this._atomPatterns.includes(childReference)) {
3258
+ const postfixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
3259
+ if (postfixPatterns.length === 0) {
3260
+ return this._binaryPatterns.map(p => p.getPatterns()).flat();
3261
+ }
3262
+ return postfixPatterns;
3263
+ }
3264
+ if (this._postfixPatterns.includes(childReference)) {
3265
+ const postfixPaterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
3266
+ const binaryPatterns = this._binaryPatterns.map(p => p.getPatterns()).flat();
3267
+ return [...postfixPaterns, ...binaryPatterns];
3268
+ }
3235
3269
  return [];
3236
3270
  }
3237
3271
  getNextPatterns() {