ohm-js 17.2.1 → 17.4.0

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.
Files changed (52) hide show
  1. package/dist/ohm-extras.cjs +568 -471
  2. package/dist/ohm-extras.js +568 -471
  3. package/dist/ohm.cjs +511 -464
  4. package/dist/ohm.cjs.map +1 -1
  5. package/dist/ohm.js +512 -465
  6. package/dist/ohm.min.js +1 -1
  7. package/extras/VisitorFamily.js +9 -9
  8. package/extras/index.d.ts +7 -11
  9. package/extras/index.mjs +1 -0
  10. package/extras/recoverSourceOrder.js +48 -0
  11. package/extras/semantics-toAST.js +1 -1
  12. package/index.d.ts +24 -4
  13. package/package.json +4 -4
  14. package/src/Builder.js +8 -8
  15. package/src/CaseInsensitiveTerminal.js +3 -3
  16. package/src/Grammar.js +69 -70
  17. package/src/GrammarDecl.js +5 -5
  18. package/src/IndentationSensitive.js +6 -6
  19. package/src/InputStream.js +3 -0
  20. package/src/Interval.js +19 -7
  21. package/src/MatchResult.js +14 -16
  22. package/src/MatchState.js +17 -17
  23. package/src/PosInfo.js +7 -7
  24. package/src/Semantics.js +43 -43
  25. package/src/Trace.js +19 -19
  26. package/src/buildGrammar.js +4 -4
  27. package/src/common.js +9 -9
  28. package/src/errors.js +36 -36
  29. package/src/main.js +3 -3
  30. package/src/nodes.js +4 -4
  31. package/src/ohm-cmd.js +5 -5
  32. package/src/pexprs-allowsSkippingPrecedingSpace.js +2 -2
  33. package/src/pexprs-assertAllApplicationsAreValid.js +11 -11
  34. package/src/pexprs-assertChoicesHaveUniformArity.js +9 -9
  35. package/src/pexprs-assertIteratedExprsAreNotNullable.js +7 -7
  36. package/src/pexprs-eval.js +40 -36
  37. package/src/pexprs-getArity.js +6 -6
  38. package/src/pexprs-introduceParams.js +5 -5
  39. package/src/pexprs-isNullable.js +9 -9
  40. package/src/pexprs-main.js +12 -4
  41. package/src/pexprs-outputRecipe.js +15 -15
  42. package/src/pexprs-substituteParams.js +6 -6
  43. package/src/pexprs-toArgumentNameList.js +20 -20
  44. package/src/pexprs-toDisplayString.js +5 -5
  45. package/src/pexprs-toFailure.js +12 -12
  46. package/src/pexprs-toString.js +20 -20
  47. package/src/semanticsDeferredInit.js +8 -8
  48. package/src/unicode.js +54 -0
  49. package/src/util.js +3 -3
  50. package/src/version.js +1 -1
  51. package/dist/ohm-grammar.js.new +0 -0
  52. package/src/UnicodeCategories.js +0 -30
package/dist/ohm.cjs CHANGED
@@ -10,14 +10,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
10
10
 
