ohm-js 17.2.1 → 17.3.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.
- package/dist/ohm-extras.cjs +517 -471
- package/dist/ohm-extras.js +517 -471
- package/dist/ohm.cjs +510 -464
- package/dist/ohm.cjs.map +1 -1
- package/dist/ohm.js +511 -465
- package/dist/ohm.min.js +1 -1
- package/extras/VisitorFamily.js +9 -9
- package/extras/index.d.ts +1 -1
- package/extras/semantics-toAST.js +1 -1
- package/index.d.ts +24 -4
- package/package.json +4 -4
- package/src/Builder.js +8 -8
- package/src/CaseInsensitiveTerminal.js +3 -3
- package/src/Grammar.js +69 -70
- package/src/GrammarDecl.js +5 -5
- package/src/IndentationSensitive.js +6 -6
- package/src/InputStream.js +3 -0
- package/src/Interval.js +19 -7
- package/src/MatchResult.js +14 -16
- package/src/MatchState.js +17 -17
- package/src/PosInfo.js +7 -7
- package/src/Semantics.js +43 -43
- package/src/Trace.js +19 -19
- package/src/buildGrammar.js +4 -4
- package/src/common.js +9 -9
- package/src/errors.js +36 -36
- package/src/main.js +3 -3
- package/src/nodes.js +4 -4
- package/src/ohm-cmd.js +5 -5
- package/src/pexprs-allowsSkippingPrecedingSpace.js +2 -2
- package/src/pexprs-assertAllApplicationsAreValid.js +11 -11
- package/src/pexprs-assertChoicesHaveUniformArity.js +9 -9
- package/src/pexprs-assertIteratedExprsAreNotNullable.js +7 -7
- package/src/pexprs-eval.js +39 -36
- package/src/pexprs-getArity.js +6 -6
- package/src/pexprs-introduceParams.js +5 -5
- package/src/pexprs-isNullable.js +9 -9
- package/src/pexprs-main.js +12 -4
- package/src/pexprs-outputRecipe.js +15 -15
- package/src/pexprs-substituteParams.js +6 -6
- package/src/pexprs-toArgumentNameList.js +20 -20
- package/src/pexprs-toDisplayString.js +5 -5
- package/src/pexprs-toFailure.js +12 -12
- package/src/pexprs-toString.js +20 -20
- package/src/semanticsDeferredInit.js +8 -8
- package/src/unicode.js +54 -0
- package/src/util.js +3 -3
- package/src/version.js +1 -1
- package/dist/ohm-grammar.js.new +0 -0
- 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
|
-
|
|
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
|
|
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
|
-
//
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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(
|
|
435
|
+
constructor(categoryOrProp) {
|
|
412
436
|
super();
|
|
413
|
-
this.
|
|
414
|
-
|
|
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
|
-
|
|
488
|
-
|
|
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
|
-
|
|
497
|
-
|
|
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
|
-
|
|
506
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
556
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
584
|
-
|
|
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
|
-
|
|
625
|
+
`applySyntactic is for syntactic rules, but '${ruleName}' is a lexical rule. ` +
|
|
594
626
|
syntacticVsLexicalNote,
|
|
595
|
-
|
|
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
|
-
|
|
604
|
-
|
|
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
|
-
|
|
631
|
-
|
|
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
|
-
|
|
650
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
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
|
-
|
|
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
|
-
|
|
968
|
-
|
|
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
|
-
|
|
972
|
-
|
|
973
|
-
|
|
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
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1113
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1256
|
-
|
|
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
|
-
|
|
1279
|
-
|
|
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
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
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
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
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
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
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;
|
|
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
|
-
|
|
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
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2067
|
-
|
|
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
|
-
|
|
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();
|
|
@@ -2248,8 +2293,8 @@ Apply.prototype.reallyEval = function(state) {
|
|
|
2248
2293
|
// Fix the input stream's examinedLength -- it should be the maximum examined length
|
|
2249
2294
|
// across all applications, not just this one.
|
|
2250
2295
|
inputStream.examinedLength = Math.max(
|
|
2251
|
-
|
|
2252
|
-
|
|
2296
|
+
inputStream.examinedLength,
|
|
2297
|
+
origInputStreamExaminedLength
|
|
2253
2298
|
);
|
|
2254
2299
|
|
|
2255
2300
|
state.exitApplication(origPosInfo, value);
|
|
@@ -2257,7 +2302,7 @@ Apply.prototype.reallyEval = function(state) {
|
|
|
2257
2302
|
return succeeded;
|
|
2258
2303
|
};
|
|
2259
2304
|
|
|
2260
|
-
Apply.prototype.evalOnce = function(expr, state) {
|
|
2305
|
+
Apply.prototype.evalOnce = function (expr, state) {
|
|
2261
2306
|
const {inputStream} = state;
|
|
2262
2307
|
const origPos = inputStream.pos;
|
|
2263
2308
|
|
|
@@ -2272,7 +2317,7 @@ Apply.prototype.evalOnce = function(expr, state) {
|
|
|
2272
2317
|
}
|
|
2273
2318
|
};
|
|
2274
2319
|
|
|
2275
|
-
Apply.prototype.growSeedResult = function(body, state, origPos, lrMemoRec, newValue) {
|
|
2320
|
+
Apply.prototype.growSeedResult = function (body, state, origPos, lrMemoRec, newValue) {
|
|
2276
2321
|
if (!newValue) {
|
|
2277
2322
|
return false;
|
|
2278
2323
|
}
|
|
@@ -2290,13 +2335,13 @@ Apply.prototype.growSeedResult = function(body, state, origPos, lrMemoRec, newVa
|
|
|
2290
2335
|
// element in `state.trace`.
|
|
2291
2336
|
const seedTrace = state.trace[state.trace.length - 1];
|
|
2292
2337
|
lrMemoRec.traceEntry = new Trace(
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2338
|
+
state.input,
|
|
2339
|
+
origPos,
|
|
2340
|
+
inputStream.pos,
|
|
2341
|
+
this,
|
|
2342
|
+
true,
|
|
2343
|
+
[newValue],
|
|
2344
|
+
[seedTrace.clone()]
|
|
2300
2345
|
);
|
|
2301
2346
|
}
|
|
2302
2347
|
inputStream.pos = origPos;
|
|
@@ -2316,17 +2361,19 @@ Apply.prototype.growSeedResult = function(body, state, origPos, lrMemoRec, newVa
|
|
|
2316
2361
|
return lrMemoRec.value;
|
|
2317
2362
|
};
|
|
2318
2363
|
|
|
2319
|
-
UnicodeChar.prototype.eval = function(state) {
|
|
2364
|
+
UnicodeChar.prototype.eval = function (state) {
|
|
2320
2365
|
const {inputStream} = state;
|
|
2321
2366
|
const origPos = inputStream.pos;
|
|
2322
|
-
const
|
|
2323
|
-
if (
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2367
|
+
const cp = inputStream.nextCodePoint();
|
|
2368
|
+
if (cp !== undefined && cp <= MAX_CODE_POINT) {
|
|
2369
|
+
const ch = String.fromCodePoint(cp);
|
|
2370
|
+
if (this.pattern.test(ch)) {
|
|
2371
|
+
state.pushBinding(new TerminalNode(ch.length), origPos);
|
|
2372
|
+
return true;
|
|
2373
|
+
}
|
|
2329
2374
|
}
|
|
2375
|
+
state.processFailure(origPos, this);
|
|
2376
|
+
return false;
|
|
2330
2377
|
};
|
|
2331
2378
|
|
|
2332
2379
|
// --------------------------------------------------------------------
|
|
@@ -2342,17 +2389,17 @@ any.getArity =
|
|
|
2342
2389
|
Param.prototype.getArity =
|
|
2343
2390
|
Apply.prototype.getArity =
|
|
2344
2391
|
UnicodeChar.prototype.getArity =
|
|
2345
|
-
function() {
|
|
2392
|
+
function () {
|
|
2346
2393
|
return 1;
|
|
2347
2394
|
};
|
|
2348
2395
|
|
|
2349
|
-
Alt.prototype.getArity = function() {
|
|
2396
|
+
Alt.prototype.getArity = function () {
|
|
2350
2397
|
// This is ok b/c all terms must have the same arity -- this property is
|
|
2351
2398
|
// checked by the Grammar constructor.
|
|
2352
2399
|
return this.terms.length === 0 ? 0 : this.terms[0].getArity();
|
|
2353
2400
|
};
|
|
2354
2401
|
|
|
2355
|
-
Seq.prototype.getArity = function() {
|
|
2402
|
+
Seq.prototype.getArity = function () {
|
|
2356
2403
|
let arity = 0;
|
|
2357
2404
|
for (let idx = 0; idx < this.factors.length; idx++) {
|
|
2358
2405
|
arity += this.factors[idx].getArity();
|
|
@@ -2360,15 +2407,15 @@ Seq.prototype.getArity = function() {
|
|
|
2360
2407
|
return arity;
|
|
2361
2408
|
};
|
|
2362
2409
|
|
|
2363
|
-
Iter.prototype.getArity = function() {
|
|
2410
|
+
Iter.prototype.getArity = function () {
|
|
2364
2411
|
return this.expr.getArity();
|
|
2365
2412
|
};
|
|
2366
2413
|
|
|
2367
|
-
Not.prototype.getArity = function() {
|
|
2414
|
+
Not.prototype.getArity = function () {
|
|
2368
2415
|
return 0;
|
|
2369
2416
|
};
|
|
2370
2417
|
|
|
2371
|
-
Lookahead.prototype.getArity = Lex.prototype.getArity = function() {
|
|
2418
|
+
Lookahead.prototype.getArity = Lex.prototype.getArity = function () {
|
|
2372
2419
|
return this.expr.getArity();
|
|
2373
2420
|
};
|
|
2374
2421
|
|
|
@@ -2391,38 +2438,38 @@ function getMetaInfo(expr, grammarInterval) {
|
|
|
2391
2438
|
|
|
2392
2439
|
PExpr.prototype.outputRecipe = abstract('outputRecipe');
|
|
2393
2440
|
|
|
2394
|
-
any.outputRecipe = function(formals, grammarInterval) {
|
|
2441
|
+
any.outputRecipe = function (formals, grammarInterval) {
|
|
2395
2442
|
return ['any', getMetaInfo(this, grammarInterval)];
|
|
2396
2443
|
};
|
|
2397
2444
|
|
|
2398
|
-
end.outputRecipe = function(formals, grammarInterval) {
|
|
2445
|
+
end.outputRecipe = function (formals, grammarInterval) {
|
|
2399
2446
|
return ['end', getMetaInfo(this, grammarInterval)];
|
|
2400
2447
|
};
|
|
2401
2448
|
|
|
2402
|
-
Terminal.prototype.outputRecipe = function(formals, grammarInterval) {
|
|
2449
|
+
Terminal.prototype.outputRecipe = function (formals, grammarInterval) {
|
|
2403
2450
|
return ['terminal', getMetaInfo(this, grammarInterval), this.obj];
|
|
2404
2451
|
};
|
|
2405
2452
|
|
|
2406
|
-
Range.prototype.outputRecipe = function(formals, grammarInterval) {
|
|
2453
|
+
Range.prototype.outputRecipe = function (formals, grammarInterval) {
|
|
2407
2454
|
return ['range', getMetaInfo(this, grammarInterval), this.from, this.to];
|
|
2408
2455
|
};
|
|
2409
2456
|
|
|
2410
|
-
Param.prototype.outputRecipe = function(formals, grammarInterval) {
|
|
2457
|
+
Param.prototype.outputRecipe = function (formals, grammarInterval) {
|
|
2411
2458
|
return ['param', getMetaInfo(this, grammarInterval), this.index];
|
|
2412
2459
|
};
|
|
2413
2460
|
|
|
2414
|
-
Alt.prototype.outputRecipe = function(formals, grammarInterval) {
|
|
2461
|
+
Alt.prototype.outputRecipe = function (formals, grammarInterval) {
|
|
2415
2462
|
return ['alt', getMetaInfo(this, grammarInterval)].concat(
|
|
2416
|
-
|
|
2463
|
+
this.terms.map(term => term.outputRecipe(formals, grammarInterval))
|
|
2417
2464
|
);
|
|
2418
2465
|
};
|
|
2419
2466
|
|
|
2420
|
-
Extend.prototype.outputRecipe = function(formals, grammarInterval) {
|
|
2467
|
+
Extend.prototype.outputRecipe = function (formals, grammarInterval) {
|
|
2421
2468
|
const extension = this.terms[0]; // [extension, original]
|
|
2422
2469
|
return extension.outputRecipe(formals, grammarInterval);
|
|
2423
2470
|
};
|
|
2424
2471
|
|
|
2425
|
-
Splice.prototype.outputRecipe = function(formals, grammarInterval) {
|
|
2472
|
+
Splice.prototype.outputRecipe = function (formals, grammarInterval) {
|
|
2426
2473
|
const beforeTerms = this.terms.slice(0, this.expansionPos);
|
|
2427
2474
|
const afterTerms = this.terms.slice(this.expansionPos + 1);
|
|
2428
2475
|
return [
|
|
@@ -2433,9 +2480,9 @@ Splice.prototype.outputRecipe = function(formals, grammarInterval) {
|
|
|
2433
2480
|
];
|
|
2434
2481
|
};
|
|
2435
2482
|
|
|
2436
|
-
Seq.prototype.outputRecipe = function(formals, grammarInterval) {
|
|
2483
|
+
Seq.prototype.outputRecipe = function (formals, grammarInterval) {
|
|
2437
2484
|
return ['seq', getMetaInfo(this, grammarInterval)].concat(
|
|
2438
|
-
|
|
2485
|
+
this.factors.map(factor => factor.outputRecipe(formals, grammarInterval))
|
|
2439
2486
|
);
|
|
2440
2487
|
};
|
|
2441
2488
|
|
|
@@ -2445,7 +2492,7 @@ Star.prototype.outputRecipe =
|
|
|
2445
2492
|
Not.prototype.outputRecipe =
|
|
2446
2493
|
Lookahead.prototype.outputRecipe =
|
|
2447
2494
|
Lex.prototype.outputRecipe =
|
|
2448
|
-
function(formals, grammarInterval) {
|
|
2495
|
+
function (formals, grammarInterval) {
|
|
2449
2496
|
return [
|
|
2450
2497
|
this.constructor.name.toLowerCase(),
|
|
2451
2498
|
getMetaInfo(this, grammarInterval),
|
|
@@ -2453,7 +2500,7 @@ Star.prototype.outputRecipe =
|
|
|
2453
2500
|
];
|
|
2454
2501
|
};
|
|
2455
2502
|
|
|
2456
|
-
Apply.prototype.outputRecipe = function(formals, grammarInterval) {
|
|
2503
|
+
Apply.prototype.outputRecipe = function (formals, grammarInterval) {
|
|
2457
2504
|
return [
|
|
2458
2505
|
'app',
|
|
2459
2506
|
getMetaInfo(this, grammarInterval),
|
|
@@ -2462,8 +2509,8 @@ Apply.prototype.outputRecipe = function(formals, grammarInterval) {
|
|
|
2462
2509
|
];
|
|
2463
2510
|
};
|
|
2464
2511
|
|
|
2465
|
-
UnicodeChar.prototype.outputRecipe = function(formals, grammarInterval) {
|
|
2466
|
-
return ['unicodeChar', getMetaInfo(this, grammarInterval), this.
|
|
2512
|
+
UnicodeChar.prototype.outputRecipe = function (formals, grammarInterval) {
|
|
2513
|
+
return ['unicodeChar', getMetaInfo(this, grammarInterval), this.categoryOrProp];
|
|
2467
2514
|
};
|
|
2468
2515
|
|
|
2469
2516
|
// --------------------------------------------------------------------
|
|
@@ -2483,18 +2530,18 @@ any.introduceParams =
|
|
|
2483
2530
|
Range.prototype.introduceParams =
|
|
2484
2531
|
Param.prototype.introduceParams =
|
|
2485
2532
|
UnicodeChar.prototype.introduceParams =
|
|
2486
|
-
function(formals) {
|
|
2533
|
+
function (formals) {
|
|
2487
2534
|
return this;
|
|
2488
2535
|
};
|
|
2489
2536
|
|
|
2490
|
-
Alt.prototype.introduceParams = function(formals) {
|
|
2537
|
+
Alt.prototype.introduceParams = function (formals) {
|
|
2491
2538
|
this.terms.forEach((term, idx, terms) => {
|
|
2492
2539
|
terms[idx] = term.introduceParams(formals);
|
|
2493
2540
|
});
|
|
2494
2541
|
return this;
|
|
2495
2542
|
};
|
|
2496
2543
|
|
|
2497
|
-
Seq.prototype.introduceParams = function(formals) {
|
|
2544
|
+
Seq.prototype.introduceParams = function (formals) {
|
|
2498
2545
|
this.factors.forEach((factor, idx, factors) => {
|
|
2499
2546
|
factors[idx] = factor.introduceParams(formals);
|
|
2500
2547
|
});
|
|
@@ -2505,12 +2552,12 @@ Iter.prototype.introduceParams =
|
|
|
2505
2552
|
Not.prototype.introduceParams =
|
|
2506
2553
|
Lookahead.prototype.introduceParams =
|
|
2507
2554
|
Lex.prototype.introduceParams =
|
|
2508
|
-
function(formals) {
|
|
2555
|
+
function (formals) {
|
|
2509
2556
|
this.expr = this.expr.introduceParams(formals);
|
|
2510
2557
|
return this;
|
|
2511
2558
|
};
|
|
2512
2559
|
|
|
2513
|
-
Apply.prototype.introduceParams = function(formals) {
|
|
2560
|
+
Apply.prototype.introduceParams = function (formals) {
|
|
2514
2561
|
const index = formals.indexOf(this.ruleName);
|
|
2515
2562
|
if (index >= 0) {
|
|
2516
2563
|
if (this.args.length > 0) {
|
|
@@ -2531,7 +2578,7 @@ Apply.prototype.introduceParams = function(formals) {
|
|
|
2531
2578
|
// --------------------------------------------------------------------
|
|
2532
2579
|
|
|
2533
2580
|
// Returns `true` if this parsing expression may accept without consuming any input.
|
|
2534
|
-
PExpr.prototype.isNullable = function(grammar) {
|
|
2581
|
+
PExpr.prototype.isNullable = function (grammar) {
|
|
2535
2582
|
return this._isNullable(grammar, Object.create(null));
|
|
2536
2583
|
};
|
|
2537
2584
|
|
|
@@ -2542,15 +2589,15 @@ any._isNullable =
|
|
|
2542
2589
|
Param.prototype._isNullable =
|
|
2543
2590
|
Plus.prototype._isNullable =
|
|
2544
2591
|
UnicodeChar.prototype._isNullable =
|
|
2545
|
-
function(grammar, memo) {
|
|
2592
|
+
function (grammar, memo) {
|
|
2546
2593
|
return false;
|
|
2547
2594
|
};
|
|
2548
2595
|
|
|
2549
|
-
end._isNullable = function(grammar, memo) {
|
|
2596
|
+
end._isNullable = function (grammar, memo) {
|
|
2550
2597
|
return true;
|
|
2551
2598
|
};
|
|
2552
2599
|
|
|
2553
|
-
Terminal.prototype._isNullable = function(grammar, memo) {
|
|
2600
|
+
Terminal.prototype._isNullable = function (grammar, memo) {
|
|
2554
2601
|
if (typeof this.obj === 'string') {
|
|
2555
2602
|
// This is an over-simplification: it's only correct if the input is a string. If it's an array
|
|
2556
2603
|
// or an object, then the empty string parsing expression is not nullable.
|
|
@@ -2560,11 +2607,11 @@ Terminal.prototype._isNullable = function(grammar, memo) {
|
|
|
2560
2607
|
}
|
|
2561
2608
|
};
|
|
2562
2609
|
|
|
2563
|
-
Alt.prototype._isNullable = function(grammar, memo) {
|
|
2610
|
+
Alt.prototype._isNullable = function (grammar, memo) {
|
|
2564
2611
|
return this.terms.length === 0 || this.terms.some(term => term._isNullable(grammar, memo));
|
|
2565
2612
|
};
|
|
2566
2613
|
|
|
2567
|
-
Seq.prototype._isNullable = function(grammar, memo) {
|
|
2614
|
+
Seq.prototype._isNullable = function (grammar, memo) {
|
|
2568
2615
|
return this.factors.every(factor => factor._isNullable(grammar, memo));
|
|
2569
2616
|
};
|
|
2570
2617
|
|
|
@@ -2572,15 +2619,15 @@ Star.prototype._isNullable =
|
|
|
2572
2619
|
Opt.prototype._isNullable =
|
|
2573
2620
|
Not.prototype._isNullable =
|
|
2574
2621
|
Lookahead.prototype._isNullable =
|
|
2575
|
-
function(grammar, memo) {
|
|
2622
|
+
function (grammar, memo) {
|
|
2576
2623
|
return true;
|
|
2577
2624
|
};
|
|
2578
2625
|
|
|
2579
|
-
Lex.prototype._isNullable = function(grammar, memo) {
|
|
2626
|
+
Lex.prototype._isNullable = function (grammar, memo) {
|
|
2580
2627
|
return this.expr._isNullable(grammar, memo);
|
|
2581
2628
|
};
|
|
2582
2629
|
|
|
2583
|
-
Apply.prototype._isNullable = function(grammar, memo) {
|
|
2630
|
+
Apply.prototype._isNullable = function (grammar, memo) {
|
|
2584
2631
|
const key = this.toMemoKey();
|
|
2585
2632
|
if (!Object.prototype.hasOwnProperty.call(memo, key)) {
|
|
2586
2633
|
const {body} = grammar.rules[this.ruleName];
|
|
@@ -2609,19 +2656,19 @@ any.substituteParams =
|
|
|
2609
2656
|
Terminal.prototype.substituteParams =
|
|
2610
2657
|
Range.prototype.substituteParams =
|
|
2611
2658
|
UnicodeChar.prototype.substituteParams =
|
|
2612
|
-
function(actuals) {
|
|
2659
|
+
function (actuals) {
|
|
2613
2660
|
return this;
|
|
2614
2661
|
};
|
|
2615
2662
|
|
|
2616
|
-
Param.prototype.substituteParams = function(actuals) {
|
|
2663
|
+
Param.prototype.substituteParams = function (actuals) {
|
|
2617
2664
|
return checkNotNull(actuals[this.index]);
|
|
2618
2665
|
};
|
|
2619
2666
|
|
|
2620
|
-
Alt.prototype.substituteParams = function(actuals) {
|
|
2667
|
+
Alt.prototype.substituteParams = function (actuals) {
|
|
2621
2668
|
return new Alt(this.terms.map(term => term.substituteParams(actuals)));
|
|
2622
2669
|
};
|
|
2623
2670
|
|
|
2624
|
-
Seq.prototype.substituteParams = function(actuals) {
|
|
2671
|
+
Seq.prototype.substituteParams = function (actuals) {
|
|
2625
2672
|
return new Seq(this.factors.map(factor => factor.substituteParams(actuals)));
|
|
2626
2673
|
};
|
|
2627
2674
|
|
|
@@ -2629,11 +2676,11 @@ Iter.prototype.substituteParams =
|
|
|
2629
2676
|
Not.prototype.substituteParams =
|
|
2630
2677
|
Lookahead.prototype.substituteParams =
|
|
2631
2678
|
Lex.prototype.substituteParams =
|
|
2632
|
-
function(actuals) {
|
|
2679
|
+
function (actuals) {
|
|
2633
2680
|
return new this.constructor(this.expr.substituteParams(actuals));
|
|
2634
2681
|
};
|
|
2635
2682
|
|
|
2636
|
-
Apply.prototype.substituteParams = function(actuals) {
|
|
2683
|
+
Apply.prototype.substituteParams = function (actuals) {
|
|
2637
2684
|
if (this.args.length === 0) {
|
|
2638
2685
|
// Avoid making a copy of this application, as an optimization
|
|
2639
2686
|
return this;
|
|
@@ -2707,15 +2754,15 @@ function resolveDuplicatedNames(argumentNameList) {
|
|
|
2707
2754
|
// function(firstArgIndex, noDupCheck) { ... }
|
|
2708
2755
|
PExpr.prototype.toArgumentNameList = abstract('toArgumentNameList');
|
|
2709
2756
|
|
|
2710
|
-
any.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
2757
|
+
any.toArgumentNameList = function (firstArgIndex, noDupCheck) {
|
|
2711
2758
|
return ['any'];
|
|
2712
2759
|
};
|
|
2713
2760
|
|
|
2714
|
-
end.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
2761
|
+
end.toArgumentNameList = function (firstArgIndex, noDupCheck) {
|
|
2715
2762
|
return ['end'];
|
|
2716
2763
|
};
|
|
2717
2764
|
|
|
2718
|
-
Terminal.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
2765
|
+
Terminal.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
|
|
2719
2766
|
if (typeof this.obj === 'string' && /^[_a-zA-Z0-9]+$/.test(this.obj)) {
|
|
2720
2767
|
// If this terminal is a valid suffix for a JS identifier, just prepend it with '_'
|
|
2721
2768
|
return ['_' + this.obj];
|
|
@@ -2725,7 +2772,7 @@ Terminal.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
|
2725
2772
|
}
|
|
2726
2773
|
};
|
|
2727
2774
|
|
|
2728
|
-
Range.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
2775
|
+
Range.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
|
|
2729
2776
|
let argName = this.from + '_to_' + this.to;
|
|
2730
2777
|
// If the `argName` is not valid then try to prepend a `_`.
|
|
2731
2778
|
if (!isRestrictedJSIdentifier(argName)) {
|
|
@@ -2738,11 +2785,11 @@ Range.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
|
2738
2785
|
return [argName];
|
|
2739
2786
|
};
|
|
2740
2787
|
|
|
2741
|
-
Alt.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
2788
|
+
Alt.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
|
|
2742
2789
|
// `termArgNameLists` is an array of arrays where each row is the
|
|
2743
2790
|
// argument name list that corresponds to a term in this alternation.
|
|
2744
2791
|
const termArgNameLists = this.terms.map(term =>
|
|
2745
|
-
term.toArgumentNameList(firstArgIndex, true)
|
|
2792
|
+
term.toArgumentNameList(firstArgIndex, true)
|
|
2746
2793
|
);
|
|
2747
2794
|
|
|
2748
2795
|
const argumentNameList = [];
|
|
@@ -2762,7 +2809,7 @@ Alt.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
|
2762
2809
|
return argumentNameList;
|
|
2763
2810
|
};
|
|
2764
2811
|
|
|
2765
|
-
Seq.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
2812
|
+
Seq.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
|
|
2766
2813
|
// Generate the argument name list, without worrying about duplicates.
|
|
2767
2814
|
let argumentNameList = [];
|
|
2768
2815
|
this.factors.forEach(factor => {
|
|
@@ -2778,44 +2825,44 @@ Seq.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
|
2778
2825
|
return argumentNameList;
|
|
2779
2826
|
};
|
|
2780
2827
|
|
|
2781
|
-
Iter.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
2828
|
+
Iter.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
|
|
2782
2829
|
const argumentNameList = this.expr
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
exprArgumentString[exprArgumentString.length - 1] === 's'
|
|
2786
|
-
exprArgumentString + 'es'
|
|
2787
|
-
exprArgumentString + 's'
|
|
2788
|
-
|
|
2830
|
+
.toArgumentNameList(firstArgIndex, noDupCheck)
|
|
2831
|
+
.map(exprArgumentString =>
|
|
2832
|
+
exprArgumentString[exprArgumentString.length - 1] === 's'
|
|
2833
|
+
? exprArgumentString + 'es'
|
|
2834
|
+
: exprArgumentString + 's'
|
|
2835
|
+
);
|
|
2789
2836
|
if (!noDupCheck) {
|
|
2790
2837
|
resolveDuplicatedNames(argumentNameList);
|
|
2791
2838
|
}
|
|
2792
2839
|
return argumentNameList;
|
|
2793
2840
|
};
|
|
2794
2841
|
|
|
2795
|
-
Opt.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
2842
|
+
Opt.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
|
|
2796
2843
|
return this.expr.toArgumentNameList(firstArgIndex, noDupCheck).map(argName => {
|
|
2797
2844
|
return 'opt' + argName[0].toUpperCase() + argName.slice(1);
|
|
2798
2845
|
});
|
|
2799
2846
|
};
|
|
2800
2847
|
|
|
2801
|
-
Not.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
2848
|
+
Not.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
|
|
2802
2849
|
return [];
|
|
2803
2850
|
};
|
|
2804
2851
|
|
|
2805
2852
|
Lookahead.prototype.toArgumentNameList = Lex.prototype.toArgumentNameList =
|
|
2806
|
-
function(firstArgIndex, noDupCheck) {
|
|
2853
|
+
function (firstArgIndex, noDupCheck) {
|
|
2807
2854
|
return this.expr.toArgumentNameList(firstArgIndex, noDupCheck);
|
|
2808
2855
|
};
|
|
2809
2856
|
|
|
2810
|
-
Apply.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
2857
|
+
Apply.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
|
|
2811
2858
|
return [this.ruleName];
|
|
2812
2859
|
};
|
|
2813
2860
|
|
|
2814
|
-
UnicodeChar.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
2861
|
+
UnicodeChar.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
|
|
2815
2862
|
return ['$' + firstArgIndex];
|
|
2816
2863
|
};
|
|
2817
2864
|
|
|
2818
|
-
Param.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
2865
|
+
Param.prototype.toArgumentNameList = function (firstArgIndex, noDupCheck) {
|
|
2819
2866
|
return ['param' + this.index];
|
|
2820
2867
|
};
|
|
2821
2868
|
|
|
@@ -2828,7 +2875,7 @@ Param.prototype.toArgumentNameList = function(firstArgIndex, noDupCheck) {
|
|
|
2828
2875
|
// Returns a string representing the PExpr, for use as a UI label, etc.
|
|
2829
2876
|
PExpr.prototype.toDisplayString = abstract('toDisplayString');
|
|
2830
2877
|
|
|
2831
|
-
Alt.prototype.toDisplayString = Seq.prototype.toDisplayString = function() {
|
|
2878
|
+
Alt.prototype.toDisplayString = Seq.prototype.toDisplayString = function () {
|
|
2832
2879
|
if (this.source) {
|
|
2833
2880
|
return this.source.trimmed().contents;
|
|
2834
2881
|
}
|
|
@@ -2844,11 +2891,11 @@ any.toDisplayString =
|
|
|
2844
2891
|
Terminal.prototype.toDisplayString =
|
|
2845
2892
|
Range.prototype.toDisplayString =
|
|
2846
2893
|
Param.prototype.toDisplayString =
|
|
2847
|
-
function() {
|
|
2894
|
+
function () {
|
|
2848
2895
|
return this.toString();
|
|
2849
2896
|
};
|
|
2850
2897
|
|
|
2851
|
-
Apply.prototype.toDisplayString = function() {
|
|
2898
|
+
Apply.prototype.toDisplayString = function () {
|
|
2852
2899
|
if (this.args.length > 0) {
|
|
2853
2900
|
const ps = this.args.map(arg => arg.toDisplayString());
|
|
2854
2901
|
return this.ruleName + '<' + ps.join(',') + '>';
|
|
@@ -2857,8 +2904,8 @@ Apply.prototype.toDisplayString = function() {
|
|
|
2857
2904
|
}
|
|
2858
2905
|
};
|
|
2859
2906
|
|
|
2860
|
-
UnicodeChar.prototype.toDisplayString = function() {
|
|
2861
|
-
return 'Unicode [' + this.
|
|
2907
|
+
UnicodeChar.prototype.toDisplayString = function () {
|
|
2908
|
+
return 'Unicode [' + this.categoryOrProp + '] character';
|
|
2862
2909
|
};
|
|
2863
2910
|
|
|
2864
2911
|
// --------------------------------------------------------------------
|
|
@@ -2961,34 +3008,34 @@ class Failure {
|
|
|
2961
3008
|
|
|
2962
3009
|
PExpr.prototype.toFailure = abstract('toFailure');
|
|
2963
3010
|
|
|
2964
|
-
any.toFailure = function(grammar) {
|
|
3011
|
+
any.toFailure = function (grammar) {
|
|
2965
3012
|
return new Failure(this, 'any object', 'description');
|
|
2966
3013
|
};
|
|
2967
3014
|
|
|
2968
|
-
end.toFailure = function(grammar) {
|
|
3015
|
+
end.toFailure = function (grammar) {
|
|
2969
3016
|
return new Failure(this, 'end of input', 'description');
|
|
2970
3017
|
};
|
|
2971
3018
|
|
|
2972
|
-
Terminal.prototype.toFailure = function(grammar) {
|
|
3019
|
+
Terminal.prototype.toFailure = function (grammar) {
|
|
2973
3020
|
return new Failure(this, this.obj, 'string');
|
|
2974
3021
|
};
|
|
2975
3022
|
|
|
2976
|
-
Range.prototype.toFailure = function(grammar) {
|
|
3023
|
+
Range.prototype.toFailure = function (grammar) {
|
|
2977
3024
|
// TODO: come up with something better
|
|
2978
3025
|
return new Failure(this, JSON.stringify(this.from) + '..' + JSON.stringify(this.to), 'code');
|
|
2979
3026
|
};
|
|
2980
3027
|
|
|
2981
|
-
Not.prototype.toFailure = function(grammar) {
|
|
3028
|
+
Not.prototype.toFailure = function (grammar) {
|
|
2982
3029
|
const description =
|
|
2983
3030
|
this.expr === any ? 'nothing' : 'not ' + this.expr.toFailure(grammar);
|
|
2984
3031
|
return new Failure(this, description, 'description');
|
|
2985
3032
|
};
|
|
2986
3033
|
|
|
2987
|
-
Lookahead.prototype.toFailure = function(grammar) {
|
|
3034
|
+
Lookahead.prototype.toFailure = function (grammar) {
|
|
2988
3035
|
return this.expr.toFailure(grammar);
|
|
2989
3036
|
};
|
|
2990
3037
|
|
|
2991
|
-
Apply.prototype.toFailure = function(grammar) {
|
|
3038
|
+
Apply.prototype.toFailure = function (grammar) {
|
|
2992
3039
|
let {description} = grammar.rules[this.ruleName];
|
|
2993
3040
|
if (!description) {
|
|
2994
3041
|
const article = /^[aeiouAEIOU]/.test(this.ruleName) ? 'an' : 'a';
|
|
@@ -2997,23 +3044,23 @@ Apply.prototype.toFailure = function(grammar) {
|
|
|
2997
3044
|
return new Failure(this, description, 'description');
|
|
2998
3045
|
};
|
|
2999
3046
|
|
|
3000
|
-
UnicodeChar.prototype.toFailure = function(grammar) {
|
|
3001
|
-
return new Failure(this, 'a Unicode [' + this.
|
|
3047
|
+
UnicodeChar.prototype.toFailure = function (grammar) {
|
|
3048
|
+
return new Failure(this, 'a Unicode [' + this.categoryOrProp + '] character', 'description');
|
|
3002
3049
|
};
|
|
3003
3050
|
|
|
3004
|
-
Alt.prototype.toFailure = function(grammar) {
|
|
3051
|
+
Alt.prototype.toFailure = function (grammar) {
|
|
3005
3052
|
const fs = this.terms.map(t => t.toFailure(grammar));
|
|
3006
3053
|
const description = '(' + fs.join(' or ') + ')';
|
|
3007
3054
|
return new Failure(this, description, 'description');
|
|
3008
3055
|
};
|
|
3009
3056
|
|
|
3010
|
-
Seq.prototype.toFailure = function(grammar) {
|
|
3057
|
+
Seq.prototype.toFailure = function (grammar) {
|
|
3011
3058
|
const fs = this.factors.map(f => f.toFailure(grammar));
|
|
3012
3059
|
const description = '(' + fs.join(' ') + ')';
|
|
3013
3060
|
return new Failure(this, description, 'description');
|
|
3014
3061
|
};
|
|
3015
3062
|
|
|
3016
|
-
Iter.prototype.toFailure = function(grammar) {
|
|
3063
|
+
Iter.prototype.toFailure = function (grammar) {
|
|
3017
3064
|
const description = '(' + this.expr.toFailure(grammar) + this.operator + ')';
|
|
3018
3065
|
return new Failure(this, description, 'description');
|
|
3019
3066
|
};
|
|
@@ -3031,55 +3078,55 @@ Iter.prototype.toFailure = function(grammar) {
|
|
|
3031
3078
|
*/
|
|
3032
3079
|
PExpr.prototype.toString = abstract('toString');
|
|
3033
3080
|
|
|
3034
|
-
any.toString = function() {
|
|
3081
|
+
any.toString = function () {
|
|
3035
3082
|
return 'any';
|
|
3036
3083
|
};
|
|
3037
3084
|
|
|
3038
|
-
end.toString = function() {
|
|
3085
|
+
end.toString = function () {
|
|
3039
3086
|
return 'end';
|
|
3040
3087
|
};
|
|
3041
3088
|
|
|
3042
|
-
Terminal.prototype.toString = function() {
|
|
3089
|
+
Terminal.prototype.toString = function () {
|
|
3043
3090
|
return JSON.stringify(this.obj);
|
|
3044
3091
|
};
|
|
3045
3092
|
|
|
3046
|
-
Range.prototype.toString = function() {
|
|
3093
|
+
Range.prototype.toString = function () {
|
|
3047
3094
|
return JSON.stringify(this.from) + '..' + JSON.stringify(this.to);
|
|
3048
3095
|
};
|
|
3049
3096
|
|
|
3050
|
-
Param.prototype.toString = function() {
|
|
3097
|
+
Param.prototype.toString = function () {
|
|
3051
3098
|
return '$' + this.index;
|
|
3052
3099
|
};
|
|
3053
3100
|
|
|
3054
|
-
Lex.prototype.toString = function() {
|
|
3101
|
+
Lex.prototype.toString = function () {
|
|
3055
3102
|
return '#(' + this.expr.toString() + ')';
|
|
3056
3103
|
};
|
|
3057
3104
|
|
|
3058
|
-
Alt.prototype.toString = function() {
|
|
3059
|
-
return this.terms.length === 1
|
|
3060
|
-
this.terms[0].toString()
|
|
3061
|
-
'(' + this.terms.map(term => term.toString()).join(' | ') + ')';
|
|
3105
|
+
Alt.prototype.toString = function () {
|
|
3106
|
+
return this.terms.length === 1
|
|
3107
|
+
? this.terms[0].toString()
|
|
3108
|
+
: '(' + this.terms.map(term => term.toString()).join(' | ') + ')';
|
|
3062
3109
|
};
|
|
3063
3110
|
|
|
3064
|
-
Seq.prototype.toString = function() {
|
|
3065
|
-
return this.factors.length === 1
|
|
3066
|
-
this.factors[0].toString()
|
|
3067
|
-
'(' + this.factors.map(factor => factor.toString()).join(' ') + ')';
|
|
3111
|
+
Seq.prototype.toString = function () {
|
|
3112
|
+
return this.factors.length === 1
|
|
3113
|
+
? this.factors[0].toString()
|
|
3114
|
+
: '(' + this.factors.map(factor => factor.toString()).join(' ') + ')';
|
|
3068
3115
|
};
|
|
3069
3116
|
|
|
3070
|
-
Iter.prototype.toString = function() {
|
|
3117
|
+
Iter.prototype.toString = function () {
|
|
3071
3118
|
return this.expr + this.operator;
|
|
3072
3119
|
};
|
|
3073
3120
|
|
|
3074
|
-
Not.prototype.toString = function() {
|
|
3121
|
+
Not.prototype.toString = function () {
|
|
3075
3122
|
return '~' + this.expr;
|
|
3076
3123
|
};
|
|
3077
3124
|
|
|
3078
|
-
Lookahead.prototype.toString = function() {
|
|
3125
|
+
Lookahead.prototype.toString = function () {
|
|
3079
3126
|
return '&' + this.expr;
|
|
3080
3127
|
};
|
|
3081
3128
|
|
|
3082
|
-
Apply.prototype.toString = function() {
|
|
3129
|
+
Apply.prototype.toString = function () {
|
|
3083
3130
|
if (this.args.length > 0) {
|
|
3084
3131
|
const ps = this.args.map(arg => arg.toString());
|
|
3085
3132
|
return this.ruleName + '<' + ps.join(',') + '>';
|
|
@@ -3088,8 +3135,8 @@ Apply.prototype.toString = function() {
|
|
|
3088
3135
|
}
|
|
3089
3136
|
};
|
|
3090
3137
|
|
|
3091
|
-
UnicodeChar.prototype.toString = function() {
|
|
3092
|
-
return '\\p{' + this.
|
|
3138
|
+
UnicodeChar.prototype.toString = function () {
|
|
3139
|
+
return '\\p{' + this.categoryOrProp + '}';
|
|
3093
3140
|
};
|
|
3094
3141
|
|
|
3095
3142
|
class CaseInsensitiveTerminal extends PExpr {
|
|
@@ -3137,9 +3184,9 @@ class CaseInsensitiveTerminal extends PExpr {
|
|
|
3137
3184
|
|
|
3138
3185
|
toFailure(grammar) {
|
|
3139
3186
|
return new Failure(
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3187
|
+
this,
|
|
3188
|
+
this.obj.toFailure(grammar) + ' (case-insensitive)',
|
|
3189
|
+
'description'
|
|
3143
3190
|
);
|
|
3144
3191
|
}
|
|
3145
3192
|
|
|
@@ -3235,8 +3282,8 @@ class MatchState {
|
|
|
3235
3282
|
posInfo.exit();
|
|
3236
3283
|
|
|
3237
3284
|
this.rightmostFailurePosition = Math.max(
|
|
3238
|
-
|
|
3239
|
-
|
|
3285
|
+
this.rightmostFailurePosition,
|
|
3286
|
+
this._rightmostFailurePositionStack.pop()
|
|
3240
3287
|
);
|
|
3241
3288
|
|
|
3242
3289
|
if (optNode) {
|
|
@@ -3372,9 +3419,9 @@ class MatchState {
|
|
|
3372
3419
|
}
|
|
3373
3420
|
|
|
3374
3421
|
_getRightmostFailureOffset() {
|
|
3375
|
-
return this.rightmostFailurePosition >= 0
|
|
3376
|
-
this.posToOffset(this.rightmostFailurePosition)
|
|
3377
|
-
-1;
|
|
3422
|
+
return this.rightmostFailurePosition >= 0
|
|
3423
|
+
? this.posToOffset(this.rightmostFailurePosition)
|
|
3424
|
+
: -1;
|
|
3378
3425
|
}
|
|
3379
3426
|
|
|
3380
3427
|
// Returns the memoized trace entry for `expr` at `pos`, if one exists, `null` otherwise.
|
|
@@ -3431,8 +3478,8 @@ class MatchState {
|
|
|
3431
3478
|
const memoRecRightmostFailurePosition =
|
|
3432
3479
|
this.inputStream.pos + memoRec.rightmostFailureOffset;
|
|
3433
3480
|
this.rightmostFailurePosition = Math.max(
|
|
3434
|
-
|
|
3435
|
-
|
|
3481
|
+
this.rightmostFailurePosition,
|
|
3482
|
+
memoRecRightmostFailurePosition
|
|
3436
3483
|
);
|
|
3437
3484
|
if (
|
|
3438
3485
|
this.recordedFailures &&
|
|
@@ -3443,8 +3490,8 @@ class MatchState {
|
|
|
3443
3490
|
}
|
|
3444
3491
|
|
|
3445
3492
|
this.inputStream.examinedLength = Math.max(
|
|
3446
|
-
|
|
3447
|
-
|
|
3493
|
+
this.inputStream.examinedLength,
|
|
3494
|
+
memoRec.examinedLength + origPos
|
|
3448
3495
|
);
|
|
3449
3496
|
|
|
3450
3497
|
if (memoRec.value) {
|
|
@@ -3522,7 +3569,7 @@ class MatchState {
|
|
|
3522
3569
|
let rightmostFailures;
|
|
3523
3570
|
if (this.recordedFailures) {
|
|
3524
3571
|
rightmostFailures = Object.keys(this.recordedFailures).map(
|
|
3525
|
-
|
|
3572
|
+
key => this.recordedFailures[key]
|
|
3526
3573
|
);
|
|
3527
3574
|
}
|
|
3528
3575
|
const cst = this._bindings[0];
|
|
@@ -3530,13 +3577,13 @@ class MatchState {
|
|
|
3530
3577
|
cst.grammar = this.grammar;
|
|
3531
3578
|
}
|
|
3532
3579
|
return new MatchResult(
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3580
|
+
this.matcher,
|
|
3581
|
+
this.input,
|
|
3582
|
+
this.startExpr,
|
|
3583
|
+
cst,
|
|
3584
|
+
this._bindingOffsets[0],
|
|
3585
|
+
this.rightmostFailurePosition,
|
|
3586
|
+
rightmostFailures
|
|
3540
3587
|
);
|
|
3541
3588
|
}
|
|
3542
3589
|
|
|
@@ -3849,11 +3896,11 @@ class Semantics {
|
|
|
3849
3896
|
if (superSemantics) {
|
|
3850
3897
|
if (!(grammar.equals(this.super.grammar) || grammar._inheritsFrom(this.super.grammar))) {
|
|
3851
3898
|
throw new Error(
|
|
3852
|
-
|
|
3899
|
+
"Cannot extend a semantics for grammar '" +
|
|
3853
3900
|
this.super.grammar.name +
|
|
3854
3901
|
"' for use with grammar '" +
|
|
3855
3902
|
grammar.name +
|
|
3856
|
-
"' (not a sub-grammar)"
|
|
3903
|
+
"' (not a sub-grammar)"
|
|
3857
3904
|
);
|
|
3858
3905
|
}
|
|
3859
3906
|
this.operations = Object.create(this.super.operations);
|
|
@@ -3862,7 +3909,7 @@ class Semantics {
|
|
|
3862
3909
|
|
|
3863
3910
|
// Assign unique symbols for each of the attributes inherited from the super-semantics so that
|
|
3864
3911
|
// they are memoized independently.
|
|
3865
|
-
|
|
3912
|
+
|
|
3866
3913
|
for (const attributeName in this.attributes) {
|
|
3867
3914
|
Object.defineProperty(this.attributeKeys, attributeName, {
|
|
3868
3915
|
value: uniqueId(attributeName),
|
|
@@ -3891,11 +3938,11 @@ class Semantics {
|
|
|
3891
3938
|
// Throws an exception if one or more of them doesn't.
|
|
3892
3939
|
checkActionDicts() {
|
|
3893
3940
|
let name;
|
|
3894
|
-
|
|
3941
|
+
|
|
3895
3942
|
for (name in this.operations) {
|
|
3896
3943
|
this.operations[name].checkActionDict(this.grammar);
|
|
3897
3944
|
}
|
|
3898
|
-
|
|
3945
|
+
|
|
3899
3946
|
for (name in this.attributes) {
|
|
3900
3947
|
this.attributes[name].checkActionDict(this.grammar);
|
|
3901
3948
|
}
|
|
@@ -3995,9 +4042,9 @@ class Semantics {
|
|
|
3995
4042
|
});
|
|
3996
4043
|
|
|
3997
4044
|
const entry =
|
|
3998
|
-
type === 'operation'
|
|
3999
|
-
new Operation(name, formals, realActionDict, builtInDefault)
|
|
4000
|
-
new Attribute(name, realActionDict, builtInDefault);
|
|
4045
|
+
type === 'operation'
|
|
4046
|
+
? new Operation(name, formals, realActionDict, builtInDefault)
|
|
4047
|
+
: new Attribute(name, realActionDict, builtInDefault);
|
|
4001
4048
|
|
|
4002
4049
|
// The following check is not strictly necessary (it will happen later anyway) but it's better
|
|
4003
4050
|
// to catch errors early.
|
|
@@ -4013,7 +4060,7 @@ class Semantics {
|
|
|
4013
4060
|
// Check that the caller passed the correct number of arguments.
|
|
4014
4061
|
if (arguments.length !== thisThing.formals.length) {
|
|
4015
4062
|
throw new Error(
|
|
4016
|
-
|
|
4063
|
+
'Invalid number of arguments passed to ' +
|
|
4017
4064
|
name +
|
|
4018
4065
|
' ' +
|
|
4019
4066
|
type +
|
|
@@ -4021,7 +4068,7 @@ class Semantics {
|
|
|
4021
4068
|
thisThing.formals.length +
|
|
4022
4069
|
', got ' +
|
|
4023
4070
|
arguments.length +
|
|
4024
|
-
')'
|
|
4071
|
+
')'
|
|
4025
4072
|
);
|
|
4026
4073
|
}
|
|
4027
4074
|
|
|
@@ -4042,7 +4089,7 @@ class Semantics {
|
|
|
4042
4089
|
|
|
4043
4090
|
if (type === 'operation') {
|
|
4044
4091
|
this.Wrapper.prototype[name] = doIt;
|
|
4045
|
-
this.Wrapper.prototype[name].toString = function() {
|
|
4092
|
+
this.Wrapper.prototype[name].toString = function () {
|
|
4046
4093
|
return '[' + name + ' operation]';
|
|
4047
4094
|
};
|
|
4048
4095
|
} else {
|
|
@@ -4064,13 +4111,13 @@ class Semantics {
|
|
|
4064
4111
|
|
|
4065
4112
|
if (!(this.super && name in this.super[typePlural])) {
|
|
4066
4113
|
throw new Error(
|
|
4067
|
-
|
|
4114
|
+
'Cannot extend ' +
|
|
4068
4115
|
type +
|
|
4069
4116
|
" '" +
|
|
4070
4117
|
name +
|
|
4071
4118
|
"': did not inherit an " +
|
|
4072
4119
|
type +
|
|
4073
|
-
' with that name'
|
|
4120
|
+
' with that name'
|
|
4074
4121
|
);
|
|
4075
4122
|
}
|
|
4076
4123
|
if (hasOwnProperty(this[typePlural], name)) {
|
|
@@ -4087,9 +4134,9 @@ class Semantics {
|
|
|
4087
4134
|
});
|
|
4088
4135
|
|
|
4089
4136
|
this[typePlural][name] =
|
|
4090
|
-
type === 'operation'
|
|
4091
|
-
new Operation(name, inheritedFormals, newActionDict)
|
|
4092
|
-
new Attribute(name, newActionDict);
|
|
4137
|
+
type === 'operation'
|
|
4138
|
+
? new Operation(name, inheritedFormals, newActionDict)
|
|
4139
|
+
: new Attribute(name, newActionDict);
|
|
4093
4140
|
|
|
4094
4141
|
// The following check is not strictly necessary (it will happen later anyway) but it's better
|
|
4095
4142
|
// to catch errors early.
|
|
@@ -4102,12 +4149,12 @@ class Semantics {
|
|
|
4102
4149
|
}
|
|
4103
4150
|
if (name in this.operations) {
|
|
4104
4151
|
throw new Error(
|
|
4105
|
-
|
|
4152
|
+
'Cannot add ' + type + " '" + name + "': an operation with that name already exists"
|
|
4106
4153
|
);
|
|
4107
4154
|
}
|
|
4108
4155
|
if (name in this.attributes) {
|
|
4109
4156
|
throw new Error(
|
|
4110
|
-
|
|
4157
|
+
'Cannot add ' + type + " '" + name + "': an attribute with that name already exists"
|
|
4111
4158
|
);
|
|
4112
4159
|
}
|
|
4113
4160
|
}
|
|
@@ -4133,8 +4180,8 @@ function parseSignature(signature, type) {
|
|
|
4133
4180
|
}
|
|
4134
4181
|
|
|
4135
4182
|
const r = Semantics.prototypeGrammar.match(
|
|
4136
|
-
|
|
4137
|
-
type === 'operation' ? 'OperationSignature' : 'AttributeSignature'
|
|
4183
|
+
signature,
|
|
4184
|
+
type === 'operation' ? 'OperationSignature' : 'AttributeSignature'
|
|
4138
4185
|
);
|
|
4139
4186
|
if (r.failed()) {
|
|
4140
4187
|
throw new Error(r.message);
|
|
@@ -4144,7 +4191,7 @@ function parseSignature(signature, type) {
|
|
|
4144
4191
|
}
|
|
4145
4192
|
|
|
4146
4193
|
function newDefaultAction(type, name, doIt) {
|
|
4147
|
-
return function(...children) {
|
|
4194
|
+
return function (...children) {
|
|
4148
4195
|
const thisThing = this._semantics.operations[name] || this._semantics.attributes[name];
|
|
4149
4196
|
const args = thisThing.formals.map(formal => this.args[formal]);
|
|
4150
4197
|
|
|
@@ -4168,12 +4215,12 @@ function newDefaultAction(type, name, doIt) {
|
|
|
4168
4215
|
// Semantics instance. When that function is invoked with a CST node as an argument, it returns
|
|
4169
4216
|
// a wrapper for that node which gives access to the operations and attributes provided by this
|
|
4170
4217
|
// semantics.
|
|
4171
|
-
Semantics.createSemantics = function(grammar, optSuperSemantics) {
|
|
4218
|
+
Semantics.createSemantics = function (grammar, optSuperSemantics) {
|
|
4172
4219
|
const s = new Semantics(
|
|
4173
|
-
|
|
4174
|
-
optSuperSemantics !== undefined
|
|
4175
|
-
optSuperSemantics
|
|
4176
|
-
Semantics.BuiltInSemantics._getSemantics()
|
|
4220
|
+
grammar,
|
|
4221
|
+
optSuperSemantics !== undefined
|
|
4222
|
+
? optSuperSemantics
|
|
4223
|
+
: Semantics.BuiltInSemantics._getSemantics()
|
|
4177
4224
|
);
|
|
4178
4225
|
|
|
4179
4226
|
// To enable clients to invoke a semantics like a function, return a function that acts as a proxy
|
|
@@ -4181,8 +4228,8 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
|
|
|
4181
4228
|
const proxy = function ASemantics(matchResult) {
|
|
4182
4229
|
if (!(matchResult instanceof MatchResult)) {
|
|
4183
4230
|
throw new TypeError(
|
|
4184
|
-
|
|
4185
|
-
unexpectedObjToString(matchResult)
|
|
4231
|
+
'Semantics expected a MatchResult, but got ' +
|
|
4232
|
+
unexpectedObjToString(matchResult)
|
|
4186
4233
|
);
|
|
4187
4234
|
}
|
|
4188
4235
|
if (matchResult.failed()) {
|
|
@@ -4192,11 +4239,11 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
|
|
|
4192
4239
|
const cst = matchResult._cst;
|
|
4193
4240
|
if (cst.grammar !== grammar) {
|
|
4194
4241
|
throw new Error(
|
|
4195
|
-
|
|
4242
|
+
"Cannot use a MatchResult from grammar '" +
|
|
4196
4243
|
cst.grammar.name +
|
|
4197
4244
|
"' with a semantics for '" +
|
|
4198
4245
|
grammar.name +
|
|
4199
|
-
"'"
|
|
4246
|
+
"'"
|
|
4200
4247
|
);
|
|
4201
4248
|
}
|
|
4202
4249
|
const inputStream = new InputStream(matchResult.input);
|
|
@@ -4204,38 +4251,38 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
|
|
|
4204
4251
|
};
|
|
4205
4252
|
|
|
4206
4253
|
// Forward public methods from the proxy to the semantics instance.
|
|
4207
|
-
proxy.addOperation = function(signature, actionDict) {
|
|
4254
|
+
proxy.addOperation = function (signature, actionDict) {
|
|
4208
4255
|
s.addOperationOrAttribute('operation', signature, actionDict);
|
|
4209
4256
|
return proxy;
|
|
4210
4257
|
};
|
|
4211
|
-
proxy.extendOperation = function(name, actionDict) {
|
|
4258
|
+
proxy.extendOperation = function (name, actionDict) {
|
|
4212
4259
|
s.extendOperationOrAttribute('operation', name, actionDict);
|
|
4213
4260
|
return proxy;
|
|
4214
4261
|
};
|
|
4215
|
-
proxy.addAttribute = function(name, actionDict) {
|
|
4262
|
+
proxy.addAttribute = function (name, actionDict) {
|
|
4216
4263
|
s.addOperationOrAttribute('attribute', name, actionDict);
|
|
4217
4264
|
return proxy;
|
|
4218
4265
|
};
|
|
4219
|
-
proxy.extendAttribute = function(name, actionDict) {
|
|
4266
|
+
proxy.extendAttribute = function (name, actionDict) {
|
|
4220
4267
|
s.extendOperationOrAttribute('attribute', name, actionDict);
|
|
4221
4268
|
return proxy;
|
|
4222
4269
|
};
|
|
4223
|
-
proxy._getActionDict = function(operationOrAttributeName) {
|
|
4270
|
+
proxy._getActionDict = function (operationOrAttributeName) {
|
|
4224
4271
|
const action =
|
|
4225
4272
|
s.operations[operationOrAttributeName] || s.attributes[operationOrAttributeName];
|
|
4226
4273
|
if (!action) {
|
|
4227
4274
|
throw new Error(
|
|
4228
|
-
|
|
4275
|
+
'"' +
|
|
4229
4276
|
operationOrAttributeName +
|
|
4230
4277
|
'" is not a valid operation or attribute ' +
|
|
4231
4278
|
'name in this semantics for "' +
|
|
4232
4279
|
grammar.name +
|
|
4233
|
-
'"'
|
|
4280
|
+
'"'
|
|
4234
4281
|
);
|
|
4235
4282
|
}
|
|
4236
4283
|
return action.actionDict;
|
|
4237
4284
|
};
|
|
4238
|
-
proxy._remove = function(operationOrAttributeName) {
|
|
4285
|
+
proxy._remove = function (operationOrAttributeName) {
|
|
4239
4286
|
let semantic;
|
|
4240
4287
|
if (operationOrAttributeName in s.operations) {
|
|
4241
4288
|
semantic = s.operations[operationOrAttributeName];
|
|
@@ -4247,16 +4294,16 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
|
|
|
4247
4294
|
delete s.Wrapper.prototype[operationOrAttributeName];
|
|
4248
4295
|
return semantic;
|
|
4249
4296
|
};
|
|
4250
|
-
proxy.getOperationNames = function() {
|
|
4297
|
+
proxy.getOperationNames = function () {
|
|
4251
4298
|
return Object.keys(s.operations);
|
|
4252
4299
|
};
|
|
4253
|
-
proxy.getAttributeNames = function() {
|
|
4300
|
+
proxy.getAttributeNames = function () {
|
|
4254
4301
|
return Object.keys(s.attributes);
|
|
4255
4302
|
};
|
|
4256
|
-
proxy.getGrammar = function() {
|
|
4303
|
+
proxy.getGrammar = function () {
|
|
4257
4304
|
return s.grammar;
|
|
4258
4305
|
};
|
|
4259
|
-
proxy.toRecipe = function(semanticsOnly) {
|
|
4306
|
+
proxy.toRecipe = function (semanticsOnly) {
|
|
4260
4307
|
return s.toRecipe(semanticsOnly);
|
|
4261
4308
|
};
|
|
4262
4309
|
|
|
@@ -4264,7 +4311,7 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
|
|
|
4264
4311
|
proxy.toString = s.toString.bind(s);
|
|
4265
4312
|
|
|
4266
4313
|
// Returns the semantics for the proxy.
|
|
4267
|
-
proxy._getSemantics = function() {
|
|
4314
|
+
proxy._getSemantics = function () {
|
|
4268
4315
|
return s;
|
|
4269
4316
|
};
|
|
4270
4317
|
|
|
@@ -4356,8 +4403,8 @@ const SPECIAL_ACTION_NAMES = ['_iter', '_terminal', '_nonterminal', '_default'];
|
|
|
4356
4403
|
|
|
4357
4404
|
function getSortedRuleValues(grammar) {
|
|
4358
4405
|
return Object.keys(grammar.rules)
|
|
4359
|
-
|
|
4360
|
-
|
|
4406
|
+
.sort()
|
|
4407
|
+
.map(name => grammar.rules[name]);
|
|
4361
4408
|
}
|
|
4362
4409
|
|
|
4363
4410
|
// Until ES2019, JSON was not a valid subset of JavaScript because U+2028 (line separator)
|
|
@@ -4378,11 +4425,11 @@ class Grammar {
|
|
|
4378
4425
|
if (optDefaultStartRule) {
|
|
4379
4426
|
if (!(optDefaultStartRule in rules)) {
|
|
4380
4427
|
throw new Error(
|
|
4381
|
-
|
|
4428
|
+
"Invalid start rule: '" +
|
|
4382
4429
|
optDefaultStartRule +
|
|
4383
4430
|
"' is not a rule in grammar '" +
|
|
4384
4431
|
name +
|
|
4385
|
-
"'"
|
|
4432
|
+
"'"
|
|
4386
4433
|
);
|
|
4387
4434
|
}
|
|
4388
4435
|
this.defaultStartRule = optDefaultStartRule;
|
|
@@ -4453,7 +4500,6 @@ class Grammar {
|
|
|
4453
4500
|
_checkTopDownActionDict(what, name, actionDict) {
|
|
4454
4501
|
const problems = [];
|
|
4455
4502
|
|
|
4456
|
-
// eslint-disable-next-line guard-for-in
|
|
4457
4503
|
for (const k in actionDict) {
|
|
4458
4504
|
const v = actionDict[k];
|
|
4459
4505
|
const isSpecialAction = SPECIAL_ACTION_NAMES.includes(k);
|
|
@@ -4483,10 +4529,10 @@ class Grammar {
|
|
|
4483
4529
|
if (problems.length > 0) {
|
|
4484
4530
|
const prettyProblems = problems.map(problem => '- ' + problem);
|
|
4485
4531
|
const error = new Error(
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4532
|
+
[
|
|
4533
|
+
`Found errors in the action dictionary of the '${name}' ${what}:`,
|
|
4534
|
+
...prettyProblems,
|
|
4535
|
+
].join('\n')
|
|
4490
4536
|
);
|
|
4491
4537
|
error.problems = problems;
|
|
4492
4538
|
throw error;
|
|
@@ -4499,9 +4545,9 @@ class Grammar {
|
|
|
4499
4545
|
// All special actions have an expected arity of 0, though all but _terminal
|
|
4500
4546
|
// are expected to use the rest parameter syntax (e.g. `_iter(...children)`).
|
|
4501
4547
|
// 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();
|
|
4548
|
+
return SPECIAL_ACTION_NAMES.includes(actionName)
|
|
4549
|
+
? 0
|
|
4550
|
+
: this.rules[actionName].body.getArity();
|
|
4505
4551
|
}
|
|
4506
4552
|
|
|
4507
4553
|
_inheritsFrom(grammar) {
|
|
@@ -4592,7 +4638,7 @@ class Grammar {
|
|
|
4592
4638
|
sb.append('{');
|
|
4593
4639
|
|
|
4594
4640
|
let first = true;
|
|
4595
|
-
|
|
4641
|
+
|
|
4596
4642
|
for (const ruleName in this.rules) {
|
|
4597
4643
|
const {body} = this.rules[ruleName];
|
|
4598
4644
|
if (first) {
|
|
@@ -4639,10 +4685,10 @@ class Grammar {
|
|
|
4639
4685
|
if (formals.length !== app.args.length) {
|
|
4640
4686
|
const {source} = this.rules[app.ruleName];
|
|
4641
4687
|
throw wrongNumberOfParameters(
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4688
|
+
app.ruleName,
|
|
4689
|
+
formals.length,
|
|
4690
|
+
app.args.length,
|
|
4691
|
+
source
|
|
4646
4692
|
);
|
|
4647
4693
|
}
|
|
4648
4694
|
return app;
|
|
@@ -4661,63 +4707,63 @@ class Grammar {
|
|
|
4661
4707
|
// `digit`, and is implicitly the super-grammar of any grammar whose super-grammar
|
|
4662
4708
|
// isn't specified.
|
|
4663
4709
|
Grammar.ProtoBuiltInRules = new Grammar(
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
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
|
-
},
|
|
4710
|
+
'ProtoBuiltInRules', // name
|
|
4711
|
+
undefined, // supergrammar
|
|
4712
|
+
{
|
|
4713
|
+
any: {
|
|
4714
|
+
body: any,
|
|
4715
|
+
formals: [],
|
|
4716
|
+
description: 'any character',
|
|
4717
|
+
primitive: true,
|
|
4716
4718
|
},
|
|
4719
|
+
end: {
|
|
4720
|
+
body: end,
|
|
4721
|
+
formals: [],
|
|
4722
|
+
description: 'end of input',
|
|
4723
|
+
primitive: true,
|
|
4724
|
+
},
|
|
4725
|
+
|
|
4726
|
+
caseInsensitive: {
|
|
4727
|
+
body: new CaseInsensitiveTerminal(new Param(0)),
|
|
4728
|
+
formals: ['str'],
|
|
4729
|
+
primitive: true,
|
|
4730
|
+
},
|
|
4731
|
+
lower: {
|
|
4732
|
+
body: new UnicodeChar('Ll'),
|
|
4733
|
+
formals: [],
|
|
4734
|
+
description: 'a lowercase letter',
|
|
4735
|
+
primitive: true,
|
|
4736
|
+
},
|
|
4737
|
+
upper: {
|
|
4738
|
+
body: new UnicodeChar('Lu'),
|
|
4739
|
+
formals: [],
|
|
4740
|
+
description: 'an uppercase letter',
|
|
4741
|
+
primitive: true,
|
|
4742
|
+
},
|
|
4743
|
+
// Union of Lt (titlecase), Lm (modifier), and Lo (other), i.e. any letter not in Ll or Lu.
|
|
4744
|
+
unicodeLtmo: {
|
|
4745
|
+
body: new UnicodeChar('Ltmo'),
|
|
4746
|
+
formals: [],
|
|
4747
|
+
description: 'a Unicode character in Lt, Lm, or Lo',
|
|
4748
|
+
primitive: true,
|
|
4749
|
+
},
|
|
4750
|
+
|
|
4751
|
+
// These rules are not truly primitive (they could be written in userland) but are defined
|
|
4752
|
+
// here for bootstrapping purposes.
|
|
4753
|
+
spaces: {
|
|
4754
|
+
body: new Star(new Apply('space')),
|
|
4755
|
+
formals: [],
|
|
4756
|
+
},
|
|
4757
|
+
space: {
|
|
4758
|
+
body: new Range('\x00', ' '),
|
|
4759
|
+
formals: [],
|
|
4760
|
+
description: 'a space',
|
|
4761
|
+
},
|
|
4762
|
+
}
|
|
4717
4763
|
);
|
|
4718
4764
|
|
|
4719
4765
|
// This method is called from main.js once Ohm has loaded.
|
|
4720
|
-
Grammar.initApplicationParser = function(grammar, builderFn) {
|
|
4766
|
+
Grammar.initApplicationParser = function (grammar, builderFn) {
|
|
4721
4767
|
ohmGrammar$1 = grammar;
|
|
4722
4768
|
buildGrammar$1 = builderFn;
|
|
4723
4769
|
};
|
|
@@ -4745,7 +4791,7 @@ class GrammarDecl {
|
|
|
4745
4791
|
// TODO: The conditional expression below is an ugly hack. It's kind of ok because
|
|
4746
4792
|
// I doubt anyone will ever try to declare a grammar called `BuiltInRules`. Still,
|
|
4747
4793
|
// we should try to find a better way to do this.
|
|
4748
|
-
this.name === 'BuiltInRules' ? Grammar.ProtoBuiltInRules : Grammar.BuiltInRules
|
|
4794
|
+
this.name === 'BuiltInRules' ? Grammar.ProtoBuiltInRules : Grammar.BuiltInRules
|
|
4749
4795
|
);
|
|
4750
4796
|
}
|
|
4751
4797
|
return this.superGrammar;
|
|
@@ -4813,10 +4859,10 @@ class GrammarDecl {
|
|
|
4813
4859
|
// Creates a Grammar instance, and if it passes the sanity checks, returns it.
|
|
4814
4860
|
build() {
|
|
4815
4861
|
const grammar = new Grammar(
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4862
|
+
this.name,
|
|
4863
|
+
this.ensureSuperGrammar(),
|
|
4864
|
+
this.rules,
|
|
4865
|
+
this.defaultStartRule
|
|
4820
4866
|
);
|
|
4821
4867
|
// Initialize internal props that are inherited from the super grammar.
|
|
4822
4868
|
grammar._matchStateInitializer = grammar.superGrammar._matchStateInitializer;
|
|
@@ -4917,7 +4963,7 @@ class Builder {
|
|
|
4917
4963
|
if (superGrammar) {
|
|
4918
4964
|
// `superGrammar` may be a recipe (i.e. an Array), or an actual grammar instance.
|
|
4919
4965
|
gDecl.withSuperGrammar(
|
|
4920
|
-
superGrammar instanceof Grammar ? superGrammar : this.fromRecipe(superGrammar)
|
|
4966
|
+
superGrammar instanceof Grammar ? superGrammar : this.fromRecipe(superGrammar)
|
|
4921
4967
|
);
|
|
4922
4968
|
}
|
|
4923
4969
|
if (defaultStartRule) {
|
|
@@ -4941,8 +4987,8 @@ class Builder {
|
|
|
4941
4987
|
let source;
|
|
4942
4988
|
if (gDecl.source && metaInfo && metaInfo.sourceInterval) {
|
|
4943
4989
|
source = gDecl.source.subInterval(
|
|
4944
|
-
|
|
4945
|
-
|
|
4990
|
+
metaInfo.sourceInterval[0],
|
|
4991
|
+
metaInfo.sourceInterval[1] - metaInfo.sourceInterval[0]
|
|
4946
4992
|
);
|
|
4947
4993
|
}
|
|
4948
4994
|
gDecl[action](ruleName, formals, body, description, source);
|
|
@@ -5037,7 +5083,7 @@ class Builder {
|
|
|
5037
5083
|
|
|
5038
5084
|
app(ruleName, optParams) {
|
|
5039
5085
|
if (optParams && optParams.length > 0) {
|
|
5040
|
-
optParams = optParams.map(function(param) {
|
|
5086
|
+
optParams = optParams.map(function (param) {
|
|
5041
5087
|
return param instanceof PExpr ? param : this.fromRecipe(param);
|
|
5042
5088
|
}, this);
|
|
5043
5089
|
}
|
|
@@ -5049,10 +5095,10 @@ class Builder {
|
|
|
5049
5095
|
// `this.currentDecl` and `this.currentRuleName` being set.
|
|
5050
5096
|
splice(beforeTerms, afterTerms) {
|
|
5051
5097
|
return new Splice(
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5098
|
+
this.currentDecl.superGrammar,
|
|
5099
|
+
this.currentRuleName,
|
|
5100
|
+
beforeTerms.map(term => this.fromRecipe(term)),
|
|
5101
|
+
afterTerms.map(term => this.fromRecipe(term))
|
|
5056
5102
|
);
|
|
5057
5103
|
}
|
|
5058
5104
|
|
|
@@ -5193,10 +5239,10 @@ function buildGrammar(match, namespace, optOhmGrammarForTesting) {
|
|
|
5193
5239
|
});
|
|
5194
5240
|
|
|
5195
5241
|
return new Splice(
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5242
|
+
decl.superGrammar,
|
|
5243
|
+
currentRuleName,
|
|
5244
|
+
beforeTerms,
|
|
5245
|
+
afterTerms
|
|
5200
5246
|
).withSource(this.source);
|
|
5201
5247
|
} else {
|
|
5202
5248
|
return builder.alt(...args).withSource(this.source);
|
|
@@ -5341,14 +5387,14 @@ function initBuiltInSemantics(builtInRules) {
|
|
|
5341
5387
|
};
|
|
5342
5388
|
|
|
5343
5389
|
Semantics.BuiltInSemantics = Semantics.createSemantics(builtInRules, null).addOperation(
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5390
|
+
'asIteration',
|
|
5391
|
+
{
|
|
5392
|
+
emptyListOf: actions.empty,
|
|
5393
|
+
nonemptyListOf: actions.nonEmpty,
|
|
5394
|
+
EmptyListOf: actions.empty,
|
|
5395
|
+
NonemptyListOf: actions.nonEmpty,
|
|
5396
|
+
_iter: actions.self,
|
|
5397
|
+
}
|
|
5352
5398
|
);
|
|
5353
5399
|
}
|
|
5354
5400
|
|
|
@@ -5537,12 +5583,12 @@ const applyDedent = new Apply('dedent');
|
|
|
5537
5583
|
const newAnyBody = new Splice(BuiltInRules, 'any', [applyIndent, applyDedent], []);
|
|
5538
5584
|
|
|
5539
5585
|
const IndentationSensitive = new Builder()
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5586
|
+
.newGrammar('IndentationSensitive')
|
|
5587
|
+
.withSuperGrammar(BuiltInRules)
|
|
5588
|
+
.define('indent', [], new Indentation(true), INDENT_DESCRIPTION, undefined, true)
|
|
5589
|
+
.define('dedent', [], new Indentation(false), DEDENT_DESCRIPTION, undefined, true)
|
|
5590
|
+
.extend('any', [], newAnyBody, 'any character', undefined)
|
|
5591
|
+
.build();
|
|
5546
5592
|
|
|
5547
5593
|
Object.assign(IndentationSensitive, {
|
|
5548
5594
|
_matchStateInitializer(state) {
|
|
@@ -5553,7 +5599,7 @@ Object.assign(IndentationSensitive, {
|
|
|
5553
5599
|
});
|
|
5554
5600
|
|
|
5555
5601
|
// Generated by scripts/prebuild.js
|
|
5556
|
-
const version = '17.
|
|
5602
|
+
const version = '17.3.0';
|
|
5557
5603
|
|
|
5558
5604
|
Grammar.initApplicationParser(ohmGrammar, buildGrammar);
|
|
5559
5605
|
|
|
@@ -5581,8 +5627,8 @@ function grammar(source, optNamespace) {
|
|
|
5581
5627
|
const secondGrammar = ns[grammarNames[1]];
|
|
5582
5628
|
const interval = secondGrammar.source;
|
|
5583
5629
|
throw new Error(
|
|
5584
|
-
|
|
5585
|
-
'Found more than one grammar definition -- use ohm.grammars() instead.'
|
|
5630
|
+
getLineAndColumnMessage(interval.sourceString, interval.startIdx) +
|
|
5631
|
+
'Found more than one grammar definition -- use ohm.grammars() instead.'
|
|
5586
5632
|
);
|
|
5587
5633
|
}
|
|
5588
5634
|
return ns[grammarNames[0]]; // Return the one and only grammar.
|
|
@@ -5596,7 +5642,7 @@ function grammars(source, optNamespace) {
|
|
|
5596
5642
|
source = source.toString();
|
|
5597
5643
|
} else {
|
|
5598
5644
|
throw new TypeError(
|
|
5599
|
-
|
|
5645
|
+
'Expected string as first argument, got ' + unexpectedObjToString(source)
|
|
5600
5646
|
);
|
|
5601
5647
|
}
|
|
5602
5648
|
}
|