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.esm.js CHANGED
@@ -2924,12 +2924,12 @@ class ExpressionPattern {
2924
2924
  this._postfixNames = [];
2925
2925
  this._binaryPatterns = [];
2926
2926
  this._binaryNames = [];
2927
- this.associationMap = {};
2927
+ this._associationMap = {};
2928
2928
  this._precedenceMap = {};
2929
2929
  this._originalPatterns = patterns;
2930
2930
  this._patterns = this._organizePatterns(patterns);
2931
2931
  this._shouldStopParsing = false;
2932
- this._precedenceTree = new PrecedenceTree(this._precedenceMap, this.associationMap);
2932
+ this._precedenceTree = new PrecedenceTree(this._precedenceMap, this._associationMap);
2933
2933
  if (this._atomPatterns.length === 0) {
2934
2934
  throw new Error("Need at least one terminating pattern with an 'expression' pattern.");
2935
2935
  }
@@ -2967,10 +2967,10 @@ class ExpressionPattern {
2967
2967
  this._binaryPatterns.push(clone);
2968
2968
  this._binaryNames.push(name);
2969
2969
  if (pattern.type === "right-associated") {
2970
- this.associationMap[name] = Association.right;
2970
+ this._associationMap[name] = Association.right;
2971
2971
  }
2972
2972
  else {
2973
- this.associationMap[name] = Association.left;
2973
+ this._associationMap[name] = Association.left;
2974
2974
  }
2975
2975
  finalPatterns.push(clone);
2976
2976
  }
@@ -2998,7 +2998,7 @@ class ExpressionPattern {
2998
2998
  _isAtom(pattern) {
2999
2999
  pattern = this._unwrapAssociationIfNecessary(pattern);
3000
3000
  const firstChild = pattern.children[0];
3001
- const lastChild = pattern.children[1];
3001
+ const lastChild = pattern.children[pattern.children.length - 1];
3002
3002
  const firstChildIsReference = this._isRecursiveReference(firstChild);
3003
3003
  const lastChildIsReference = this._isRecursiveReference(lastChild);
3004
3004
  return !firstChildIsReference && !lastChildIsReference;
@@ -3215,7 +3215,24 @@ class ExpressionPattern {
3215
3215
  getTokens() {
3216
3216
  return this.atomPatterns.map(p => p.getTokens()).flat();
3217
3217
  }
3218
- getTokensAfter(_childReference) {
3218
+ getTokensAfter(childReference) {
3219
+ if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
3220
+ const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
3221
+ const prefixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
3222
+ return [...prefixTokens, ...atomTokens];
3223
+ }
3224
+ if (this._atomPatterns.includes(childReference)) {
3225
+ const postfixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
3226
+ if (postfixTokens.length === 0) {
3227
+ return this._binaryPatterns.map(p => p.getTokens()).flat();
3228
+ }
3229
+ return postfixTokens;
3230
+ }
3231
+ if (this._postfixPatterns.includes(childReference)) {
3232
+ const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
3233
+ const binaryTokens = this._binaryPatterns.map(p => p.getTokens()).flat();
3234
+ return [...postfixTokens, ...binaryTokens];
3235
+ }
3219
3236
  return [];
3220
3237
  }
3221
3238
  getNextTokens() {
@@ -3227,7 +3244,24 @@ class ExpressionPattern {
3227
3244
  getPatterns() {
3228
3245
  return this.atomPatterns.map(p => p.getPatterns()).flat();
3229
3246
  }
3230
- getPatternsAfter(_childReference) {
3247
+ getPatternsAfter(childReference) {
3248
+ if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
3249
+ const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
3250
+ const prefixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
3251
+ return [...prefixPatterns, ...atomPatterns];
3252
+ }
3253
+ if (this._atomPatterns.includes(childReference)) {
3254
+ const postfixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
3255
+ if (postfixPatterns.length === 0) {
3256
+ return this._binaryPatterns.map(p => p.getPatterns()).flat();
3257
+ }
3258
+ return postfixPatterns;
3259
+ }
3260
+ if (this._postfixPatterns.includes(childReference)) {
3261
+ const postfixPaterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
3262
+ const binaryPatterns = this._binaryPatterns.map(p => p.getPatterns()).flat();
3263
+ return [...postfixPaterns, ...binaryPatterns];
3264
+ }
3231
3265
  return [];
3232
3266
  }
3233
3267
  getNextPatterns() {