11
11
  function abstract(optMethodName) {
12
12
  const methodName = optMethodName || '';
13
- return function() {
13
+ return function () {
14
14
  throw new Error(
15
- 'this method ' +
15
+ 'this method ' +
16
16
  methodName +
17
17
  ' is abstract! ' +
18
18
  '(it has no implementation in class ' +
19
19
  this.constructor.name +
20
- ')',
20
+ ')'
21
21
  );
22
22
  };
23
23
  }
@@ -110,11 +110,11 @@ function StringBuffer() {
110
110
  this.strings = [];
111
111
  }
112
112
 
113
- StringBuffer.prototype.append = function(str) {
113
+ StringBuffer.prototype.append = function (str) {
114
114
  this.strings.push(str);
115
115
  };
116
116
 
117
- StringBuffer.prototype.contents = function() {
117
+ StringBuffer.prototype.contents = function () {
118
118
  return this.strings.join('');
119
119
  };
120
120
 
@@ -138,9 +138,9 @@ function unescapeCodePoint(s) {
138
138
  case 'x':
139
139
  return escapeUnicode(s.slice(2, 4));
140
140
  case 'u':
141
- return s.charAt(2) === '{' ?
142
- escapeUnicode(s.slice(3, -1)) :
143
- escapeUnicode(s.slice(2, 6));
141
+ return s.charAt(2) === '{'
142
+ ? escapeUnicode(s.slice(3, -1))
143
+ : escapeUnicode(s.slice(2, 6));
144
144
  default:
145
145
  return s.charAt(1);
146
146
  }
@@ -166,7 +166,7 @@ function unexpectedObjToString(obj) {
166
166
  typeName = typeof obj;
167
167
  }
168
168
  return typeName + ': ' + JSON.stringify(String(obj));
169
- } catch (e) {
169
+ } catch {
170
170
  return baseToString;
171
171
  }
172
172
  }
@@ -198,36 +198,60 @@ var common = /*#__PURE__*/Object.freeze({
198
198
  checkNotNull: checkNotNull
199
199
  });
200
200
 
201
- // These are just categories that are used in ES5/ES2015.
202
- // The full list of Unicode categories is here: http://www.fileformat.info/info/unicode/category/index.htm.
203
- const UnicodeCategories = {
204
- // Letters
205
- Lu: /\p{Lu}/u,
206
- Ll: /\p{Ll}/u,
207
- Lt: /\p{Lt}/u,
208
- Lm: /\p{Lm}/u,
209
- Lo: /\p{Lo}/u,
210
-
211
- // Numbers
212
- Nl: /\p{Nl}/u,
213
- Nd: /\p{Nd}/u,
214
-
215
- // Marks
216
- Mn: /\p{Mn}/u,
217
- Mc: /\p{Mc}/u,
218
-
219
- // Punctuation, Connector
220
- Pc: /\p{Pc}/u,
221
-
222
- // Separator, Space
223
- Zs: /\p{Zs}/u,
224
-
225
- // These two are not real Unicode categories, but our useful for Ohm.
226
- // L is a combination of all the letter categories.
227
- // Ltmo is a combination of Lt, Lm, and Lo.
228
- L: /\p{Letter}/u,
229
- Ltmo: /\p{Lt}|\p{Lm}|\p{Lo}/u,
230
- };
201
+ // The full list of categories from:
202
+ // https://www.unicode.org/Public/UCD/latest/ucd/extracted/DerivedGeneralCategory.txt.
203
+
204
+ const toRegExp = val => new RegExp(String.raw`\p{${val}}`, 'u');
205
+
206
+ /*
207
+ grep -v '^#' DerivedGeneralCategory.txt \
208
+ | cut -d';' -f2 \
209
+ | awk 'NF{print $1}' \
210
+ | sort -u \
211
+ | awk '{printf "\x27%s\x27,\n",$1}'
212
+ */
213
+
214
+ const UnicodeCategories = Object.fromEntries(
215
+ [
216
+ 'Cc',
217
+ 'Cf',
218
+ 'Cn',
219
+ 'Co',
220
+ 'Cs',
221
+ 'Ll',
222
+ 'Lm',
223
+ 'Lo',
224
+ 'Lt',
225
+ 'Lu',
226
+ 'Mc',
227
+ 'Me',
228
+ 'Mn',
229
+ 'Nd',
230
+ 'Nl',
231
+ 'No',
232
+ 'Pc',
233
+ 'Pd',
234
+ 'Pe',
235
+ 'Pf',
236
+ 'Pi',
237
+ 'Po',
238
+ 'Ps',
239
+ 'Sc',
240
+ 'Sk',
241
+ 'Sm',
242
+ 'So',
243
+ 'Zl',
244
+ 'Zp',
245
+ 'Zs',
246
+ ].map(cat => [cat, toRegExp(cat)])
247
+ );
248
+ UnicodeCategories['Ltmo'] = /\p{Lt}|\p{Lm}|\p{Lo}/u;
249
+
250
+ // We only support a few of these for now, but could add more later.
251
+ // See https://www.unicode.org/Public/UCD/latest/ucd/PropertyAliases.txt
252
+ const UnicodeBinaryProperties = Object.fromEntries(
253
+ ['XID_Start', 'XID_Continue', 'White_Space'].map(prop => [prop, toRegExp(prop)])
254
+ );
231
255
 
232
256
  // --------------------------------------------------------------------
233
257
  // Private stuff
@@ -408,10 +432,18 @@ class Apply extends PExpr {
408
432
  // Unicode character
409
433
 
410
434
  class UnicodeChar extends PExpr {
411
- constructor(category) {
435
+ constructor(categoryOrProp) {
412
436
  super();
413
- this.category = category;
414
- this.pattern = UnicodeCategories[category];
437
+ this.categoryOrProp = categoryOrProp;
438
+ if (categoryOrProp in UnicodeCategories) {
439
+ this.pattern = UnicodeCategories[categoryOrProp];
440
+ } else if (categoryOrProp in UnicodeBinaryProperties) {
441
+ this.pattern = UnicodeBinaryProperties[categoryOrProp];
442
+ } else {
443
+ throw new Error(
444
+ `Invalid Unicode category or property name: ${JSON.stringify(categoryOrProp)}`
445
+ );
446
+ }
415
447
  }
416
448
  }
417
449
 
@@ -462,9 +494,9 @@ function grammarSyntaxError(matchFailure) {
462
494
  // Undeclared grammar
463
495
 
464
496
  function undeclaredGrammar(grammarName, namespace, interval) {
465
- const message = namespace ?
466
- `Grammar ${grammarName} is not declared in namespace '${namespace}'` :
467
- 'Undeclared grammar ' + grammarName;
497
+ const message = namespace
498
+ ? `Grammar ${grammarName} is not declared in namespace '${namespace}'`
499
+ : 'Undeclared grammar ' + grammarName;
468
500
  return createError(message, interval);
469
501
  }
470
502
 
@@ -484,8 +516,8 @@ function grammarDoesNotSupportIncrementalParsing(grammar) {
484
516
 
485
517
  function undeclaredRule(ruleName, grammarName, optInterval) {
486
518
  return createError(
487
- 'Rule ' + ruleName + ' is not declared in grammar ' + grammarName,
488
- optInterval,
519
+ 'Rule ' + ruleName + ' is not declared in grammar ' + grammarName,
520
+ optInterval
489
521
  );
490
522
  }
491
523
 
@@ -493,8 +525,8 @@ function undeclaredRule(ruleName, grammarName, optInterval) {
493
525
 
494
526
  function cannotOverrideUndeclaredRule(ruleName, grammarName, optSource) {
495
527
  return createError(
496
- 'Cannot override rule ' + ruleName + ' because it is not declared in ' + grammarName,
497
- optSource,
528
+ 'Cannot override rule ' + ruleName + ' because it is not declared in ' + grammarName,
529
+ optSource
498
530
  );
499
531
  }
500
532
 
@@ -502,8 +534,8 @@ function cannotOverrideUndeclaredRule(ruleName, grammarName, optSource) {
502
534
 
503
535
  function cannotExtendUndeclaredRule(ruleName, grammarName, optSource) {
504
536
  return createError(
505
- 'Cannot extend rule ' + ruleName + ' because it is not declared in ' + grammarName,
506
- optSource,
537
+ 'Cannot extend rule ' + ruleName + ' because it is not declared in ' + grammarName,
538
+ optSource
507
539
  );
508
540
  }
509
541
 
@@ -522,14 +554,14 @@ function duplicateRuleDeclaration(ruleName, grammarName, declGrammarName, optSou
522
554
 
523
555
  function wrongNumberOfParameters(ruleName, expected, actual, source) {
524
556
  return createError(
525
- 'Wrong number of parameters for rule ' +
557
+ 'Wrong number of parameters for rule ' +
526
558
  ruleName +
527
559
  ' (expected ' +
528
560
  expected +
529
561
  ', got ' +
530
562
  actual +
531
563
  ')',
532
- source,
564
+ source
533
565
  );
534
566
  }
535
567
 
@@ -537,14 +569,14 @@ function wrongNumberOfParameters(ruleName, expected, actual, source) {
537
569
 
538
570
  function wrongNumberOfArguments(ruleName, expected, actual, expr) {
539
571
  return createError(
540
- 'Wrong number of arguments for rule ' +
572
+ 'Wrong number of arguments for rule ' +
541
573
  ruleName +
542
574
  ' (expected ' +
543
575
  expected +
544
576
  ', got ' +
545
577
  actual +
546
578
  ')',
547
- expr,
579
+ expr
548
580
  );
549
581
  }
550
582
 
@@ -552,8 +584,8 @@ function wrongNumberOfArguments(ruleName, expected, actual, expr) {
552
584
 
553
585
  function duplicateParameterNames(ruleName, duplicates, source) {
554
586
  return createError(
555
- 'Duplicate parameter names in rule ' + ruleName + ': ' + duplicates.join(', '),
556
- source,
587
+ 'Duplicate parameter names in rule ' + ruleName + ': ' + duplicates.join(', '),
588
+ source
557
589
  );
558
590
  }
559
591
 
@@ -561,14 +593,14 @@ function duplicateParameterNames(ruleName, duplicates, source) {
561
593
 
562
594
  function invalidParameter(ruleName, expr) {
563
595
  return createError(
564
- 'Invalid parameter to rule ' +
596
+ 'Invalid parameter to rule ' +
565
597
  ruleName +
566
598
  ': ' +
567
599
  expr +
568
600
  ' has arity ' +
569
601
  expr.getArity() +
570
602
  ', but parameter expressions must have arity 1',
571
- expr.source,
603
+ expr.source
572
604
  );
573
605
  }
574
606
 
@@ -580,8 +612,8 @@ const syntacticVsLexicalNote =
580
612
 
581
613
  function applicationOfSyntacticRuleFromLexicalContext(ruleName, applyExpr) {
582
614
  return createError(
583
- 'Cannot apply syntactic rule ' + ruleName + ' from here (inside a lexical context)',
584
- applyExpr.source,
615
+ 'Cannot apply syntactic rule ' + ruleName + ' from here (inside a lexical context)',
616
+ applyExpr.source
585
617
  );
586
618
  }
587
619
 
@@ -590,9 +622,9 @@ function applicationOfSyntacticRuleFromLexicalContext(ruleName, applyExpr) {
590
622
  function applySyntacticWithLexicalRuleApplication(applyExpr) {
591
623
  const {ruleName} = applyExpr;
592
624
  return createError(
593
- `applySyntactic is for syntactic rules, but '${ruleName}' is a lexical rule. ` +
625
+ `applySyntactic is for syntactic rules, but '${ruleName}' is a lexical rule. ` +
594
626
  syntacticVsLexicalNote,
595
- applyExpr.source,
627
+ applyExpr.source
596
628
  );
597
629
  }
598
630
 
@@ -600,8 +632,8 @@ function applySyntacticWithLexicalRuleApplication(applyExpr) {
600
632
 
601
633
  function unnecessaryExperimentalApplySyntactic(applyExpr) {
602
634
  return createError(
603
- 'applySyntactic is not required here (in a syntactic context)',
604
- applyExpr.source,
635
+ 'applySyntactic is not required here (in a syntactic context)',
636
+ applyExpr.source
605
637
  );
606
638
  }
607
639
 
@@ -627,8 +659,8 @@ function invalidCodePoint(applyWrapper) {
627
659
  const digitIntervals = applyWrapper.children.slice(1, -1).map(d => d.source);
628
660
  const fullInterval = digitIntervals[0].coverageWith(...digitIntervals.slice(1));
629
661
  return createError(
630
- `U+${fullInterval.contents} is not a valid Unicode code point`,
631
- fullInterval,
662
+ `U+${fullInterval.contents} is not a valid Unicode code point`,
663
+ fullInterval
632
664
  );
633
665
  }
634
666
 
@@ -646,8 +678,8 @@ function kleeneExprHasNullableOperand(kleeneExpr, applicationStack) {
646
678
  "' (possible infinite loop)";
647
679
  if (applicationStack.length > 0) {
648
680
  const stackTrace = applicationStack
649
- .map(app => new Apply(app.ruleName, app.args))
650
- .join('\n');
681
+ .map(app => new Apply(app.ruleName, app.args))
682
+ .join('\n');
651
683
  message += '\nApplication stack (most recent application last):\n' + stackTrace;
652
684
  }
653
685
  return createError(message, kleeneExpr.expr.source);
@@ -657,7 +689,7 @@ function kleeneExprHasNullableOperand(kleeneExpr, applicationStack) {
657
689
 
658
690
  function inconsistentArity(ruleName, expected, actual, expr) {
659
691
  return createError(
660
- 'Rule ' +
692
+ 'Rule ' +
661
693
  ruleName +
662
694
  ' involves an alternation which has inconsistent arity ' +
663
695
  '(expected ' +
@@ -665,7 +697,7 @@ function inconsistentArity(ruleName, expected, actual, expr) {
665
697
  ', got ' +
666
698
  actual +
667
699
  ')',
668
- expr.source,
700
+ expr.source
669
701
  );
670
702
  }
671
703
 
@@ -680,12 +712,12 @@ function multipleErrors(errors) {
680
712
 
681
713
  function missingSemanticAction(ctorName, name, type, stack) {
682
714
  let stackTrace = stack
683
- .slice(0, -1)
684
- .map(info => {
685
- const ans = ' ' + info[0].name + ' > ' + info[1];
686
- return info.length === 3 ? ans + " for '" + info[2] + "'" : ans;
687
- })
688
- .join('\n');
715
+ .slice(0, -1)
716
+ .map(info => {
717
+ const ans = ' ' + info[0].name + ' > ' + info[1];
718
+ return info.length === 3 ? ans + " for '" + info[2] + "'" : ans;
719
+ })
720
+ .join('\n');
689
721
  stackTrace += '\n ' + name + ' > ' + ctorName;
690
722
 
691
723
  let moreInfo = '';
@@ -850,9 +882,9 @@ function getLineAndColumn(str, offset) {
850
882
  // Get the next line.
851
883
  const nextLineEndOffset = str.indexOf('\n', lineEndOffset + 1);
852
884
  nextLine =
853
- nextLineEndOffset === -1 ?
854
- str.slice(lineEndOffset) :
855
- str.slice(lineEndOffset, nextLineEndOffset);
885
+ nextLineEndOffset === -1
886
+ ? str.slice(lineEndOffset)
887
+ : str.slice(lineEndOffset, nextLineEndOffset);
856
888
  // Strip leading and trailing EOL char(s).
857
889
  nextLine = nextLine.replace(/^\r?\n/, '').replace(/\r$/, '');
858
890
  }
@@ -894,11 +926,23 @@ const uniqueId = (() => {
894
926
 
895
927
  class Interval {
896
928
  constructor(sourceString, startIdx, endIdx) {
897
- this.sourceString = sourceString;
929
+ // Store the full source in a non-enumerable property, so that when
930
+ // grammars and other objects are printed in the REPL, it's not
931
+ // cluttered with multiple copies of the same long string.
932
+ Object.defineProperty(this, '_sourceString', {
933
+ value: sourceString,
934
+ configurable: false,
935
+ enumerable: false,
936
+ writable: false,
937
+ });
898
938
  this.startIdx = startIdx;
899
939
  this.endIdx = endIdx;
900
940
  }
901
941
 
942
+ get sourceString() {
943
+ return this._sourceString;
944
+ }
945
+
902
946
  get contents() {
903
947
  if (this._contents === undefined) {
904
948
  this._contents = this.sourceString.slice(this.startIdx, this.endIdx);
@@ -964,13 +1008,13 @@ class Interval {
964
1008
  throw intervalSourcesDontMatch();
965
1009
  }
966
1010
  assert(
967
- this.startIdx >= that.startIdx && this.endIdx <= that.endIdx,
968
- 'other interval does not cover this one',
1011
+ this.startIdx >= that.startIdx && this.endIdx <= that.endIdx,
1012
+ 'other interval does not cover this one'
969
1013
  );
970
1014
  return new Interval(
971
- this.sourceString,
972
- this.startIdx - that.startIdx,
973
- this.endIdx - that.startIdx,
1015
+ this.sourceString,
1016
+ this.startIdx - that.startIdx,
1017
+ this.endIdx - that.startIdx
974
1018
  );
975
1019
  }
976
1020
 
@@ -989,7 +1033,7 @@ class Interval {
989
1033
  }
990
1034
  }
991
1035
 
992
- Interval.coverage = function(firstInterval, ...intervals) {
1036
+ Interval.coverage = function (firstInterval, ...intervals) {
993
1037
  let {startIdx, endIdx} = firstInterval;
994
1038
  for (const interval of intervals) {
995
1039
  if (interval.sourceString !== firstInterval.sourceString) {
@@ -1003,6 +1047,7 @@ Interval.coverage = function(firstInterval, ...intervals) {
1003
1047
  };
1004
1048
 
1005
1049
  const MAX_CHAR_CODE = 0xffff;
1050
+ const MAX_CODE_POINT = 0x10ffff;
1006
1051
 
1007
1052
  class InputStream {
1008
1053
  constructor(source) {
@@ -1048,6 +1093,8 @@ class InputStream {
1048
1093
 
1049
1094
  This is intended to be a locale-invariant comparison, which means it may not obey
1050
1095
  locale-specific expectations (e.g. "i" => "İ").
1096
+
1097
+ See also https://unicode.org/faq/casemap_charprop.html#casemap
1051
1098
  */
1052
1099
  for (idx = 0; idx < s.length; idx++) {
1053
1100
  const actual = this.next();
@@ -1082,13 +1129,13 @@ class InputStream {
1082
1129
 
1083
1130
  class MatchResult {
1084
1131
  constructor(
1085
- matcher,
1086
- input,
1087
- startExpr,
1088
- cst,
1089
- cstOffset,
1090
- rightmostFailurePosition,
1091
- optRecordedFailures,
1132
+ matcher,
1133
+ input,
1134
+ startExpr,
1135
+ cst,
1136
+ cstOffset,
1137
+ rightmostFailurePosition,
1138
+ optRecordedFailures
1092
1139
  ) {
1093
1140
  this.matcher = matcher;
1094
1141
  this.input = input;
@@ -1099,22 +1146,20 @@ class MatchResult {
1099
1146
  this._rightmostFailures = optRecordedFailures;
1100
1147
 
1101
1148
  if (this.failed()) {
1102
- /* eslint-disable no-invalid-this */
1103
- defineLazyProperty(this, 'message', function() {
1149
+ defineLazyProperty(this, 'message', function () {
1104
1150
  const detail = 'Expected ' + this.getExpectedText();
1105
1151
  return (
1106
1152
  getLineAndColumnMessage(this.input, this.getRightmostFailurePosition()) + detail
1107
1153
  );
1108
1154
  });
1109
- defineLazyProperty(this, 'shortMessage', function() {
1155
+ defineLazyProperty(this, 'shortMessage', function () {
1110
1156
  const detail = 'expected ' + this.getExpectedText();
1111
1157
  const errorInfo = getLineAndColumn(
1112
- this.input,
1113
- this.getRightmostFailurePosition(),
1158
+ this.input,
1159
+ this.getRightmostFailurePosition()
1114
1160
  );
1115
1161
  return 'Line ' + errorInfo.lineNum + ', col ' + errorInfo.colNum + ': ' + detail;
1116
1162
  });
1117
- /* eslint-enable no-invalid-this */
1118
1163
  }
1119
1164
  }
1120
1165
 
@@ -1143,9 +1188,9 @@ class MatchResult {
1143
1188
  }
1144
1189
 
1145
1190
  toString() {
1146
- return this.succeeded() ?
1147
- '[match succeeded]' :
1148
- '[match failed at position ' + this.getRightmostFailurePosition() + ']';
1191
+ return this.succeeded()
1192
+ ? '[match succeeded]'
1193
+ : '[match failed at position ' + this.getRightmostFailurePosition() + ']';
1149
1194
  }
1150
1195
 
1151
1196
  // Return a string summarizing the expected contents of the input stream when
@@ -1211,14 +1256,14 @@ class PosInfo {
1211
1256
  const indexOfFirstInvolvedRule =
1212
1257
  applicationMemoKeyStack.indexOf(headApplication.toMemoKey()) + 1;
1213
1258
  const involvedApplicationMemoKeys = applicationMemoKeyStack.slice(
1214
- indexOfFirstInvolvedRule,
1259
+ indexOfFirstInvolvedRule
1215
1260
  );
1216
1261
 
1217
- memoRec.isInvolved = function(applicationMemoKey) {
1262
+ memoRec.isInvolved = function (applicationMemoKey) {
1218
1263
  return involvedApplicationMemoKeys.indexOf(applicationMemoKey) >= 0;
1219
1264
  };
1220
1265
 
1221
- memoRec.updateInvolvedApplicationMemoKeys = function() {
1266
+ memoRec.updateInvolvedApplicationMemoKeys = function () {
1222
1267
  for (let idx = indexOfFirstInvolvedRule; idx < applicationMemoKeyStack.length; idx++) {
1223
1268
  const applicationMemoKey = applicationMemoKeyStack[idx];
1224
1269
  if (!this.isInvolved(applicationMemoKey)) {
@@ -1252,8 +1297,8 @@ class PosInfo {
1252
1297
  this.memo[memoKey] = memoRec;
1253
1298
  this.maxExaminedLength = Math.max(this.maxExaminedLength, memoRec.examinedLength);
1254
1299
  this.maxRightmostFailureOffset = Math.max(
1255
- this.maxRightmostFailureOffset,
1256
- memoRec.rightmostFailureOffset,
1300
+ this.maxRightmostFailureOffset,
1301
+ memoRec.rightmostFailureOffset
1257
1302
  );
1258
1303
  return memoRec;
1259
1304
  }
@@ -1275,8 +1320,8 @@ class PosInfo {
1275
1320
  } else {
1276
1321
  this.maxExaminedLength = Math.max(this.maxExaminedLength, memoRec.examinedLength);
1277
1322
  this.maxRightmostFailureOffset = Math.max(
1278
- this.maxRightmostFailureOffset,
1279
- memoRec.rightmostFailureOffset,
1323
+ this.maxRightmostFailureOffset,
1324
+ memoRec.rightmostFailureOffset
1280
1325
  );
1281
1326
  }
1282
1327
  });
@@ -1325,10 +1370,10 @@ function asEscapedString(obj) {
1325
1370
  if (typeof obj === 'string') {
1326
1371
  // Replace non-printable characters with visible symbols.
1327
1372
  return obj
1328
- .replace(/ /g, DOT_OPERATOR)
1329
- .replace(/\t/g, SYMBOL_FOR_HORIZONTAL_TABULATION)
1330
- .replace(/\n/g, SYMBOL_FOR_LINE_FEED)
1331
- .replace(/\r/g, SYMBOL_FOR_CARRIAGE_RETURN);
1373
+ .replace(/ /g, DOT_OPERATOR)
1374
+ .replace(/\t/g, SYMBOL_FOR_HORIZONTAL_TABULATION)
1375
+ .replace(/\n/g, SYMBOL_FOR_LINE_FEED)
1376
+ .replace(/\r/g, SYMBOL_FOR_CARRIAGE_RETURN);
1332
1377
  }
1333
1378
  return String(obj);
1334
1379
  }
@@ -1359,13 +1404,13 @@ class Trace {
1359
1404
 
1360
1405
  cloneWithExpr(expr) {
1361
1406
  const ans = new Trace(
1362
- this.input,
1363
- this.pos,
1364
- this.pos2,
1365
- expr,
1366
- this.succeeded,
1367
- this.bindings,
1368
- this.children,
1407
+ this.input,
1408
+ this.pos,
1409
+ this.pos2,
1410
+ expr,
1411
+ this.succeeded,
1412
+ this.bindings,
1413
+ this.children
1369
1414
  );
1370
1415
 
1371
1416
  ans.isHeadOfLeftRecursion = this.isHeadOfLeftRecursion;
@@ -1380,13 +1425,13 @@ class Trace {
1380
1425
  // Record the trace information for the terminating condition of the LR loop.
1381
1426
  recordLRTermination(ruleBodyTrace, value) {
1382
1427
  this.terminatingLREntry = new Trace(
1383
- this.input,
1384
- this.pos,
1385
- this.pos2,
1386
- this.expr,
1387
- false,
1388
- [value],
1389
- [ruleBodyTrace],
1428
+ this.input,
1429
+ this.pos,
1430
+ this.pos2,
1431
+ this.expr,
1432
+ false,
1433
+ [value],
1434
+ [ruleBodyTrace]
1390
1435
  );
1391
1436
  this.terminatingLREntry.terminatesLR = true;
1392
1437
  }
@@ -1446,7 +1491,7 @@ class Trace {
1446
1491
  const ctorName = node.expr.constructor.name;
1447
1492
  // Don't print anything for Alt nodes.
1448
1493
  if (ctorName === 'Alt') {
1449
- return; // eslint-disable-line consistent-return
1494
+ return;
1450
1495
  }
1451
1496
  sb.append(getInputExcerpt(node.input, node.pos, 10) + spaces(depth * 2 + 1));
1452
1497
  sb.append((node.succeeded ? CHECK_MARK : BALLOT_X) + ' ' + node.displayString);
@@ -1504,7 +1549,7 @@ any.allowsSkippingPrecedingSpace =
1504
1549
  Terminal.prototype.allowsSkippingPrecedingSpace =
1505
1550
  Range.prototype.allowsSkippingPrecedingSpace =
1506
1551
  UnicodeChar.prototype.allowsSkippingPrecedingSpace =
1507
- function() {
1552
+ function () {
1508
1553
  return true;
1509
1554
  };
1510
1555
 
@@ -1518,7 +1563,7 @@ Alt.prototype.allowsSkippingPrecedingSpace =
1518
1563
  Not.prototype.allowsSkippingPrecedingSpace =
1519
1564
  Param.prototype.allowsSkippingPrecedingSpace =
1520
1565
  Seq.prototype.allowsSkippingPrecedingSpace =
1521
- function() {
1566
+ function () {
1522
1567
  return false;
1523
1568
  };
1524
1569
 
@@ -1534,13 +1579,13 @@ awaitBuiltInRules(g => {
1534
1579
 
1535
1580
  let lexifyCount;
1536
1581
 
1537
- PExpr.prototype.assertAllApplicationsAreValid = function(ruleName, grammar) {
1582
+ PExpr.prototype.assertAllApplicationsAreValid = function (ruleName, grammar) {
1538
1583
  lexifyCount = 0;
1539
1584
  this._assertAllApplicationsAreValid(ruleName, grammar);
1540
1585
  };
1541
1586
 
1542
1587
  PExpr.prototype._assertAllApplicationsAreValid = abstract(
1543
- '_assertAllApplicationsAreValid',
1588
+ '_assertAllApplicationsAreValid'
1544
1589
  );
1545
1590
 
1546
1591
  any._assertAllApplicationsAreValid =
@@ -1549,23 +1594,23 @@ any._assertAllApplicationsAreValid =
1549
1594
  Range.prototype._assertAllApplicationsAreValid =
1550
1595
  Param.prototype._assertAllApplicationsAreValid =
1551
1596
  UnicodeChar.prototype._assertAllApplicationsAreValid =
1552
- function(ruleName, grammar) {
1597
+ function (ruleName, grammar) {
1553
1598
  // no-op
1554
1599
  };
1555
1600
 
1556
- Lex.prototype._assertAllApplicationsAreValid = function(ruleName, grammar) {
1601
+ Lex.prototype._assertAllApplicationsAreValid = function (ruleName, grammar) {
1557
1602
  lexifyCount++;
1558
1603
  this.expr._assertAllApplicationsAreValid(ruleName, grammar);
1559
1604
  lexifyCount--;
1560
1605
  };
1561
1606
 
1562
- Alt.prototype._assertAllApplicationsAreValid = function(ruleName, grammar) {
1607
+ Alt.prototype._assertAllApplicationsAreValid = function (ruleName, grammar) {
1563
1608
  for (let idx = 0; idx < this.terms.length; idx++) {
1564
1609
  this.terms[idx]._assertAllApplicationsAreValid(ruleName, grammar);
1565
1610
  }
1566
1611
  };
1567
1612
 
1568
- Seq.prototype._assertAllApplicationsAreValid = function(ruleName, grammar) {
1613
+ Seq.prototype._assertAllApplicationsAreValid = function (ruleName, grammar) {
1569
1614
  for (let idx = 0; idx < this.factors.length; idx++) {
1570
1615
  this.factors[idx]._assertAllApplicationsAreValid(ruleName, grammar);
1571
1616
  }
@@ -1574,14 +1619,14 @@ Seq.prototype._assertAllApplicationsAreValid = function(ruleName, grammar) {
1574
1619
  Iter.prototype._assertAllApplicationsAreValid =
1575
1620
  Not.prototype._assertAllApplicationsAreValid =
1576
1621
  Lookahead.prototype._assertAllApplicationsAreValid =
1577
- function(ruleName, grammar) {
1622
+ function (ruleName, grammar) {
1578
1623
  this.expr._assertAllApplicationsAreValid(ruleName, grammar);
1579
1624
  };
1580
1625
 
1581
- Apply.prototype._assertAllApplicationsAreValid = function(
1582
- ruleName,
1583
- grammar,
1584
- skipSyntacticCheck = false,
1626
+ Apply.prototype._assertAllApplicationsAreValid = function (
1627
+ ruleName,
1628
+ grammar,
1629
+ skipSyntacticCheck = false
1585
1630
  ) {
1586
1631
  const ruleInfo = grammar.rules[this.ruleName];
1587
1632
  const isContextSyntactic = isSyntactic(ruleName) && lexifyCount === 0;
@@ -1644,7 +1689,7 @@ Apply.prototype._assertAllApplicationsAreValid = function(
1644
1689
  // --------------------------------------------------------------------
1645
1690
 
1646
1691
  PExpr.prototype.assertChoicesHaveUniformArity = abstract(
1647
- 'assertChoicesHaveUniformArity',
1692
+ 'assertChoicesHaveUniformArity'
1648
1693
  );
1649
1694
 
1650
1695
  any.assertChoicesHaveUniformArity =
@@ -1654,11 +1699,11 @@ any.assertChoicesHaveUniformArity =
1654
1699
  Param.prototype.assertChoicesHaveUniformArity =
1655
1700
  Lex.prototype.assertChoicesHaveUniformArity =
1656
1701
  UnicodeChar.prototype.assertChoicesHaveUniformArity =
1657
- function(ruleName) {
1702
+ function (ruleName) {
1658
1703
  // no-op
1659
1704
  };
1660
1705
 
1661
- Alt.prototype.assertChoicesHaveUniformArity = function(ruleName) {
1706
+ Alt.prototype.assertChoicesHaveUniformArity = function (ruleName) {
1662
1707
  if (this.terms.length === 0) {
1663
1708
  return;
1664
1709
  }
@@ -1673,7 +1718,7 @@ Alt.prototype.assertChoicesHaveUniformArity = function(ruleName) {
1673
1718
  }
1674
1719
  };
1675
1720
 
1676
- Extend.prototype.assertChoicesHaveUniformArity = function(ruleName) {
1721
+ Extend.prototype.assertChoicesHaveUniformArity = function (ruleName) {
1677
1722
  // Extend is a special case of Alt that's guaranteed to have exactly two
1678
1723
  // cases: [extensions, origBody].
1679
1724
  const actualArity = this.terms[0].getArity();
@@ -1683,25 +1728,25 @@ Extend.prototype.assertChoicesHaveUniformArity = function(ruleName) {
1683
1728
  }
1684
1729
  };
1685
1730
 
1686
- Seq.prototype.assertChoicesHaveUniformArity = function(ruleName) {
1731
+ Seq.prototype.assertChoicesHaveUniformArity = function (ruleName) {
1687
1732
  for (let idx = 0; idx < this.factors.length; idx++) {
1688
1733
  this.factors[idx].assertChoicesHaveUniformArity(ruleName);
1689
1734
  }
1690
1735
  };
1691
1736
 
1692
- Iter.prototype.assertChoicesHaveUniformArity = function(ruleName) {
1737
+ Iter.prototype.assertChoicesHaveUniformArity = function (ruleName) {
1693
1738
  this.expr.assertChoicesHaveUniformArity(ruleName);
1694
1739
  };
1695
1740
 
1696
- Not.prototype.assertChoicesHaveUniformArity = function(ruleName) {
1741
+ Not.prototype.assertChoicesHaveUniformArity = function (ruleName) {
1697
1742
  // no-op (not required b/c the nested expr doesn't show up in the CST)
1698
1743
  };
1699
1744
 
1700
- Lookahead.prototype.assertChoicesHaveUniformArity = function(ruleName) {
1745
+ Lookahead.prototype.assertChoicesHaveUniformArity = function (ruleName) {
1701
1746
  this.expr.assertChoicesHaveUniformArity(ruleName);
1702
1747
  };
1703
1748
 
1704
- Apply.prototype.assertChoicesHaveUniformArity = function(ruleName) {
1749
+ Apply.prototype.assertChoicesHaveUniformArity = function (ruleName) {
1705
1750
  // The arities of the parameter expressions is required to be 1 by
1706
1751
  // `assertAllApplicationsAreValid()`.
1707
1752
  };
@@ -1711,7 +1756,7 @@ Apply.prototype.assertChoicesHaveUniformArity = function(ruleName) {
1711
1756
  // --------------------------------------------------------------------
1712
1757
 
1713
1758
  PExpr.prototype.assertIteratedExprsAreNotNullable = abstract(
1714
- 'assertIteratedExprsAreNotNullable',
1759
+ 'assertIteratedExprsAreNotNullable'
1715
1760
  );
1716
1761
 
1717
1762
  any.assertIteratedExprsAreNotNullable =
@@ -1720,23 +1765,23 @@ any.assertIteratedExprsAreNotNullable =
1720
1765
  Range.prototype.assertIteratedExprsAreNotNullable =
1721
1766
  Param.prototype.assertIteratedExprsAreNotNullable =
1722
1767
  UnicodeChar.prototype.assertIteratedExprsAreNotNullable =
1723
- function(grammar) {
1768
+ function (grammar) {
1724
1769
  // no-op
1725
1770
  };
1726
1771
 
1727
- Alt.prototype.assertIteratedExprsAreNotNullable = function(grammar) {
1772
+ Alt.prototype.assertIteratedExprsAreNotNullable = function (grammar) {
1728
1773
  for (let idx = 0; idx < this.terms.length; idx++) {
1729
1774
  this.terms[idx].assertIteratedExprsAreNotNullable(grammar);
1730
1775
  }
1731
1776
  };
1732
1777
 
1733
- Seq.prototype.assertIteratedExprsAreNotNullable = function(grammar) {
1778
+ Seq.prototype.assertIteratedExprsAreNotNullable = function (grammar) {
1734
1779
  for (let idx = 0; idx < this.factors.length; idx++) {
1735
1780
  this.factors[idx].assertIteratedExprsAreNotNullable(grammar);
1736
1781
  }
1737
1782
  };
1738
1783
 
1739
- Iter.prototype.assertIteratedExprsAreNotNullable = function(grammar) {
1784
+ Iter.prototype.assertIteratedExprsAreNotNullable = function (grammar) {
1740
1785
  // Note: this is the implementation of this method for `Star` and `Plus` expressions.
1741
1786
  // It is overridden for `Opt` below.
1742
1787
  this.expr.assertIteratedExprsAreNotNullable(grammar);
@@ -1749,11 +1794,11 @@ Opt.prototype.assertIteratedExprsAreNotNullable =
1749
1794
  Not.prototype.assertIteratedExprsAreNotNullable =
1750
1795
  Lookahead.prototype.assertIteratedExprsAreNotNullable =
1751
1796
  Lex.prototype.assertIteratedExprsAreNotNullable =
1752
- function(grammar) {
1797
+ function (grammar) {
1753
1798
  this.expr.assertIteratedExprsAreNotNullable(grammar);
1754
1799
  };
1755
1800
 
1756
- Apply.prototype.assertIteratedExprsAreNotNullable = function(grammar) {
1801
+ Apply.prototype.assertIteratedExprsAreNotNullable = function (grammar) {
1757
1802
  this.args.forEach(arg => {
1758
1803
  arg.assertIteratedExprsAreNotNullable(grammar);
1759
1804
  });
@@ -1797,11 +1842,11 @@ class Node {
1797
1842
  onlyChild() {
1798
1843
  if (this.numChildren() !== 1) {
1799
1844
  throw new Error(
1800
- 'cannot get only child of a node of type ' +
1845
+ 'cannot get only child of a node of type ' +
1801
1846
  this.ctorName +
1802
1847
  ' (it has ' +
1803
1848
  this.numChildren() +
1804
- ' children)',
1849
+ ' children)'
1805
1850
  );
1806
1851
  } else {
1807
1852
  return this.firstChild();
@@ -1811,7 +1856,7 @@ class Node {
1811
1856
  firstChild() {
1812
1857
  if (this.hasNoChildren()) {
1813
1858
  throw new Error(
1814
- 'cannot get first child of a ' + this.ctorName + ' node, which has no children',
1859
+ 'cannot get first child of a ' + this.ctorName + ' node, which has no children'
1815
1860
  );
1816
1861
  } else {
1817
1862
  return this.childAt(0);
@@ -1821,7 +1866,7 @@ class Node {
1821
1866
  lastChild() {
1822
1867
  if (this.hasNoChildren()) {
1823
1868
  throw new Error(
1824
- 'cannot get last child of a ' + this.ctorName + ' node, which has no children',
1869
+ 'cannot get last child of a ' + this.ctorName + ' node, which has no children'
1825
1870
  );
1826
1871
  } else {
1827
1872
  return this.childAt(this.numChildren() - 1);
@@ -1955,7 +2000,7 @@ class IterationNode extends Node {
1955
2000
  */
1956
2001
  PExpr.prototype.eval = abstract('eval'); // function(state) { ... }
1957
2002
 
1958
- any.eval = function(state) {
2003
+ any.eval = function (state) {
1959
2004
  const {inputStream} = state;
1960
2005
  const origPos = inputStream.pos;
1961
2006
  const cp = inputStream.nextCodePoint();
@@ -1968,7 +2013,7 @@ any.eval = function(state) {
1968
2013
  }
1969
2014
  };
1970
2015
 
1971
- end.eval = function(state) {
2016
+ end.eval = function (state) {
1972
2017
  const {inputStream} = state;
1973
2018
  const origPos = inputStream.pos;
1974
2019
  if (inputStream.atEnd()) {
@@ -1980,7 +2025,7 @@ end.eval = function(state) {
1980
2025
  }
1981
2026
  };
1982
2027
 
1983
- Terminal.prototype.eval = function(state) {
2028
+ Terminal.prototype.eval = function (state) {
1984
2029
  const {inputStream} = state;
1985
2030
  const origPos = inputStream.pos;
1986
2031
  if (!inputStream.matchString(this.obj)) {
@@ -1992,7 +2037,7 @@ Terminal.prototype.eval = function(state) {
1992
2037
  }
1993
2038
  };
1994
2039
 
1995
- Range.prototype.eval = function(state) {
2040
+ Range.prototype.eval = function (state) {
1996
2041
  const {inputStream} = state;
1997
2042
  const origPos = inputStream.pos;
1998
2043
 
@@ -2011,18 +2056,18 @@ Range.prototype.eval = function(state) {
2011
2056
  }
2012
2057
  };
2013
2058
 
2014
- Param.prototype.eval = function(state) {
2059
+ Param.prototype.eval = function (state) {
2015
2060
  return state.eval(state.currentApplication().args[this.index]);
2016
2061
  };
2017
2062
 
2018
- Lex.prototype.eval = function(state) {
2063
+ Lex.prototype.eval = function (state) {
2019
2064
  state.enterLexifiedContext();
2020
2065
  const ans = state.eval(this.expr);
2021
2066
  state.exitLexifiedContext();
2022
2067
  return ans;
2023
2068
  };
2024
2069
 
2025
- Alt.prototype.eval = function(state) {
2070
+ Alt.prototype.eval = function (state) {
2026
2071
  for (let idx = 0; idx < this.terms.length; idx++) {
2027
2072
  if (state.eval(this.terms[idx])) {
2028
2073
  return true;
@@ -2031,7 +2076,7 @@ Alt.prototype.eval = function(state) {
2031
2076
  return false;
2032
2077
  };
2033
2078
 
2034
- Seq.prototype.eval = function(state) {
2079
+ Seq.prototype.eval = function (state) {
2035
2080
  for (let idx = 0; idx < this.factors.length; idx++) {
2036
2081
  const factor = this.factors[idx];
2037
2082
  if (!state.eval(factor)) {
@@ -2041,7 +2086,7 @@ Seq.prototype.eval = function(state) {
2041
2086
  return true;
2042
2087
  };
2043
2088
 
2044
- Iter.prototype.eval = function(state) {
2089
+ Iter.prototype.eval = function (state) {
2045
2090
  const {inputStream} = state;
2046
2091
  const origPos = inputStream.pos;
2047
2092
  const arity = this.getArity();
@@ -2063,8 +2108,8 @@ Iter.prototype.eval = function(state) {
2063
2108
  numMatches++;
2064
2109
  const row = state._bindings.splice(state._bindings.length - arity, arity);
2065
2110
  const rowOffsets = state._bindingOffsets.splice(
2066
- state._bindingOffsets.length - arity,
2067
- arity,
2111
+ state._bindingOffsets.length - arity,
2112
+ arity
2068
2113
  );
2069
2114
  for (idx = 0; idx < row.length; idx++) {
2070
2115
  cols[idx].push(row[idx]);
@@ -2088,14 +2133,14 @@ Iter.prototype.eval = function(state) {
2088
2133
  const isOptional = this instanceof Opt;
2089
2134
  for (idx = 0; idx < cols.length; idx++) {
2090
2135
  state._bindings.push(
2091
- new IterationNode(cols[idx], colOffsets[idx], matchLength, isOptional),
2136
+ new IterationNode(cols[idx], colOffsets[idx], matchLength, isOptional)
2092
2137
  );
2093
2138
  state._bindingOffsets.push(offset);
2094
2139
  }
2095
2140
  return true;
2096
2141
  };
2097
2142
 
2098
- Not.prototype.eval = function(state) {
2143
+ Not.prototype.eval = function (state) {
2099
2144
  /*
2100
2145
  TODO:
2101
2146
  - Right now we're just throwing away all of the failures that happen inside a `not`, and
@@ -2121,7 +2166,7 @@ Not.prototype.eval = function(state) {
2121
2166
  return true;
2122
2167
  };
2123
2168
 
2124
- Lookahead.prototype.eval = function(state) {
2169
+ Lookahead.prototype.eval = function (state) {
2125
2170
  const {inputStream} = state;
2126
2171
  const origPos = inputStream.pos;
2127
2172
  if (state.eval(this.expr)) {
@@ -2132,7 +2177,7 @@ Lookahead.prototype.eval = function(state) {
2132
2177
  }
2133
2178
  };
2134
2179
 
2135
- Apply.prototype.eval = function(state) {
2180
+ Apply.prototype.eval = function (state) {
2136
2181
  const caller = state.currentApplication();
2137
2182
  const actuals = caller ? caller.args : [];
2138
2183
  const app = this.substituteParams(actuals);
@@ -2155,7 +2200,7 @@ Apply.prototype.eval = function(state) {
2155
2200
  return app.reallyEval(state);
2156
2201
  };
2157
2202
 
2158
- Apply.prototype.handleCycle = function(state) {
2203
+ Apply.prototype.handleCycle = function (state) {
2159
2204
  const posInfo = state.getCurrentPosInfo();
2160
2205
  const {currentLeftRecursion} = posInfo;
2161
2206
  const memoKey = this.toMemoKey();
@@ -2178,7 +2223,7 @@ Apply.prototype.handleCycle = function(state) {
2178
2223
  return state.useMemoizedResult(state.inputStream.pos, memoRec);
2179
2224
  };
2180
2225
 
2181
- Apply.prototype.reallyEval = function(state) {
2226
+ Apply.prototype.reallyEval = function (state) {
2182
2227
  const {inputStream} = state;
2183
2228
  const origPos = inputStream.pos;
2184
2229
  const origPosInfo = state.getCurrentPosInfo();
@@ -2231,6 +2276,7 @@ Apply.prototype.reallyEval = function(state) {
2231
2276
  }
2232
2277
  if (memoRec) {
2233
2278
  memoRec.failuresAtRightmostPosition = state.cloneRecordedFailures();
2279
+ memoRec.rightmostFailureOffset = state._getRightmostFailureOffset();
2234
2280
  }
2235
2281
  }
2236
2282
 
@@ -2248,8 +2294,8 @@ Apply.prototype.reallyEval = function(state) {
2248
2294
  // Fix the input stream's examinedLength -- it should be the maximum examined length
2249
2295
  // across all applications, not just this one.
2250
2296
  inputStream.examinedLength = Math.max(
2251
- inputStream.examinedLength,
2252
- origInputStreamExaminedLength,
2297
+ inputStream.examinedLength,
2298
+ origInputStreamExaminedLength
2253
2299
  );
2254
2300
 
2255
2301
  state.exitApplication(origPosInfo, value);
@@ -2257,7 +2303,7 @@ Apply.prototype.reallyEval = function(state) {
2257
2303
  return succeeded;
2258
2304
  };
2259
2305
 
2260
- Apply.prototype.evalOnce = function(expr, state) {
2306
+ Apply.prototype.evalOnce = function (expr, state) {
2261
2307
  const {inputStream} = state;
2262
2308
  const origPos = inputStream.pos;
2263
2309
 
@@ -2272,7 +2318,7 @@ Apply.prototype.evalOnce = function(expr, state) {
2272
2318
  }
2273
2319
  };
2274
2320
 
2275
- Apply.prototype.growSeedResult = function(body, state, origPos, lrMemoRec, newValue) {
2321
+ Apply.prototype.growSeedResult = function (body, state, origPos, lrMemoRec, newValue) {
2276
2322
  if (!newValue) {
2277
2323
  return false;
2278
2324
  }
@@ -2290,13 +2336,13 @@ Apply.prototype.growSeedResult = function(body, state, origPos, lrMemoRec, newVa
2290
2336
  // element in `state.trace`.
2291
2337
  const seedTrace = state.trace[state.trace.length - 1];
2292
2338
  lrMemoRec.traceEntry = new Trace(
2293
- state.input,
2294
- origPos,
2295
- inputStream.pos,
2296
- this,
2297
- true,
2298
- [newValue],
2299
- [seedTrace.clone()],
2339
+ state.input,
2340
+ origPos,
2341
+ inputStream.pos,
2342
+ this,
2343
+ true,
2344
+ [newValue],
2345
+ [seedTrace.clone()]
2300
2346
  );
2301
2347
  }
2302
2348
  inputStream.pos = origPos;
@@ -2316,17 +2362,19 @@ Apply.prototype.growSeedResult = function(body, state, origPos, lrMemoRec, newVa
2316
2362
  return lrMemoRec.value;
2317
2363
  };
2318
2364
 
2319
- UnicodeChar.prototype.eval = function(state) {
2365
+ UnicodeChar.prototype.eval = function (state) {
2320
2366
  const {inputStream} = state;
2321
2367
  const origPos = inputStream.pos;
2322
- const ch = inputStream.next();
2323
- if (ch && this.pattern.test(ch)) {
2324
- state.pushBinding(new TerminalNode(ch.length), origPos);
2325
- return true;
2326
- } else {
2327
- state.processFailure(origPos, this);
2328
- return false;
2368
+ const cp = inputStream.nextCodePoint();
2369
+ if (cp !== undefined && cp <= MAX_CODE_POINT) {
2370
+ const ch = String.fromCodePoint(cp);
2371
+ if (this.pattern.test(ch)) {
2372
+ state.pushBinding(new TerminalNode(ch.length), origPos);
2373
+ return true;
2374
+ }
2329
2375
  }
2376
+ state.processFailure(origPos, this);
2377
+ return false;
2330
2378
  };
2331
2379
 
2332
2380
  // --------------------------------------------------------------------
@@ -2342,17 +2390,17 @@ any.getArity =
2342
2390
  Param.prototype.getArity =
2343
2391
  Apply.prototype.getArity =
2344
2392
  UnicodeChar.prototype.getArity =
2345
- function() {
2393
+ function () {
2346
2394
  return 1;
2347
2395
  };
2348
2396
 
2349
- Alt.prototype.getArity = function() {
2397
+ Alt.prototype.getArity = function () {
2350
2398
  // This is ok b/c all terms must have the same arity -- this property is
2351
2399
  // checked by the Grammar constructor.
2352
2400
  return this.terms.length === 0 ? 0 : this.terms[0].getArity();
2353
2401
  };
2354
2402
 
2355
- Seq.prototype.getArity = function() {
2403
+ Seq.prototype.getArity = function () {
2356
2404
  let arity = 0;
2357
2405
  for (let idx = 0; idx < this.factors.length; idx++) {
2358
2406
  arity += this.factors[idx].getArity();
@@ -2360,15 +2408,15 @@ Seq.prototype.getArity = function() {
2360
2408
  return arity;
2361
2409
  };
2362
2410
 
2363
- Iter.prototype.getArity = function() {
2411
+ Iter.prototype.getArity = function () {
2364
2412
  return this.expr.getArity();
2365
2413
  };
2366
2414
 
2367
- Not.prototype.getArity = function() {
2415
+ Not.prototype.getArity = function () {
2368
2416
  return 0;
2369
2417
  };
2370
2418
 
2371
- Lookahead.prototype.getArity = Lex.prototype.getArity = function() {
2419
+ Lookahead.prototype.getArity = Lex.prototype.getArity = function () {
2372
2420
  return this.expr.getArity();
2373
2421
  };
2374
2422
 
@@ -2391,38 +2439,38 @@ function getMetaInfo(expr, grammarInterval) {
2391
2439
 
2392
2440
  PExpr.prototype.outputRecipe = abstract('outputRecipe');
2393
2441
 
2394
- any.outputRecipe = function(formals, grammarInterval) {
2442
+ any.outputRecipe = function (formals, grammarInterval) {
2395
2443
  return ['any', getMetaInfo(this, grammarInterval)];
2396
2444
  };
2397
2445
 
2398
- end.outputRecipe = function(formals, grammarInterval) {
2446
+ end.outputRecipe = function (formals, grammarInterval) {
2399
2447
  return ['end', getMetaInfo(this, grammarInterval)];
2400
2448
  };
2401
2449
 
2402
- Terminal.prototype.outputRecipe = function(formals, grammarInterval) {
2450
+ Terminal.prototype.outputRecipe = function (formals, grammarInterval) {
2403
2451
  return ['terminal', getMetaInfo(this, grammarInterval), this.obj];
2404
2452
  };
2405
2453
 
2406
- Range.prototype.outputRecipe = function(formals, grammarInterval) {
2454
+ Range.prototype.outputRecipe = function (formals, grammarInterval) {
2407
2455
  return ['range', getMetaInfo(this, grammarInterval), this.from, this.to];
2408
2456
  };
2409
2457
 
2410
- Param.prototype.outputRecipe = function(formals, grammarInterval) {
2458
+ Param.prototype.outputRecipe = function (formals, grammarInterval) {
2411
2459
  return ['param', getMetaInfo(this, grammarInterval), this.index];
2412
2460
  };
2413
2461
 
2414
- Alt.prototype.outputRecipe = function(formals, grammarInterval) {
2462
+ Alt.prototype.outputRecipe = function (formals, grammarInterval) {
2415
2463
  return ['alt', getMetaInfo(this, grammarInterval)].concat(
2416
- this.terms.map(term => term.outputRecipe(formals, grammarInterval)),
2464
+ this.terms.map(term => term.outputRecipe(formals, grammarInterval))
2417
2465
  );
2418
2466
  };
2419
2467
 
2420
- Extend.prototype.outputRecipe = function(formals, grammarInterval) {
2468
+ Extend.prototype.outputRecipe = function (formals, grammarInterval) {
2421
2469
  const extension = this.terms[0]; // [extension, original]
2422
2470
  return extension.outputRecipe(formals, grammarInterval);
2423
2471
  };
2424
2472
 
2425
- Splice.prototype.outputRecipe = function(formals, grammarInterval) {
2473
+ Splice.prototype.outputRecipe = function (formals, grammarInterval) {
2426
2474
  const beforeTerms = this.terms.slice(0, this.expansionPos);
2427
2475
  const afterTerms = this.terms.slice(this.expansionPos + 1);
2428
2476
  return [
@@ -2433,9 +2481,9 @@ Splice.prototype.outputRecipe = function(formals, grammarInterval) {
2433
2481
  ];
2434
2482
  };
2435
2483
 
2436
- Seq.prototype.outputRecipe = function(formals, grammarInterval) {
2484
+ Seq.prototype.outputRecipe = function (formals, grammarInterval) {
2437
2485
  return ['seq', getMetaInfo(this, grammarInterval)].concat(
2438
- this.factors.map(factor => factor.outputRecipe(formals, grammarInterval)),
2486
+ this.factors.map(factor => factor.outputRecipe(formals, grammarInterval))
2439
2487
  );
2440
2488
  };
2441
2489
 
@@ -2445,7 +2493,7 @@ Star.prototype.outputRecipe =
2445
2493
  Not.prototype.outputRecipe =
2446
2494
  Lookahead.prototype.outputRecipe =
2447
2495
  Lex.prototype.outputRecipe =
2448
- function(formals, grammarInterval) {
2496
+ function (formals, grammarInterval) {
2449
2497
  return [
2450
2498
  this.constructor.name.toLowerCase(),
2451
2499
  getMetaInfo(this, grammarInterval),
@@ -2453,7 +2501,7 @@ Star.prototype.outputRecipe =
2453
2501
  ];
2454
2502
  };
2455
2503
 
2456
- Apply.prototype.outputRecipe = function(formals, grammarInterval) {
2504
+ Apply.prototype.outputRecipe = function (formals, grammarInterval) {
2457
2505
  return [
2458
2506
  'app',
2459
2507
  getMetaInfo(this, grammarInterval),
@@ -2462,8 +2510,8 @@ Apply.prototype.outputRecipe = function(formals, grammarInterval) {
2462
2510
  ];
2463
2511
  };
2464
2512
 
2465
- UnicodeChar.prototype.outputRecipe = function(formals, grammarInterval) {
2466
- return ['unicodeChar', getMetaInfo(this, grammarInterval), this.category];
2513
+ UnicodeChar.prototype.outputRecipe = function (formals, grammarInterval) {
2514
+ return ['unicodeChar', getMetaInfo(this, grammarInterval), this.categoryOrProp];
2467
2515
  };
2468
2516
 
2469
2517
  // --------------------------------------------------------------------
@@ -2483,18 +2531,18 @@ any.introduceParams =
2483
2531
  Range.prototype.introduceParams =
2484
2532
  Param.prototype.introduceParams =
2485
2533
  UnicodeChar.prototype.introduceParams =
2486
- function(formals) {
2534
+ function (formals) {
2487
2535
  return this;
2488
2536
  };
2489
2537
 
2490
- Alt.prototype.introduceParams = function(formals) {
2538
+ Alt.prototype.introduceParams = function (formals) {
2491
2539
  this.terms.forEach((term, idx, terms) => {
2492
2540
  terms[idx] = term.introduceParams(formals);
2493
2541
  });
2494
2542
  return this;
2495
2543
  };
2496
2544
 
2497
- Seq.prototype.introduceParams = function(formals) {
2545
+ Seq.prototype.introduceParams = function (formals) {
2498
2546
  this.factors.forEach((factor, idx, factors) => {
2499
2547
  factors[idx] = factor.introduceParams(formals);
2500
2548
  });
@@ -2505,12 +2553,12 @@ Iter.prototype.introduceParams =
2505
2553
  Not.prototype.introduceParams =
2506
2554
  Lookahead.prototype.introduceParams =
2507
2555
  Lex.prototype.introduceParams =
2508
- function(formals) {
2556
+ function (formals) {
2509
2557
  this.expr = this.expr.introduceParams(formals);
2510
2558
  return this;
2511
2559
  };
2512
2560
 
2513
- Apply.prototype.introduceParams = function(formals) {
2561
+ Apply.prototype.introduceParams = function (formals) {
2514
2562
  const index = formals.indexOf(this.ruleName);
2515
2563
  if (index >= 0) {
2516
2564
  if (this.args.length > 0) {
@@ -2531,7 +2579,7 @@ Apply.prototype.introduceParams = function(formals) {
2531
2579
  // --------------------------------------------------------------------
2532
2580
 
2533
2581
  // Returns `true` if this parsing expression may accept without consuming any input.
2534
- PExpr.prototype.isNullable = function(grammar) {
2582
+ PExpr.prototype.isNullable = function (grammar) {
2535
2583
  return this._isNullable(grammar, Object.create(null));
2536
2584
  };
2537
2585
 
@@ -2542,15 +2590,15 @@ any._isNullable =
2542
2590
  Param.prototype._isNullable =
2543
2591
  Plus.prototype._isNullable =
2544
2592
  UnicodeChar.prototype._isNullable =
2545
- function(grammar, memo) {
2593
+ function (grammar, memo) {
2546
2594
  return false;
2547
2595
  };
2548
2596
 
2549
- end._isNullable = function(grammar, memo) {
2597
+ end._isNullable = function (grammar, memo) {
2550
2598
  return true;
2551
2599
  };
2552
2600
 
2553
- Terminal.prototype._isNullable = function(grammar, memo) {
2601
+ Terminal.prototype._isNullable = function (grammar, memo) {
2554
2602
  if (typeof this.obj === 'string') {
2555
2603
  // This is an over-simplification: it's only correct if the input is a string. If it's an array
2556
2604
  // or an object, then the empty string parsing expression is not nullable.
@@ -2560,11 +2608,11 @@ Terminal.prototype._isNullable = function(grammar, memo) {
2560
2608
  }
2561
2609
  };
2562
2610
 
2563
- Alt.prototype._isNullable = function(grammar, memo) {
2611
+ Alt.prototype._isNullable = function (grammar, memo) {
2564
2612
  return this.terms.length === 0 || this.terms.some(term => term._isNullable(grammar, memo));
2565
2613
  };
2566
2614
 
2567
- Seq.prototype._isNullable = function(grammar, memo) {
2615
+ Seq.prototype._isNullable = function (grammar, memo) {
2568
2616
  return this.factors.every(factor => factor._isNullable(grammar, memo));
2569
2617
  };
2570
2618
 
@@ -2572,15 +2620,15 @@ Star.prototype._isNullable =
2572
2620
  Opt.prototype._isNullable =
2573
2621
  Not.prototype._isNullable =
2574
2622
  Lookahead.prototype._isNullable =
2575
- function(grammar, memo) {
2623
+ function (grammar, memo) {
2576
2624
  return true;
2577
2625
  };
2578
2626
 
2579
- Lex.prototype._isNullable = function(grammar, memo) {
2627
+ Lex.prototype._isNullable = function (grammar, memo) {
2580
2628
  return this.expr._isNullable(grammar, memo);
2581
2629
  };
2582
2630
 
2583
- Apply.prototype._isNullable = function(grammar, memo) {
2631
+ Apply.prototype._isNullable = function (grammar, memo) {
2584
2632
  const key = this.toMemoKey();
2585
2633
  if (!Object.prototype.hasOwnProperty.call(memo, key)) {
2586
2634
  const {body} = grammar.rules[this.ruleName];
@@ -2609,19 +2657,19 @@ any.substituteParams =
2609
2657
  Terminal.prototype.substituteParams =
2610
2658
  Range.prototype.substituteParams =
2611
2659
  UnicodeChar.prototype.substituteParams =
2612
- function(actuals) {
2660
+ function (actuals) {
2613
2661
  return this;
2614
2662
  };
2615
2663
 
2616
- Param.prototype.substituteParams = function(actuals) {
2664
+ Param.prototype.substituteParams = function (actuals) {
2617
2665
  return checkNotNull(actuals[this.index]);
2618
2666
  };
2619
2667
 
2620
- Alt.prototype.substituteParams = function(actuals) {
2668
+ Alt.prototype.substituteParams = function (actuals) {
2621
2669
  return new Alt(this.terms.map(term => term.substituteParams(actuals)));
2622
2670
  };
2623
2671
 
2624
- Seq.prototype.substituteParams = function(actuals) {
2672
+ Seq.prototype.substituteParams = function (actuals) {
2625
2673
  return new Seq(this.factors.map(factor => factor.substituteParams(actuals)));
2626
2674
  };
2627
2675
 
@@ -2629,11 +2677,11 @@ Iter.prototype.substituteParams =
2629
2677
  Not.prototype.substituteParams =
2630
2678
  Lookahead.prototype.substituteParams =
2631
2679
  Lex.prototype.substituteParams =
2632
- function(actuals) {
2680
+ function (actuals) {
2633
2681
  return new this.constructor(this.expr.substituteParams(actuals));
2634
2682
  };
2635
2683
 
2636
- Apply.prototype.substituteParams = function(actuals) {
2684
+ Apply.prototype.substituteParams = function (actuals) {
2637
2685
  if (this.args.length === 0) {
2638
2686
  // Avoid making a copy of this application, as an optimization
2639
2687
  return this;
@@ -2707,15 +2755,15 @@ function resolveDuplicatedNames(argumentNameList) {
2707
2755
  // function(firstArgIndex, noDupCheck) { ... }
2708
2756
  PExpr.prototype.toArgumentNameList = abstract('toArgumentNameList');
2709
2757
 
2710
- any.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2758
+ any.toArgumentNameList = function (firstArgIndex, noDupCheck) {
2711
2759
  return ['any'];
2712
2760
  };
2713
2761
 
2714
- end.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2762
+ end.toArgumentNameList = function (firstArgIndex, noDupCheck) {
2715
2763
  return ['end'];
2716
2764
  };
2717
2765
 
2718
- Terminal.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2766
+ Terminal.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
2719
2767
  if (typeof this.obj === 'string' && /^[_a-zA-Z0-9]+$/.test(this.obj)) {
2720
2768
  // If this terminal is a valid suffix for a JS identifier, just prepend it with '_'
2721
2769
  return ['_' + this.obj];
@@ -2725,7 +2773,7 @@ Terminal.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2725
2773
  }
2726
2774
  };
2727
2775
 
2728
- Range.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2776
+ Range.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
2729
2777
  let argName = this.from + '_to_' + this.to;
2730
2778
  // If the `argName` is not valid then try to prepend a `_`.
2731
2779
  if (!isRestrictedJSIdentifier(argName)) {
@@ -2738,11 +2786,11 @@ Range.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2738
2786
  return [argName];
2739
2787
  };
2740
2788
 
2741
- Alt.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2789
+ Alt.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
2742
2790
  // `termArgNameLists` is an array of arrays where each row is the
2743
2791
  // argument name list that corresponds to a term in this alternation.
2744
2792
  const termArgNameLists = this.terms.map(term =>
2745
- term.toArgumentNameList(firstArgIndex, true),
2793
+ term.toArgumentNameList(firstArgIndex, true)
2746
2794
  );
2747
2795
 
2748
2796
  const argumentNameList = [];
@@ -2762,7 +2810,7 @@ Alt.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2762
2810
  return argumentNameList;
2763
2811
  };
2764
2812
 
2765
- Seq.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2813
+ Seq.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
2766
2814
  // Generate the argument name list, without worrying about duplicates.
2767
2815
  let argumentNameList = [];
2768
2816
  this.factors.forEach(factor => {
@@ -2778,44 +2826,44 @@ Seq.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2778
2826
  return argumentNameList;
2779
2827
  };
2780
2828
 
2781
- Iter.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2829
+ Iter.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
2782
2830
  const argumentNameList = this.expr
2783
- .toArgumentNameList(firstArgIndex, noDupCheck)
2784
- .map(exprArgumentString =>
2785
- exprArgumentString[exprArgumentString.length - 1] === 's' ?
2786
- exprArgumentString + 'es' :
2787
- exprArgumentString + 's',
2788
- );
2831
+ .toArgumentNameList(firstArgIndex, noDupCheck)
2832
+ .map(exprArgumentString =>
2833
+ exprArgumentString[exprArgumentString.length - 1] === 's'
2834
+ ? exprArgumentString + 'es'
2835
+ : exprArgumentString + 's'
2836
+ );
2789
2837
  if (!noDupCheck) {
2790
2838
  resolveDuplicatedNames(argumentNameList);
2791
2839
  }
2792
2840
  return argumentNameList;
2793
2841
  };
2794
2842
 
2795
- Opt.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2843
+ Opt.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
2796
2844
  return this.expr.toArgumentNameList(firstArgIndex, noDupCheck).map(argName => {
2797
2845
  return 'opt' + argName[0].toUpperCase() + argName.slice(1);
2798
2846
  });
2799
2847
  };
2800
2848
 
2801
- Not.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2849
+ Not.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
2802
2850
  return [];
2803
2851
  };
2804
2852
 
2805
2853
  Lookahead.prototype.toArgumentNameList = Lex.prototype.toArgumentNameList =
2806
- function(firstArgIndex, noDupCheck) {
2854
+ function (firstArgIndex, noDupCheck) {
2807
2855
  return this.expr.toArgumentNameList(firstArgIndex, noDupCheck);
2808
2856
  };
2809
2857
 
2810
- Apply.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2858
+ Apply.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
2811
2859
  return [this.ruleName];
2812
2860
  };
2813
2861
 
2814
- UnicodeChar.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2862
+ UnicodeChar.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
2815
2863
  return ['$' + firstArgIndex];
2816
2864
  };
2817
2865
 
2818
- Param.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2866
+ Param.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
2819
2867
  return ['param' + this.index];
2820
2868
  };
2821
2869
 
@@ -2828,7 +2876,7 @@ Param.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
2828
2876
  // Returns a string representing the PExpr, for use as a UI label, etc.
2829
2877
  PExpr.prototype.toDisplayString = abstract('toDisplayString');
2830
2878
 
2831
- Alt.prototype.toDisplayString = Seq.prototype.toDisplayString = function() {
2879
+ Alt.prototype.toDisplayString = Seq.prototype.toDisplayString = function () {
2832
2880
  if (this.source) {
2833
2881
  return this.source.trimmed().contents;
2834
2882
  }
@@ -2844,11 +2892,11 @@ any.toDisplayString =
2844
2892
  Terminal.prototype.toDisplayString =
2845
2893
  Range.prototype.toDisplayString =
2846
2894
  Param.prototype.toDisplayString =
2847
- function() {
2895
+ function () {
2848
2896
  return this.toString();
2849
2897
  };
2850
2898
 
2851
- Apply.prototype.toDisplayString = function() {
2899
+ Apply.prototype.toDisplayString = function () {
2852
2900
  if (this.args.length > 0) {
2853
2901
  const ps = this.args.map(arg => arg.toDisplayString());
2854
2902
  return this.ruleName + '<' + ps.join(',') + '>';
@@ -2857,8 +2905,8 @@ Apply.prototype.toDisplayString = function() {
2857
2905
  }
2858
2906
  };
2859
2907
 
2860
- UnicodeChar.prototype.toDisplayString = function() {
2861
- return 'Unicode [' + this.category + '] character';
2908
+ UnicodeChar.prototype.toDisplayString = function () {
2909
+ return 'Unicode [' + this.categoryOrProp + '] character';
2862
2910
  };
2863
2911
 
2864
2912
  // --------------------------------------------------------------------
@@ -2961,34 +3009,34 @@ class Failure {
2961
3009
 
2962
3010
  PExpr.prototype.toFailure = abstract('toFailure');
2963
3011
 
2964
- any.toFailure = function(grammar) {
3012
+ any.toFailure = function (grammar) {
2965
3013
  return new Failure(this, 'any object', 'description');
2966
3014
  };
2967
3015
 
2968
- end.toFailure = function(grammar) {
3016
+ end.toFailure = function (grammar) {
2969
3017
  return new Failure(this, 'end of input', 'description');
2970
3018
  };
2971
3019
 
2972
- Terminal.prototype.toFailure = function(grammar) {
3020
+ Terminal.prototype.toFailure = function (grammar) {
2973
3021
  return new Failure(this, this.obj, 'string');
2974
3022
  };
2975
3023
 
2976
- Range.prototype.toFailure = function(grammar) {
3024
+ Range.prototype.toFailure = function (grammar) {
2977
3025
  // TODO: come up with something better
2978
3026
  return new Failure(this, JSON.stringify(this.from) + '..' + JSON.stringify(this.to), 'code');
2979
3027
  };
2980
3028
 
2981
- Not.prototype.toFailure = function(grammar) {
3029
+ Not.prototype.toFailure = function (grammar) {
2982
3030
  const description =
2983
3031
  this.expr === any ? 'nothing' : 'not ' + this.expr.toFailure(grammar);
2984
3032
  return new Failure(this, description, 'description');
2985
3033
  };
2986
3034
 
2987
- Lookahead.prototype.toFailure = function(grammar) {
3035
+ Lookahead.prototype.toFailure = function (grammar) {
2988
3036
  return this.expr.toFailure(grammar);
2989
3037
  };
2990
3038
 
2991
- Apply.prototype.toFailure = function(grammar) {
3039
+ Apply.prototype.toFailure = function (grammar) {
2992
3040
  let {description} = grammar.rules[this.ruleName];
2993
3041
  if (!description) {
2994
3042
  const article = /^[aeiouAEIOU]/.test(this.ruleName) ? 'an' : 'a';
@@ -2997,23 +3045,23 @@ Apply.prototype.toFailure = function(grammar) {
2997
3045
  return new Failure(this, description, 'description');
2998
3046
  };
2999
3047
 
3000
- UnicodeChar.prototype.toFailure = function(grammar) {
3001
- return new Failure(this, 'a Unicode [' + this.category + '] character', 'description');
3048
+ UnicodeChar.prototype.toFailure = function (grammar) {
3049
+ return new Failure(this, 'a Unicode [' + this.categoryOrProp + '] character', 'description');
3002
3050
  };
3003
3051
 
3004
- Alt.prototype.toFailure = function(grammar) {
3052
+ Alt.prototype.toFailure = function (grammar) {
3005
3053
  const fs = this.terms.map(t => t.toFailure(grammar));
3006
3054
  const description = '(' + fs.join(' or ') + ')';
3007
3055
  return new Failure(this, description, 'description');
3008
3056
  };
3009
3057
 
3010
- Seq.prototype.toFailure = function(grammar) {
3058
+ Seq.prototype.toFailure = function (grammar) {
3011
3059
  const fs = this.factors.map(f => f.toFailure(grammar));
3012
3060
  const description = '(' + fs.join(' ') + ')';
3013
3061
  return new Failure(this, description, 'description');
3014
3062
  };
3015
3063
 
3016
- Iter.prototype.toFailure = function(grammar) {
3064
+ Iter.prototype.toFailure = function (grammar) {
3017
3065
  const description = '(' + this.expr.toFailure(grammar) + this.operator + ')';
3018
3066
  return new Failure(this, description, 'description');
3019
3067
  };
@@ -3031,55 +3079,55 @@ Iter.prototype.toFailure = function(grammar) {
3031
3079
  */
3032
3080
  PExpr.prototype.toString = abstract('toString');
3033
3081
 
3034
- any.toString = function() {
3082
+ any.toString = function () {
3035
3083
  return 'any';
3036
3084
  };
3037
3085
 
3038
- end.toString = function() {
3086
+ end.toString = function () {
3039
3087
  return 'end';
3040
3088
  };
3041
3089
 
3042
- Terminal.prototype.toString = function() {
3090
+ Terminal.prototype.toString = function () {
3043
3091
  return JSON.stringify(this.obj);
3044
3092
  };
3045
3093
 
3046
- Range.prototype.toString = function() {
3094
+ Range.prototype.toString = function () {
3047
3095
  return JSON.stringify(this.from) + '..' + JSON.stringify(this.to);
3048
3096
  };
3049
3097
 
3050
- Param.prototype.toString = function() {
3098
+ Param.prototype.toString = function () {
3051
3099
  return '$' + this.index;
3052
3100
  };
3053
3101
 
3054
- Lex.prototype.toString = function() {
3102
+ Lex.prototype.toString = function () {
3055
3103
  return '#(' + this.expr.toString() + ')';
3056
3104
  };
3057
3105
 
3058
- Alt.prototype.toString = function() {
3059
- return this.terms.length === 1 ?
3060
- this.terms[0].toString() :
3061
- '(' + this.terms.map(term => term.toString()).join(' | ') + ')';
3106
+ Alt.prototype.toString = function () {
3107
+ return this.terms.length === 1
3108
+ ? this.terms[0].toString()
3109
+ : '(' + this.terms.map(term => term.toString()).join(' | ') + ')';
3062
3110
  };
3063
3111
 
3064
- Seq.prototype.toString = function() {
3065
- return this.factors.length === 1 ?
3066
- this.factors[0].toString() :
3067
- '(' + this.factors.map(factor => factor.toString()).join(' ') + ')';
3112
+ Seq.prototype.toString = function () {
3113
+ return this.factors.length === 1
3114
+ ? this.factors[0].toString()
3115
+ : '(' + this.factors.map(factor => factor.toString()).join(' ') + ')';
3068
3116
  };
3069
3117
 
3070
- Iter.prototype.toString = function() {
3118
+ Iter.prototype.toString = function () {
3071
3119
  return this.expr + this.operator;
3072
3120
  };
3073
3121
 
3074
- Not.prototype.toString = function() {
3122
+ Not.prototype.toString = function () {
3075
3123
  return '~' + this.expr;
3076
3124
  };
3077
3125
 
3078
- Lookahead.prototype.toString = function() {
3126
+ Lookahead.prototype.toString = function () {
3079
3127
  return '&' + this.expr;
3080
3128
  };
3081
3129
 
3082
- Apply.prototype.toString = function() {
3130
+ Apply.prototype.toString = function () {
3083
3131
  if (this.args.length > 0) {
3084
3132
  const ps = this.args.map(arg => arg.toString());
3085
3133
  return this.ruleName + '<' + ps.join(',') + '>';
@@ -3088,8 +3136,8 @@ Apply.prototype.toString = function() {
3088
3136
  }
3089
3137
  };
3090
3138
 
3091
- UnicodeChar.prototype.toString = function() {
3092
- return '\\p{' + this.category + '}';
3139
+ UnicodeChar.prototype.toString = function () {
3140
+ return '\\p{' + this.categoryOrProp + '}';
3093
3141
  };
3094
3142
 
3095
3143
  class CaseInsensitiveTerminal extends PExpr {
@@ -3137,9 +3185,9 @@ class CaseInsensitiveTerminal extends PExpr {
3137
3185
 
3138
3186
  toFailure(grammar) {
3139
3187
  return new Failure(
3140
- this,
3141
- this.obj.toFailure(grammar) + ' (case-insensitive)',
3142
- 'description',
3188
+ this,
3189
+ this.obj.toFailure(grammar) + ' (case-insensitive)',
3190
+ 'description'
3143
3191
  );
3144
3192
  }
3145
3193
 
@@ -3235,8 +3283,8 @@ class MatchState {
3235
3283
  posInfo.exit();
3236
3284
 
3237
3285
  this.rightmostFailurePosition = Math.max(
3238
- this.rightmostFailurePosition,
3239
- this._rightmostFailurePositionStack.pop(),
3286
+ this.rightmostFailurePosition,
3287
+ this._rightmostFailurePositionStack.pop()
3240
3288
  );
3241
3289
 
3242
3290
  if (optNode) {
@@ -3372,9 +3420,9 @@ class MatchState {
3372
3420
  }
3373
3421
 
3374
3422
  _getRightmostFailureOffset() {
3375
- return this.rightmostFailurePosition >= 0 ?
3376
- this.posToOffset(this.rightmostFailurePosition) :
3377
- -1;
3423
+ return this.rightmostFailurePosition >= 0
3424
+ ? this.posToOffset(this.rightmostFailurePosition)
3425
+ : -1;
3378
3426
  }
3379
3427
 
3380
3428
  // Returns the memoized trace entry for `expr` at `pos`, if one exists, `null` otherwise.
@@ -3431,8 +3479,8 @@ class MatchState {
3431
3479
  const memoRecRightmostFailurePosition =
3432
3480
  this.inputStream.pos + memoRec.rightmostFailureOffset;
3433
3481
  this.rightmostFailurePosition = Math.max(
3434
- this.rightmostFailurePosition,
3435
- memoRecRightmostFailurePosition,
3482
+ this.rightmostFailurePosition,
3483
+ memoRecRightmostFailurePosition
3436
3484
  );
3437
3485
  if (
3438
3486
  this.recordedFailures &&
@@ -3443,8 +3491,8 @@ class MatchState {
3443
3491
  }
3444
3492
 
3445
3493
  this.inputStream.examinedLength = Math.max(
3446
- this.inputStream.examinedLength,
3447
- memoRec.examinedLength + origPos,
3494
+ this.inputStream.examinedLength,
3495
+ memoRec.examinedLength + origPos
3448
3496
  );
3449
3497
 
3450
3498
  if (memoRec.value) {
@@ -3522,7 +3570,7 @@ class MatchState {
3522
3570
  let rightmostFailures;
3523
3571
  if (this.recordedFailures) {
3524
3572
  rightmostFailures = Object.keys(this.recordedFailures).map(
3525
- key => this.recordedFailures[key],
3573
+ key => this.recordedFailures[key]
3526
3574
  );
3527
3575
  }
3528
3576
  const cst = this._bindings[0];
@@ -3530,13 +3578,13 @@ class MatchState {
3530
3578
  cst.grammar = this.grammar;
3531
3579
  }
3532
3580
  return new MatchResult(
3533
- this.matcher,
3534
- this.input,
3535
- this.startExpr,
3536
- cst,
3537
- this._bindingOffsets[0],
3538
- this.rightmostFailurePosition,
3539
- rightmostFailures,
3581
+ this.matcher,
3582
+ this.input,
3583
+ this.startExpr,
3584
+ cst,
3585
+ this._bindingOffsets[0],
3586
+ this.rightmostFailurePosition,
3587
+ rightmostFailures
3540
3588
  );
3541
3589
  }
3542
3590
 
@@ -3849,11 +3897,11 @@ class Semantics {
3849
3897
  if (superSemantics) {
3850
3898
  if (!(grammar.equals(this.super.grammar) || grammar._inheritsFrom(this.super.grammar))) {
3851
3899
  throw new Error(
3852
- "Cannot extend a semantics for grammar '" +
3900
+ "Cannot extend a semantics for grammar '" +
3853
3901
  this.super.grammar.name +
3854
3902
  "' for use with grammar '" +
3855
3903
  grammar.name +
3856
- "' (not a sub-grammar)",
3904
+ "' (not a sub-grammar)"
3857
3905
  );
3858
3906
  }
3859
3907
  this.operations = Object.create(this.super.operations);
@@ -3862,7 +3910,7 @@ class Semantics {
3862
3910
 
3863
3911
  // Assign unique symbols for each of the attributes inherited from the super-semantics so that
3864
3912
  // they are memoized independently.
3865
- // eslint-disable-next-line guard-for-in
3913
+
3866
3914
  for (const attributeName in this.attributes) {
3867
3915
  Object.defineProperty(this.attributeKeys, attributeName, {
3868
3916
  value: uniqueId(attributeName),
@@ -3891,11 +3939,11 @@ class Semantics {
3891
3939
  // Throws an exception if one or more of them doesn't.
3892
3940
  checkActionDicts() {
3893
3941
  let name;
3894
- // eslint-disable-next-line guard-for-in
3942
+
3895
3943
  for (name in this.operations) {
3896
3944
  this.operations[name].checkActionDict(this.grammar);
3897
3945
  }
3898
- // eslint-disable-next-line guard-for-in
3946
+
3899
3947
  for (name in this.attributes) {
3900
3948
  this.attributes[name].checkActionDict(this.grammar);
3901
3949
  }
@@ -3995,9 +4043,9 @@ class Semantics {
3995
4043
  });
3996
4044
 
3997
4045
  const entry =
3998
- type === 'operation' ?
3999
- new Operation(name, formals, realActionDict, builtInDefault) :
4000
- new Attribute(name, realActionDict, builtInDefault);
4046
+ type === 'operation'
4047
+ ? new Operation(name, formals, realActionDict, builtInDefault)
4048
+ : new Attribute(name, realActionDict, builtInDefault);
4001
4049
 
4002
4050
  // The following check is not strictly necessary (it will happen later anyway) but it's better
4003
4051
  // to catch errors early.
@@ -4013,7 +4061,7 @@ class Semantics {
4013
4061
  // Check that the caller passed the correct number of arguments.
4014
4062
  if (arguments.length !== thisThing.formals.length) {
4015
4063
  throw new Error(
4016
- 'Invalid number of arguments passed to ' +
4064
+ 'Invalid number of arguments passed to ' +
4017
4065
  name +
4018
4066
  ' ' +
4019
4067
  type +
@@ -4021,7 +4069,7 @@ class Semantics {
4021
4069
  thisThing.formals.length +
4022
4070
  ', got ' +
4023
4071
  arguments.length +
4024
- ')',
4072
+ ')'
4025
4073
  );
4026
4074
  }
4027
4075
 
@@ -4042,7 +4090,7 @@ class Semantics {
4042
4090
 
4043
4091
  if (type === 'operation') {
4044
4092
  this.Wrapper.prototype[name] = doIt;
4045
- this.Wrapper.prototype[name].toString = function() {
4093
+ this.Wrapper.prototype[name].toString = function () {
4046
4094
  return '[' + name + ' operation]';
4047
4095
  };
4048
4096
  } else {
@@ -4064,13 +4112,13 @@ class Semantics {
4064
4112
 
4065
4113
  if (!(this.super && name in this.super[typePlural])) {
4066
4114
  throw new Error(
4067
- 'Cannot extend ' +
4115
+ 'Cannot extend ' +
4068
4116
  type +
4069
4117
  " '" +
4070
4118
  name +
4071
4119
  "': did not inherit an " +
4072
4120
  type +
4073
- ' with that name',
4121
+ ' with that name'
4074
4122
  );
4075
4123
  }
4076
4124
  if (hasOwnProperty(this[typePlural], name)) {
@@ -4087,9 +4135,9 @@ class Semantics {
4087
4135
  });
4088
4136
 
4089
4137
  this[typePlural][name] =
4090
- type === 'operation' ?
4091
- new Operation(name, inheritedFormals, newActionDict) :
4092
- new Attribute(name, newActionDict);
4138
+ type === 'operation'
4139
+ ? new Operation(name, inheritedFormals, newActionDict)
4140
+ : new Attribute(name, newActionDict);
4093
4141
 
4094
4142
  // The following check is not strictly necessary (it will happen later anyway) but it's better
4095
4143
  // to catch errors early.
@@ -4102,12 +4150,12 @@ class Semantics {
4102
4150
  }
4103
4151
  if (name in this.operations) {
4104
4152
  throw new Error(
4105
- 'Cannot add ' + type + " '" + name + "': an operation with that name already exists",
4153
+ 'Cannot add ' + type + " '" + name + "': an operation with that name already exists"
4106
4154
  );
4107
4155
  }
4108
4156
  if (name in this.attributes) {
4109
4157
  throw new Error(
4110
- 'Cannot add ' + type + " '" + name + "': an attribute with that name already exists",
4158
+ 'Cannot add ' + type + " '" + name + "': an attribute with that name already exists"
4111
4159
  );
4112
4160
  }
4113
4161
  }
@@ -4133,8 +4181,8 @@ function parseSignature(signature, type) {
4133
4181
  }
4134
4182
 
4135
4183
  const r = Semantics.prototypeGrammar.match(
4136
- signature,
4137
- type === 'operation' ? 'OperationSignature' : 'AttributeSignature',
4184
+ signature,
4185
+ type === 'operation' ? 'OperationSignature' : 'AttributeSignature'
4138
4186
  );
4139
4187
  if (r.failed()) {
4140
4188
  throw new Error(r.message);
@@ -4144,7 +4192,7 @@ function parseSignature(signature, type) {
4144
4192
  }
4145
4193
 
4146
4194
  function newDefaultAction(type, name, doIt) {
4147
- return function(...children) {
4195
+ return function (...children) {
4148
4196
  const thisThing = this._semantics.operations[name] || this._semantics.attributes[name];
4149
4197
  const args = thisThing.formals.map(formal => this.args[formal]);
4150
4198
 
@@ -4168,12 +4216,12 @@ function newDefaultAction(type, name, doIt) {
4168
4216
  // Semantics instance. When that function is invoked with a CST node as an argument, it returns
4169
4217
  // a wrapper for that node which gives access to the operations and attributes provided by this
4170
4218
  // semantics.
4171
- Semantics.createSemantics = function(grammar, optSuperSemantics) {
4219
+ Semantics.createSemantics = function (grammar, optSuperSemantics) {
4172
4220
  const s = new Semantics(
4173
- grammar,
4174
- optSuperSemantics !== undefined ?
4175
- optSuperSemantics :
4176
- Semantics.BuiltInSemantics._getSemantics(),
4221
+ grammar,
4222
+ optSuperSemantics !== undefined
4223
+ ? optSuperSemantics
4224
+ : Semantics.BuiltInSemantics._getSemantics()
4177
4225
  );
4178
4226
 
4179
4227
  // To enable clients to invoke a semantics like a function, return a function that acts as a proxy
@@ -4181,8 +4229,8 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
4181
4229
  const proxy = function ASemantics(matchResult) {
4182
4230
  if (!(matchResult instanceof MatchResult)) {
4183
4231
  throw new TypeError(
4184
- 'Semantics expected a MatchResult, but got ' +
4185
- unexpectedObjToString(matchResult),
4232
+ 'Semantics expected a MatchResult, but got ' +
4233
+ unexpectedObjToString(matchResult)
4186
4234
  );
4187
4235
  }
4188
4236
  if (matchResult.failed()) {
@@ -4192,11 +4240,11 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
4192
4240
  const cst = matchResult._cst;
4193
4241
  if (cst.grammar !== grammar) {
4194
4242
  throw new Error(
4195
- "Cannot use a MatchResult from grammar '" +
4243
+ "Cannot use a MatchResult from grammar '" +
4196
4244
  cst.grammar.name +
4197
4245
  "' with a semantics for '" +
4198
4246
  grammar.name +
4199
- "'",
4247
+ "'"
4200
4248
  );
4201
4249
  }
4202
4250
  const inputStream = new InputStream(matchResult.input);
@@ -4204,38 +4252,38 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
4204
4252
  };
4205
4253
 
4206
4254
  // Forward public methods from the proxy to the semantics instance.
4207
- proxy.addOperation = function(signature, actionDict) {
4255
+ proxy.addOperation = function (signature, actionDict) {
4208
4256
  s.addOperationOrAttribute('operation', signature, actionDict);
4209
4257
  return proxy;
4210
4258
  };
4211
- proxy.extendOperation = function(name, actionDict) {
4259
+ proxy.extendOperation = function (name, actionDict) {
4212
4260
  s.extendOperationOrAttribute('operation', name, actionDict);
4213
4261
  return proxy;
4214
4262
  };
4215
- proxy.addAttribute = function(name, actionDict) {
4263
+ proxy.addAttribute = function (name, actionDict) {
4216
4264
  s.addOperationOrAttribute('attribute', name, actionDict);
4217
4265
  return proxy;
4218
4266
  };
4219
- proxy.extendAttribute = function(name, actionDict) {
4267
+ proxy.extendAttribute = function (name, actionDict) {
4220
4268
  s.extendOperationOrAttribute('attribute', name, actionDict);
4221
4269
  return proxy;
4222
4270
  };
4223
- proxy._getActionDict = function(operationOrAttributeName) {
4271
+ proxy._getActionDict = function (operationOrAttributeName) {
4224
4272
  const action =
4225
4273
  s.operations[operationOrAttributeName] || s.attributes[operationOrAttributeName];
4226
4274
  if (!action) {
4227
4275
  throw new Error(
4228
- '"' +
4276
+ '"' +
4229
4277
  operationOrAttributeName +
4230
4278
  '" is not a valid operation or attribute ' +
4231
4279
  'name in this semantics for "' +
4232
4280
  grammar.name +
4233
- '"',
4281
+ '"'
4234
4282
  );
4235
4283
  }
4236
4284
  return action.actionDict;
4237
4285
  };
4238
- proxy._remove = function(operationOrAttributeName) {
4286
+ proxy._remove = function (operationOrAttributeName) {
4239
4287
  let semantic;
4240
4288
  if (operationOrAttributeName in s.operations) {
4241
4289
  semantic = s.operations[operationOrAttributeName];
@@ -4247,16 +4295,16 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
4247
4295
  delete s.Wrapper.prototype[operationOrAttributeName];
4248
4296
  return semantic;
4249
4297
  };
4250
- proxy.getOperationNames = function() {
4298
+ proxy.getOperationNames = function () {
4251
4299
  return Object.keys(s.operations);
4252
4300
  };
4253
- proxy.getAttributeNames = function() {
4301
+ proxy.getAttributeNames = function () {
4254
4302
  return Object.keys(s.attributes);
4255
4303
  };
4256
- proxy.getGrammar = function() {
4304
+ proxy.getGrammar = function () {
4257
4305
  return s.grammar;
4258
4306
  };
4259
- proxy.toRecipe = function(semanticsOnly) {
4307
+ proxy.toRecipe = function (semanticsOnly) {
4260
4308
  return s.toRecipe(semanticsOnly);
4261
4309
  };
4262
4310
 
@@ -4264,7 +4312,7 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
4264
4312
  proxy.toString = s.toString.bind(s);
4265
4313
 
4266
4314
  // Returns the semantics for the proxy.
4267
- proxy._getSemantics = function() {
4315
+ proxy._getSemantics = function () {
4268
4316
  return s;
4269
4317
  };
4270
4318
 
@@ -4356,8 +4404,8 @@ const SPECIAL_ACTION_NAMES = ['_iter', '_terminal', '_nonterminal', '_default'];
4356
4404
 
4357
4405
  function getSortedRuleValues(grammar) {
4358
4406
  return Object.keys(grammar.rules)
4359
- .sort()
4360
- .map(name => grammar.rules[name]);
4407
+ .sort()
4408
+ .map(name => grammar.rules[name]);
4361
4409
  }
4362
4410
 
4363
4411
  // Until ES2019, JSON was not a valid subset of JavaScript because U+2028 (line separator)
@@ -4378,11 +4426,11 @@ class Grammar {
4378
4426
  if (optDefaultStartRule) {
4379
4427
  if (!(optDefaultStartRule in rules)) {
4380
4428
  throw new Error(
4381
- "Invalid start rule: '" +
4429
+ "Invalid start rule: '" +
4382
4430
  optDefaultStartRule +
4383
4431
  "' is not a rule in grammar '" +
4384
4432
  name +
4385
- "'",
4433
+ "'"
4386
4434
  );
4387
4435
  }
4388
4436
  this.defaultStartRule = optDefaultStartRule;
@@ -4453,7 +4501,6 @@ class Grammar {
4453
4501
  _checkTopDownActionDict(what, name, actionDict) {
4454
4502
  const problems = [];
4455
4503
 
4456
- // eslint-disable-next-line guard-for-in
4457
4504
  for (const k in actionDict) {
4458
4505
  const v = actionDict[k];
4459
4506
  const isSpecialAction = SPECIAL_ACTION_NAMES.includes(k);
@@ -4483,10 +4530,10 @@ class Grammar {
4483
4530
  if (problems.length > 0) {
4484
4531
  const prettyProblems = problems.map(problem => '- ' + problem);
4485
4532
  const error = new Error(
4486
- [
4487
- `Found errors in the action dictionary of the '${name}' ${what}:`,
4488
- ...prettyProblems,
4489
- ].join('\n'),
4533
+ [
4534
+ `Found errors in the action dictionary of the '${name}' ${what}:`,
4535
+ ...prettyProblems,
4536
+ ].join('\n')
4490
4537
  );
4491
4538
  error.problems = problems;
4492
4539
  throw error;
@@ -4499,9 +4546,9 @@ class Grammar {
4499
4546
  // All special actions have an expected arity of 0, though all but _terminal
4500
4547
  // are expected to use the rest parameter syntax (e.g. `_iter(...children)`).
4501
4548
  // This is considered to have arity 0, i.e. `((...args) => {}).length` is 0.
4502
- return SPECIAL_ACTION_NAMES.includes(actionName) ?
4503
- 0 :
4504
- this.rules[actionName].body.getArity();
4549
+ return SPECIAL_ACTION_NAMES.includes(actionName)
4550
+ ? 0
4551
+ : this.rules[actionName].body.getArity();
4505
4552
  }
4506
4553
 
4507
4554
  _inheritsFrom(grammar) {
@@ -4592,7 +4639,7 @@ class Grammar {
4592
4639
  sb.append('{');
4593
4640
 
4594
4641
  let first = true;
4595
- // eslint-disable-next-line guard-for-in
4642
+
4596
4643
  for (const ruleName in this.rules) {
4597
4644
  const {body} = this.rules[ruleName];
4598
4645
  if (first) {
@@ -4639,10 +4686,10 @@ class Grammar {
4639
4686
  if (formals.length !== app.args.length) {
4640
4687
  const {source} = this.rules[app.ruleName];
4641
4688
  throw wrongNumberOfParameters(
4642
- app.ruleName,
4643
- formals.length,
4644
- app.args.length,
4645
- source,
4689
+ app.ruleName,
4690
+ formals.length,
4691
+ app.args.length,
4692
+ source
4646
4693
  );
4647
4694
  }
4648
4695
  return app;
@@ -4661,63 +4708,63 @@ class Grammar {
4661
4708
  // `digit`, and is implicitly the super-grammar of any grammar whose super-grammar
4662
4709
  // isn't specified.
4663
4710
  Grammar.ProtoBuiltInRules = new Grammar(
4664
- 'ProtoBuiltInRules', // name
4665
- undefined, // supergrammar
4666
- {
4667
- any: {
4668
- body: any,
4669
- formals: [],
4670
- description: 'any character',
4671
- primitive: true,
4672
- },
4673
- end: {
4674
- body: end,
4675
- formals: [],
4676
- description: 'end of input',
4677
- primitive: true,
4678
- },
4679
-
4680
- caseInsensitive: {
4681
- body: new CaseInsensitiveTerminal(new Param(0)),
4682
- formals: ['str'],
4683
- primitive: true,
4684
- },
4685
- lower: {
4686
- body: new UnicodeChar('Ll'),
4687
- formals: [],
4688
- description: 'a lowercase letter',
4689
- primitive: true,
4690
- },
4691
- upper: {
4692
- body: new UnicodeChar('Lu'),
4693
- formals: [],
4694
- description: 'an uppercase letter',
4695
- primitive: true,
4696
- },
4697
- // Union of Lt (titlecase), Lm (modifier), and Lo (other), i.e. any letter not in Ll or Lu.
4698
- unicodeLtmo: {
4699
- body: new UnicodeChar('Ltmo'),
4700
- formals: [],
4701
- description: 'a Unicode character in Lt, Lm, or Lo',
4702
- primitive: true,
4703
- },
4704
-
4705
- // These rules are not truly primitive (they could be written in userland) but are defined
4706
- // here for bootstrapping purposes.
4707
- spaces: {
4708
- body: new Star(new Apply('space')),
4709
- formals: [],
4710
- },
4711
- space: {
4712
- body: new Range('\x00', ' '),
4713
- formals: [],
4714
- description: 'a space',
4715
- },
4711
+ 'ProtoBuiltInRules', // name
4712
+ undefined, // supergrammar
4713
+ {
4714
+ any: {
4715
+ body: any,
4716
+ formals: [],
4717
+ description: 'any character',
4718
+ primitive: true,
4716
4719
  },
4720
+ end: {
4721
+ body: end,
4722
+ formals: [],
4723
+ description: 'end of input',
4724
+ primitive: true,
4725
+ },
4726
+
4727
+ caseInsensitive: {
4728
+ body: new CaseInsensitiveTerminal(new Param(0)),
4729
+ formals: ['str'],
4730
+ primitive: true,
4731
+ },
4732
+ lower: {
4733
+ body: new UnicodeChar('Ll'),
4734
+ formals: [],
4735
+ description: 'a lowercase letter',
4736
+ primitive: true,
4737
+ },
4738
+ upper: {
4739
+ body: new UnicodeChar('Lu'),
4740
+ formals: [],
4741
+ description: 'an uppercase letter',
4742
+ primitive: true,
4743
+ },
4744
+ // Union of Lt (titlecase), Lm (modifier), and Lo (other), i.e. any letter not in Ll or Lu.
4745
+ unicodeLtmo: {
4746
+ body: new UnicodeChar('Ltmo'),
4747
+ formals: [],
4748
+ description: 'a Unicode character in Lt, Lm, or Lo',
4749
+ primitive: true,
4750
+ },
4751
+
4752
+ // These rules are not truly primitive (they could be written in userland) but are defined
4753
+ // here for bootstrapping purposes.
4754
+ spaces: {
4755
+ body: new Star(new Apply('space')),
4756
+ formals: [],
4757
+ },
4758
+ space: {
4759
+ body: new Range('\x00', ' '),
4760
+ formals: [],
4761
+ description: 'a space',
4762
+ },
4763
+ }
4717
4764
  );
4718
4765
 
4719
4766
  // This method is called from main.js once Ohm has loaded.
4720
- Grammar.initApplicationParser = function(grammar, builderFn) {
4767
+ Grammar.initApplicationParser = function (grammar, builderFn) {
4721
4768
  ohmGrammar$1 = grammar;
4722
4769
  buildGrammar$1 = builderFn;
4723
4770
  };
@@ -4745,7 +4792,7 @@ class GrammarDecl {
4745
4792
  // TODO: The conditional expression below is an ugly hack. It's kind of ok because
4746
4793
  // I doubt anyone will ever try to declare a grammar called `BuiltInRules`. Still,
4747
4794
  // we should try to find a better way to do this.
4748
- this.name === 'BuiltInRules' ? Grammar.ProtoBuiltInRules : Grammar.BuiltInRules,
4795
+ this.name === 'BuiltInRules' ? Grammar.ProtoBuiltInRules : Grammar.BuiltInRules
4749
4796
  );
4750
4797
  }
4751
4798
  return this.superGrammar;
@@ -4813,10 +4860,10 @@ class GrammarDecl {
4813
4860
  // Creates a Grammar instance, and if it passes the sanity checks, returns it.
4814
4861
  build() {
4815
4862
  const grammar = new Grammar(
4816
- this.name,
4817
- this.ensureSuperGrammar(),
4818
- this.rules,
4819
- this.defaultStartRule,
4863
+ this.name,
4864
+ this.ensureSuperGrammar(),
4865
+ this.rules,
4866
+ this.defaultStartRule
4820
4867
  );
4821
4868
  // Initialize internal props that are inherited from the super grammar.
4822
4869
  grammar._matchStateInitializer = grammar.superGrammar._matchStateInitializer;
@@ -4917,7 +4964,7 @@ class Builder {
4917
4964
  if (superGrammar) {
4918
4965
  // `superGrammar` may be a recipe (i.e. an Array), or an actual grammar instance.
4919
4966
  gDecl.withSuperGrammar(
4920
- superGrammar instanceof Grammar ? superGrammar : this.fromRecipe(superGrammar),
4967
+ superGrammar instanceof Grammar ? superGrammar : this.fromRecipe(superGrammar)
4921
4968
  );
4922
4969
  }
4923
4970
  if (defaultStartRule) {
@@ -4941,8 +4988,8 @@ class Builder {
4941
4988
  let source;
4942
4989
  if (gDecl.source && metaInfo && metaInfo.sourceInterval) {
4943
4990
  source = gDecl.source.subInterval(
4944
- metaInfo.sourceInterval[0],
4945
- metaInfo.sourceInterval[1] - metaInfo.sourceInterval[0],
4991
+ metaInfo.sourceInterval[0],
4992
+ metaInfo.sourceInterval[1] - metaInfo.sourceInterval[0]
4946
4993
  );
4947
4994
  }
4948
4995
  gDecl[action](ruleName, formals, body, description, source);
@@ -5037,7 +5084,7 @@ class Builder {
5037
5084
 
5038
5085
  app(ruleName, optParams) {
5039
5086
  if (optParams && optParams.length > 0) {
5040
- optParams = optParams.map(function(param) {
5087
+ optParams = optParams.map(function (param) {
5041
5088
  return param instanceof PExpr ? param : this.fromRecipe(param);
5042
5089
  }, this);
5043
5090
  }
@@ -5049,10 +5096,10 @@ class Builder {
5049
5096
  // `this.currentDecl` and `this.currentRuleName` being set.
5050
5097
  splice(beforeTerms, afterTerms) {
5051
5098
  return new Splice(
5052
- this.currentDecl.superGrammar,
5053
- this.currentRuleName,
5054
- beforeTerms.map(term => this.fromRecipe(term)),
5055
- afterTerms.map(term => this.fromRecipe(term)),
5099
+ this.currentDecl.superGrammar,
5100
+ this.currentRuleName,
5101
+ beforeTerms.map(term => this.fromRecipe(term)),
5102
+ afterTerms.map(term => this.fromRecipe(term))
5056
5103
  );
5057
5104
  }
5058
5105
 
@@ -5193,10 +5240,10 @@ function buildGrammar(match, namespace, optOhmGrammarForTesting) {
5193
5240
  });
5194
5241
 
5195
5242
  return new Splice(
5196
- decl.superGrammar,
5197
- currentRuleName,
5198
- beforeTerms,
5199
- afterTerms,
5243
+ decl.superGrammar,
5244
+ currentRuleName,
5245
+ beforeTerms,
5246
+ afterTerms
5200
5247
  ).withSource(this.source);
5201
5248
  } else {
5202
5249
  return builder.alt(...args).withSource(this.source);
@@ -5341,14 +5388,14 @@ function initBuiltInSemantics(builtInRules) {
5341
5388
  };
5342
5389
 
5343
5390
  Semantics.BuiltInSemantics = Semantics.createSemantics(builtInRules, null).addOperation(
5344
- 'asIteration',
5345
- {
5346
- emptyListOf: actions.empty,
5347
- nonemptyListOf: actions.nonEmpty,
5348
- EmptyListOf: actions.empty,
5349
- NonemptyListOf: actions.nonEmpty,
5350
- _iter: actions.self,
5351
- },
5391
+ 'asIteration',
5392
+ {
5393
+ emptyListOf: actions.empty,
5394
+ nonemptyListOf: actions.nonEmpty,
5395
+ EmptyListOf: actions.empty,
5396
+ NonemptyListOf: actions.nonEmpty,
5397
+ _iter: actions.self,
5398
+ }
5352
5399
  );
5353
5400
  }
5354
5401
 
@@ -5537,12 +5584,12 @@ const applyDedent = new Apply('dedent');
5537
5584
  const newAnyBody = new Splice(BuiltInRules, 'any', [applyIndent, applyDedent], []);
5538
5585
 
5539
5586
  const IndentationSensitive = new Builder()
5540
- .newGrammar('IndentationSensitive')
5541
- .withSuperGrammar(BuiltInRules)
5542
- .define('indent', [], new Indentation(true), INDENT_DESCRIPTION, undefined, true)
5543
- .define('dedent', [], new Indentation(false), DEDENT_DESCRIPTION, undefined, true)
5544
- .extend('any', [], newAnyBody, 'any character', undefined)
5545
- .build();
5587
+ .newGrammar('IndentationSensitive')
5588
+ .withSuperGrammar(BuiltInRules)
5589
+ .define('indent', [], new Indentation(true), INDENT_DESCRIPTION, undefined, true)
5590
+ .define('dedent', [], new Indentation(false), DEDENT_DESCRIPTION, undefined, true)
5591
+ .extend('any', [], newAnyBody, 'any character', undefined)
5592
+ .build();
5546
5593
 
5547
5594
  Object.assign(IndentationSensitive, {
5548
5595
  _matchStateInitializer(state) {
@@ -5553,7 +5600,7 @@ Object.assign(IndentationSensitive, {
5553
5600
  });
5554
5601
 
5555
5602
  // Generated by scripts/prebuild.js
5556
- const version = '17.2.1';
5603
+ const version = '17.4.0';
5557
5604
 
5558
5605
  Grammar.initApplicationParser(ohmGrammar, buildGrammar);
5559
5606
 
@@ -5581,8 +5628,8 @@ function grammar(source, optNamespace) {
5581
5628
  const secondGrammar = ns[grammarNames[1]];
5582
5629
  const interval = secondGrammar.source;
5583
5630
  throw new Error(
5584
- getLineAndColumnMessage(interval.sourceString, interval.startIdx) +
5585
- 'Found more than one grammar definition -- use ohm.grammars() instead.',
5631
+ getLineAndColumnMessage(interval.sourceString, interval.startIdx) +
5632
+ 'Found more than one grammar definition -- use ohm.grammars() instead.'
5586
5633
  );
5587
5634
  }
5588
5635
  return ns[grammarNames[0]]; // Return the one and only grammar.
@@ -5596,7 +5643,7 @@ function grammars(source, optNamespace) {
5596
5643
  source = source.toString();
5597
5644
  } else {
5598
5645
  throw new TypeError(
5599
- 'Expected string as first argument, got ' + unexpectedObjToString(source),
5646
+ 'Expected string as first argument, got ' + unexpectedObjToString(source)
5600
5647
  );
5601
5648
  }
5602
5649
  }