ohm-js 17.2.1 → 17.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ohm-extras.cjs +568 -471
- package/dist/ohm-extras.js +568 -471
- package/dist/ohm.cjs +511 -464
- package/dist/ohm.cjs.map +1 -1
- package/dist/ohm.js +512 -465
- package/dist/ohm.min.js +1 -1
- package/extras/VisitorFamily.js +9 -9
- package/extras/index.d.ts +7 -11
- package/extras/index.mjs +1 -0
- package/extras/recoverSourceOrder.js +48 -0
- 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 +40 -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/src/PosInfo.js
CHANGED
|
@@ -29,14 +29,14 @@ export class PosInfo {
|
|
|
29
29
|
const indexOfFirstInvolvedRule =
|
|
30
30
|
applicationMemoKeyStack.indexOf(headApplication.toMemoKey()) + 1;
|
|
31
31
|
const involvedApplicationMemoKeys = applicationMemoKeyStack.slice(
|
|
32
|
-
|
|
32
|
+
indexOfFirstInvolvedRule
|
|
33
33
|
);
|
|
34
34
|
|
|
35
|
-
memoRec.isInvolved = function(applicationMemoKey) {
|
|
35
|
+
memoRec.isInvolved = function (applicationMemoKey) {
|
|
36
36
|
return involvedApplicationMemoKeys.indexOf(applicationMemoKey) >= 0;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
memoRec.updateInvolvedApplicationMemoKeys = function() {
|
|
39
|
+
memoRec.updateInvolvedApplicationMemoKeys = function () {
|
|
40
40
|
for (let idx = indexOfFirstInvolvedRule; idx < applicationMemoKeyStack.length; idx++) {
|
|
41
41
|
const applicationMemoKey = applicationMemoKeyStack[idx];
|
|
42
42
|
if (!this.isInvolved(applicationMemoKey)) {
|
|
@@ -70,8 +70,8 @@ export class PosInfo {
|
|
|
70
70
|
this.memo[memoKey] = memoRec;
|
|
71
71
|
this.maxExaminedLength = Math.max(this.maxExaminedLength, memoRec.examinedLength);
|
|
72
72
|
this.maxRightmostFailureOffset = Math.max(
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
this.maxRightmostFailureOffset,
|
|
74
|
+
memoRec.rightmostFailureOffset
|
|
75
75
|
);
|
|
76
76
|
return memoRec;
|
|
77
77
|
}
|
|
@@ -93,8 +93,8 @@ export class PosInfo {
|
|
|
93
93
|
} else {
|
|
94
94
|
this.maxExaminedLength = Math.max(this.maxExaminedLength, memoRec.examinedLength);
|
|
95
95
|
this.maxRightmostFailureOffset = Math.max(
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
this.maxRightmostFailureOffset,
|
|
97
|
+
memoRec.rightmostFailureOffset
|
|
98
98
|
);
|
|
99
99
|
}
|
|
100
100
|
});
|
package/src/Semantics.js
CHANGED
|
@@ -179,11 +179,11 @@ export class Semantics {
|
|
|
179
179
|
if (superSemantics) {
|
|
180
180
|
if (!(grammar.equals(this.super.grammar) || grammar._inheritsFrom(this.super.grammar))) {
|
|
181
181
|
throw new Error(
|
|
182
|
-
|
|
182
|
+
"Cannot extend a semantics for grammar '" +
|
|
183
183
|
this.super.grammar.name +
|
|
184
184
|
"' for use with grammar '" +
|
|
185
185
|
grammar.name +
|
|
186
|
-
"' (not a sub-grammar)"
|
|
186
|
+
"' (not a sub-grammar)"
|
|
187
187
|
);
|
|
188
188
|
}
|
|
189
189
|
this.operations = Object.create(this.super.operations);
|
|
@@ -192,7 +192,7 @@ export class Semantics {
|
|
|
192
192
|
|
|
193
193
|
// Assign unique symbols for each of the attributes inherited from the super-semantics so that
|
|
194
194
|
// they are memoized independently.
|
|
195
|
-
|
|
195
|
+
|
|
196
196
|
for (const attributeName in this.attributes) {
|
|
197
197
|
Object.defineProperty(this.attributeKeys, attributeName, {
|
|
198
198
|
value: util.uniqueId(attributeName),
|
|
@@ -221,11 +221,11 @@ export class Semantics {
|
|
|
221
221
|
// Throws an exception if one or more of them doesn't.
|
|
222
222
|
checkActionDicts() {
|
|
223
223
|
let name;
|
|
224
|
-
|
|
224
|
+
|
|
225
225
|
for (name in this.operations) {
|
|
226
226
|
this.operations[name].checkActionDict(this.grammar);
|
|
227
227
|
}
|
|
228
|
-
|
|
228
|
+
|
|
229
229
|
for (name in this.attributes) {
|
|
230
230
|
this.attributes[name].checkActionDict(this.grammar);
|
|
231
231
|
}
|
|
@@ -325,9 +325,9 @@ export class Semantics {
|
|
|
325
325
|
});
|
|
326
326
|
|
|
327
327
|
const entry =
|
|
328
|
-
type === 'operation'
|
|
329
|
-
new Operation(name, formals, realActionDict, builtInDefault)
|
|
330
|
-
new Attribute(name, realActionDict, builtInDefault);
|
|
328
|
+
type === 'operation'
|
|
329
|
+
? new Operation(name, formals, realActionDict, builtInDefault)
|
|
330
|
+
: new Attribute(name, realActionDict, builtInDefault);
|
|
331
331
|
|
|
332
332
|
// The following check is not strictly necessary (it will happen later anyway) but it's better
|
|
333
333
|
// to catch errors early.
|
|
@@ -343,7 +343,7 @@ export class Semantics {
|
|
|
343
343
|
// Check that the caller passed the correct number of arguments.
|
|
344
344
|
if (arguments.length !== thisThing.formals.length) {
|
|
345
345
|
throw new Error(
|
|
346
|
-
|
|
346
|
+
'Invalid number of arguments passed to ' +
|
|
347
347
|
name +
|
|
348
348
|
' ' +
|
|
349
349
|
type +
|
|
@@ -351,7 +351,7 @@ export class Semantics {
|
|
|
351
351
|
thisThing.formals.length +
|
|
352
352
|
', got ' +
|
|
353
353
|
arguments.length +
|
|
354
|
-
')'
|
|
354
|
+
')'
|
|
355
355
|
);
|
|
356
356
|
}
|
|
357
357
|
|
|
@@ -372,7 +372,7 @@ export class Semantics {
|
|
|
372
372
|
|
|
373
373
|
if (type === 'operation') {
|
|
374
374
|
this.Wrapper.prototype[name] = doIt;
|
|
375
|
-
this.Wrapper.prototype[name].toString = function() {
|
|
375
|
+
this.Wrapper.prototype[name].toString = function () {
|
|
376
376
|
return '[' + name + ' operation]';
|
|
377
377
|
};
|
|
378
378
|
} else {
|
|
@@ -394,13 +394,13 @@ export class Semantics {
|
|
|
394
394
|
|
|
395
395
|
if (!(this.super && name in this.super[typePlural])) {
|
|
396
396
|
throw new Error(
|
|
397
|
-
|
|
397
|
+
'Cannot extend ' +
|
|
398
398
|
type +
|
|
399
399
|
" '" +
|
|
400
400
|
name +
|
|
401
401
|
"': did not inherit an " +
|
|
402
402
|
type +
|
|
403
|
-
' with that name'
|
|
403
|
+
' with that name'
|
|
404
404
|
);
|
|
405
405
|
}
|
|
406
406
|
if (hasOwnProperty(this[typePlural], name)) {
|
|
@@ -417,9 +417,9 @@ export class Semantics {
|
|
|
417
417
|
});
|
|
418
418
|
|
|
419
419
|
this[typePlural][name] =
|
|
420
|
-
type === 'operation'
|
|
421
|
-
new Operation(name, inheritedFormals, newActionDict)
|
|
422
|
-
new Attribute(name, newActionDict);
|
|
420
|
+
type === 'operation'
|
|
421
|
+
? new Operation(name, inheritedFormals, newActionDict)
|
|
422
|
+
: new Attribute(name, newActionDict);
|
|
423
423
|
|
|
424
424
|
// The following check is not strictly necessary (it will happen later anyway) but it's better
|
|
425
425
|
// to catch errors early.
|
|
@@ -432,12 +432,12 @@ export class Semantics {
|
|
|
432
432
|
}
|
|
433
433
|
if (name in this.operations) {
|
|
434
434
|
throw new Error(
|
|
435
|
-
|
|
435
|
+
'Cannot add ' + type + " '" + name + "': an operation with that name already exists"
|
|
436
436
|
);
|
|
437
437
|
}
|
|
438
438
|
if (name in this.attributes) {
|
|
439
439
|
throw new Error(
|
|
440
|
-
|
|
440
|
+
'Cannot add ' + type + " '" + name + "': an attribute with that name already exists"
|
|
441
441
|
);
|
|
442
442
|
}
|
|
443
443
|
}
|
|
@@ -463,8 +463,8 @@ function parseSignature(signature, type) {
|
|
|
463
463
|
}
|
|
464
464
|
|
|
465
465
|
const r = Semantics.prototypeGrammar.match(
|
|
466
|
-
|
|
467
|
-
type === 'operation' ? 'OperationSignature' : 'AttributeSignature'
|
|
466
|
+
signature,
|
|
467
|
+
type === 'operation' ? 'OperationSignature' : 'AttributeSignature'
|
|
468
468
|
);
|
|
469
469
|
if (r.failed()) {
|
|
470
470
|
throw new Error(r.message);
|
|
@@ -474,7 +474,7 @@ function parseSignature(signature, type) {
|
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
function newDefaultAction(type, name, doIt) {
|
|
477
|
-
return function(...children) {
|
|
477
|
+
return function (...children) {
|
|
478
478
|
const thisThing = this._semantics.operations[name] || this._semantics.attributes[name];
|
|
479
479
|
const args = thisThing.formals.map(formal => this.args[formal]);
|
|
480
480
|
|
|
@@ -498,12 +498,12 @@ function newDefaultAction(type, name, doIt) {
|
|
|
498
498
|
// Semantics instance. When that function is invoked with a CST node as an argument, it returns
|
|
499
499
|
// a wrapper for that node which gives access to the operations and attributes provided by this
|
|
500
500
|
// semantics.
|
|
501
|
-
Semantics.createSemantics = function(grammar, optSuperSemantics) {
|
|
501
|
+
Semantics.createSemantics = function (grammar, optSuperSemantics) {
|
|
502
502
|
const s = new Semantics(
|
|
503
|
-
|
|
504
|
-
optSuperSemantics !== undefined
|
|
505
|
-
optSuperSemantics
|
|
506
|
-
Semantics.BuiltInSemantics._getSemantics()
|
|
503
|
+
grammar,
|
|
504
|
+
optSuperSemantics !== undefined
|
|
505
|
+
? optSuperSemantics
|
|
506
|
+
: Semantics.BuiltInSemantics._getSemantics()
|
|
507
507
|
);
|
|
508
508
|
|
|
509
509
|
// To enable clients to invoke a semantics like a function, return a function that acts as a proxy
|
|
@@ -511,8 +511,8 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
|
|
|
511
511
|
const proxy = function ASemantics(matchResult) {
|
|
512
512
|
if (!(matchResult instanceof MatchResult)) {
|
|
513
513
|
throw new TypeError(
|
|
514
|
-
|
|
515
|
-
common.unexpectedObjToString(matchResult)
|
|
514
|
+
'Semantics expected a MatchResult, but got ' +
|
|
515
|
+
common.unexpectedObjToString(matchResult)
|
|
516
516
|
);
|
|
517
517
|
}
|
|
518
518
|
if (matchResult.failed()) {
|
|
@@ -522,11 +522,11 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
|
|
|
522
522
|
const cst = matchResult._cst;
|
|
523
523
|
if (cst.grammar !== grammar) {
|
|
524
524
|
throw new Error(
|
|
525
|
-
|
|
525
|
+
"Cannot use a MatchResult from grammar '" +
|
|
526
526
|
cst.grammar.name +
|
|
527
527
|
"' with a semantics for '" +
|
|
528
528
|
grammar.name +
|
|
529
|
-
"'"
|
|
529
|
+
"'"
|
|
530
530
|
);
|
|
531
531
|
}
|
|
532
532
|
const inputStream = new InputStream(matchResult.input);
|
|
@@ -534,38 +534,38 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
|
|
|
534
534
|
};
|
|
535
535
|
|
|
536
536
|
// Forward public methods from the proxy to the semantics instance.
|
|
537
|
-
proxy.addOperation = function(signature, actionDict) {
|
|
537
|
+
proxy.addOperation = function (signature, actionDict) {
|
|
538
538
|
s.addOperationOrAttribute('operation', signature, actionDict);
|
|
539
539
|
return proxy;
|
|
540
540
|
};
|
|
541
|
-
proxy.extendOperation = function(name, actionDict) {
|
|
541
|
+
proxy.extendOperation = function (name, actionDict) {
|
|
542
542
|
s.extendOperationOrAttribute('operation', name, actionDict);
|
|
543
543
|
return proxy;
|
|
544
544
|
};
|
|
545
|
-
proxy.addAttribute = function(name, actionDict) {
|
|
545
|
+
proxy.addAttribute = function (name, actionDict) {
|
|
546
546
|
s.addOperationOrAttribute('attribute', name, actionDict);
|
|
547
547
|
return proxy;
|
|
548
548
|
};
|
|
549
|
-
proxy.extendAttribute = function(name, actionDict) {
|
|
549
|
+
proxy.extendAttribute = function (name, actionDict) {
|
|
550
550
|
s.extendOperationOrAttribute('attribute', name, actionDict);
|
|
551
551
|
return proxy;
|
|
552
552
|
};
|
|
553
|
-
proxy._getActionDict = function(operationOrAttributeName) {
|
|
553
|
+
proxy._getActionDict = function (operationOrAttributeName) {
|
|
554
554
|
const action =
|
|
555
555
|
s.operations[operationOrAttributeName] || s.attributes[operationOrAttributeName];
|
|
556
556
|
if (!action) {
|
|
557
557
|
throw new Error(
|
|
558
|
-
|
|
558
|
+
'"' +
|
|
559
559
|
operationOrAttributeName +
|
|
560
560
|
'" is not a valid operation or attribute ' +
|
|
561
561
|
'name in this semantics for "' +
|
|
562
562
|
grammar.name +
|
|
563
|
-
'"'
|
|
563
|
+
'"'
|
|
564
564
|
);
|
|
565
565
|
}
|
|
566
566
|
return action.actionDict;
|
|
567
567
|
};
|
|
568
|
-
proxy._remove = function(operationOrAttributeName) {
|
|
568
|
+
proxy._remove = function (operationOrAttributeName) {
|
|
569
569
|
let semantic;
|
|
570
570
|
if (operationOrAttributeName in s.operations) {
|
|
571
571
|
semantic = s.operations[operationOrAttributeName];
|
|
@@ -577,16 +577,16 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
|
|
|
577
577
|
delete s.Wrapper.prototype[operationOrAttributeName];
|
|
578
578
|
return semantic;
|
|
579
579
|
};
|
|
580
|
-
proxy.getOperationNames = function() {
|
|
580
|
+
proxy.getOperationNames = function () {
|
|
581
581
|
return Object.keys(s.operations);
|
|
582
582
|
};
|
|
583
|
-
proxy.getAttributeNames = function() {
|
|
583
|
+
proxy.getAttributeNames = function () {
|
|
584
584
|
return Object.keys(s.attributes);
|
|
585
585
|
};
|
|
586
|
-
proxy.getGrammar = function() {
|
|
586
|
+
proxy.getGrammar = function () {
|
|
587
587
|
return s.grammar;
|
|
588
588
|
};
|
|
589
|
-
proxy.toRecipe = function(semanticsOnly) {
|
|
589
|
+
proxy.toRecipe = function (semanticsOnly) {
|
|
590
590
|
return s.toRecipe(semanticsOnly);
|
|
591
591
|
};
|
|
592
592
|
|
|
@@ -594,7 +594,7 @@ Semantics.createSemantics = function(grammar, optSuperSemantics) {
|
|
|
594
594
|
proxy.toString = s.toString.bind(s);
|
|
595
595
|
|
|
596
596
|
// Returns the semantics for the proxy.
|
|
597
|
-
proxy._getSemantics = function() {
|
|
597
|
+
proxy._getSemantics = function () {
|
|
598
598
|
return s;
|
|
599
599
|
};
|
|
600
600
|
|
package/src/Trace.js
CHANGED
|
@@ -43,10 +43,10 @@ function asEscapedString(obj) {
|
|
|
43
43
|
if (typeof obj === 'string') {
|
|
44
44
|
// Replace non-printable characters with visible symbols.
|
|
45
45
|
return obj
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
.replace(/ /g, DOT_OPERATOR)
|
|
47
|
+
.replace(/\t/g, SYMBOL_FOR_HORIZONTAL_TABULATION)
|
|
48
|
+
.replace(/\n/g, SYMBOL_FOR_LINE_FEED)
|
|
49
|
+
.replace(/\r/g, SYMBOL_FOR_CARRIAGE_RETURN);
|
|
50
50
|
}
|
|
51
51
|
return String(obj);
|
|
52
52
|
}
|
|
@@ -77,13 +77,13 @@ export class Trace {
|
|
|
77
77
|
|
|
78
78
|
cloneWithExpr(expr) {
|
|
79
79
|
const ans = new Trace(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
this.input,
|
|
81
|
+
this.pos,
|
|
82
|
+
this.pos2,
|
|
83
|
+
expr,
|
|
84
|
+
this.succeeded,
|
|
85
|
+
this.bindings,
|
|
86
|
+
this.children
|
|
87
87
|
);
|
|
88
88
|
|
|
89
89
|
ans.isHeadOfLeftRecursion = this.isHeadOfLeftRecursion;
|
|
@@ -98,13 +98,13 @@ export class Trace {
|
|
|
98
98
|
// Record the trace information for the terminating condition of the LR loop.
|
|
99
99
|
recordLRTermination(ruleBodyTrace, value) {
|
|
100
100
|
this.terminatingLREntry = new Trace(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
101
|
+
this.input,
|
|
102
|
+
this.pos,
|
|
103
|
+
this.pos2,
|
|
104
|
+
this.expr,
|
|
105
|
+
false,
|
|
106
|
+
[value],
|
|
107
|
+
[ruleBodyTrace]
|
|
108
108
|
);
|
|
109
109
|
this.terminatingLREntry.terminatesLR = true;
|
|
110
110
|
}
|
|
@@ -164,7 +164,7 @@ export class Trace {
|
|
|
164
164
|
const ctorName = node.expr.constructor.name;
|
|
165
165
|
// Don't print anything for Alt nodes.
|
|
166
166
|
if (ctorName === 'Alt') {
|
|
167
|
-
return;
|
|
167
|
+
return;
|
|
168
168
|
}
|
|
169
169
|
sb.append(getInputExcerpt(node.input, node.pos, 10) + spaces(depth * 2 + 1));
|
|
170
170
|
sb.append((node.succeeded ? CHECK_MARK : BALLOT_X) + ' ' + node.displayString);
|
package/src/buildGrammar.js
CHANGED
|
@@ -108,10 +108,10 @@ export function buildGrammar(match, namespace, optOhmGrammarForTesting) {
|
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
return new pexprs.Splice(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
decl.superGrammar,
|
|
112
|
+
currentRuleName,
|
|
113
|
+
beforeTerms,
|
|
114
|
+
afterTerms
|
|
115
115
|
).withSource(this.source);
|
|
116
116
|
} else {
|
|
117
117
|
return builder.alt(...args).withSource(this.source);
|
package/src/common.js
CHANGED
|
@@ -24,14 +24,14 @@ escapeStringFor['\u000b'.charCodeAt(0)] = '\\v';
|
|
|
24
24
|
|
|
25
25
|
export function abstract(optMethodName) {
|
|
26
26
|
const methodName = optMethodName || '';
|
|
27
|
-
return function() {
|
|
27
|
+
return function () {
|
|
28
28
|
throw new Error(
|
|
29
|
-
|
|
29
|
+
'this method ' +
|
|
30
30
|
methodName +
|
|
31
31
|
' is abstract! ' +
|
|
32
32
|
'(it has no implementation in class ' +
|
|
33
33
|
this.constructor.name +
|
|
34
|
-
')'
|
|
34
|
+
')'
|
|
35
35
|
);
|
|
36
36
|
};
|
|
37
37
|
}
|
|
@@ -124,11 +124,11 @@ export function StringBuffer() {
|
|
|
124
124
|
this.strings = [];
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
StringBuffer.prototype.append = function(str) {
|
|
127
|
+
StringBuffer.prototype.append = function (str) {
|
|
128
128
|
this.strings.push(str);
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
-
StringBuffer.prototype.contents = function() {
|
|
131
|
+
StringBuffer.prototype.contents = function () {
|
|
132
132
|
return this.strings.join('');
|
|
133
133
|
};
|
|
134
134
|
|
|
@@ -152,9 +152,9 @@ export function unescapeCodePoint(s) {
|
|
|
152
152
|
case 'x':
|
|
153
153
|
return escapeUnicode(s.slice(2, 4));
|
|
154
154
|
case 'u':
|
|
155
|
-
return s.charAt(2) === '{'
|
|
156
|
-
escapeUnicode(s.slice(3, -1))
|
|
157
|
-
escapeUnicode(s.slice(2, 6));
|
|
155
|
+
return s.charAt(2) === '{'
|
|
156
|
+
? escapeUnicode(s.slice(3, -1))
|
|
157
|
+
: escapeUnicode(s.slice(2, 6));
|
|
158
158
|
default:
|
|
159
159
|
return s.charAt(1);
|
|
160
160
|
}
|
|
@@ -180,7 +180,7 @@ export function unexpectedObjToString(obj) {
|
|
|
180
180
|
typeName = typeof obj;
|
|
181
181
|
}
|
|
182
182
|
return typeName + ': ' + JSON.stringify(String(obj));
|
|
183
|
-
} catch
|
|
183
|
+
} catch {
|
|
184
184
|
return baseToString;
|
|
185
185
|
}
|
|
186
186
|
}
|
package/src/errors.js
CHANGED
|
@@ -48,9 +48,9 @@ export function grammarSyntaxError(matchFailure) {
|
|
|
48
48
|
// Undeclared grammar
|
|
49
49
|
|
|
50
50
|
export function undeclaredGrammar(grammarName, namespace, interval) {
|
|
51
|
-
const message = namespace
|
|
52
|
-
`Grammar ${grammarName} is not declared in namespace '${namespace}'`
|
|
53
|
-
'Undeclared grammar ' + grammarName;
|
|
51
|
+
const message = namespace
|
|
52
|
+
? `Grammar ${grammarName} is not declared in namespace '${namespace}'`
|
|
53
|
+
: 'Undeclared grammar ' + grammarName;
|
|
54
54
|
return createError(message, interval);
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -70,8 +70,8 @@ export function grammarDoesNotSupportIncrementalParsing(grammar) {
|
|
|
70
70
|
|
|
71
71
|
export function undeclaredRule(ruleName, grammarName, optInterval) {
|
|
72
72
|
return createError(
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
'Rule ' + ruleName + ' is not declared in grammar ' + grammarName,
|
|
74
|
+
optInterval
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -79,8 +79,8 @@ export function undeclaredRule(ruleName, grammarName, optInterval) {
|
|
|
79
79
|
|
|
80
80
|
export function cannotOverrideUndeclaredRule(ruleName, grammarName, optSource) {
|
|
81
81
|
return createError(
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
'Cannot override rule ' + ruleName + ' because it is not declared in ' + grammarName,
|
|
83
|
+
optSource
|
|
84
84
|
);
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -88,8 +88,8 @@ export function cannotOverrideUndeclaredRule(ruleName, grammarName, optSource) {
|
|
|
88
88
|
|
|
89
89
|
export function cannotExtendUndeclaredRule(ruleName, grammarName, optSource) {
|
|
90
90
|
return createError(
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
'Cannot extend rule ' + ruleName + ' because it is not declared in ' + grammarName,
|
|
92
|
+
optSource
|
|
93
93
|
);
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -108,14 +108,14 @@ export function duplicateRuleDeclaration(ruleName, grammarName, declGrammarName,
|
|
|
108
108
|
|
|
109
109
|
export function wrongNumberOfParameters(ruleName, expected, actual, source) {
|
|
110
110
|
return createError(
|
|
111
|
-
|
|
111
|
+
'Wrong number of parameters for rule ' +
|
|
112
112
|
ruleName +
|
|
113
113
|
' (expected ' +
|
|
114
114
|
expected +
|
|
115
115
|
', got ' +
|
|
116
116
|
actual +
|
|
117
117
|
')',
|
|
118
|
-
|
|
118
|
+
source
|
|
119
119
|
);
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -123,14 +123,14 @@ export function wrongNumberOfParameters(ruleName, expected, actual, source) {
|
|
|
123
123
|
|
|
124
124
|
export function wrongNumberOfArguments(ruleName, expected, actual, expr) {
|
|
125
125
|
return createError(
|
|
126
|
-
|
|
126
|
+
'Wrong number of arguments for rule ' +
|
|
127
127
|
ruleName +
|
|
128
128
|
' (expected ' +
|
|
129
129
|
expected +
|
|
130
130
|
', got ' +
|
|
131
131
|
actual +
|
|
132
132
|
')',
|
|
133
|
-
|
|
133
|
+
expr
|
|
134
134
|
);
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -138,8 +138,8 @@ export function wrongNumberOfArguments(ruleName, expected, actual, expr) {
|
|
|
138
138
|
|
|
139
139
|
export function duplicateParameterNames(ruleName, duplicates, source) {
|
|
140
140
|
return createError(
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
'Duplicate parameter names in rule ' + ruleName + ': ' + duplicates.join(', '),
|
|
142
|
+
source
|
|
143
143
|
);
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -147,14 +147,14 @@ export function duplicateParameterNames(ruleName, duplicates, source) {
|
|
|
147
147
|
|
|
148
148
|
export function invalidParameter(ruleName, expr) {
|
|
149
149
|
return createError(
|
|
150
|
-
|
|
150
|
+
'Invalid parameter to rule ' +
|
|
151
151
|
ruleName +
|
|
152
152
|
': ' +
|
|
153
153
|
expr +
|
|
154
154
|
' has arity ' +
|
|
155
155
|
expr.getArity() +
|
|
156
156
|
', but parameter expressions must have arity 1',
|
|
157
|
-
|
|
157
|
+
expr.source
|
|
158
158
|
);
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -166,8 +166,8 @@ const syntacticVsLexicalNote =
|
|
|
166
166
|
|
|
167
167
|
export function applicationOfSyntacticRuleFromLexicalContext(ruleName, applyExpr) {
|
|
168
168
|
return createError(
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
'Cannot apply syntactic rule ' + ruleName + ' from here (inside a lexical context)',
|
|
170
|
+
applyExpr.source
|
|
171
171
|
);
|
|
172
172
|
}
|
|
173
173
|
|
|
@@ -176,9 +176,9 @@ export function applicationOfSyntacticRuleFromLexicalContext(ruleName, applyExpr
|
|
|
176
176
|
export function applySyntacticWithLexicalRuleApplication(applyExpr) {
|
|
177
177
|
const {ruleName} = applyExpr;
|
|
178
178
|
return createError(
|
|
179
|
-
|
|
179
|
+
`applySyntactic is for syntactic rules, but '${ruleName}' is a lexical rule. ` +
|
|
180
180
|
syntacticVsLexicalNote,
|
|
181
|
-
|
|
181
|
+
applyExpr.source
|
|
182
182
|
);
|
|
183
183
|
}
|
|
184
184
|
|
|
@@ -186,8 +186,8 @@ export function applySyntacticWithLexicalRuleApplication(applyExpr) {
|
|
|
186
186
|
|
|
187
187
|
export function unnecessaryExperimentalApplySyntactic(applyExpr) {
|
|
188
188
|
return createError(
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
'applySyntactic is not required here (in a syntactic context)',
|
|
190
|
+
applyExpr.source
|
|
191
191
|
);
|
|
192
192
|
}
|
|
193
193
|
|
|
@@ -213,8 +213,8 @@ export function invalidCodePoint(applyWrapper) {
|
|
|
213
213
|
const digitIntervals = applyWrapper.children.slice(1, -1).map(d => d.source);
|
|
214
214
|
const fullInterval = digitIntervals[0].coverageWith(...digitIntervals.slice(1));
|
|
215
215
|
return createError(
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
`U+${fullInterval.contents} is not a valid Unicode code point`,
|
|
217
|
+
fullInterval
|
|
218
218
|
);
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -232,8 +232,8 @@ export function kleeneExprHasNullableOperand(kleeneExpr, applicationStack) {
|
|
|
232
232
|
"' (possible infinite loop)";
|
|
233
233
|
if (applicationStack.length > 0) {
|
|
234
234
|
const stackTrace = applicationStack
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
.map(app => new pexprs.Apply(app.ruleName, app.args))
|
|
236
|
+
.join('\n');
|
|
237
237
|
message += '\nApplication stack (most recent application last):\n' + stackTrace;
|
|
238
238
|
}
|
|
239
239
|
return createError(message, kleeneExpr.expr.source);
|
|
@@ -243,7 +243,7 @@ export function kleeneExprHasNullableOperand(kleeneExpr, applicationStack) {
|
|
|
243
243
|
|
|
244
244
|
export function inconsistentArity(ruleName, expected, actual, expr) {
|
|
245
245
|
return createError(
|
|
246
|
-
|
|
246
|
+
'Rule ' +
|
|
247
247
|
ruleName +
|
|
248
248
|
' involves an alternation which has inconsistent arity ' +
|
|
249
249
|
'(expected ' +
|
|
@@ -251,7 +251,7 @@ export function inconsistentArity(ruleName, expected, actual, expr) {
|
|
|
251
251
|
', got ' +
|
|
252
252
|
actual +
|
|
253
253
|
')',
|
|
254
|
-
|
|
254
|
+
expr.source
|
|
255
255
|
);
|
|
256
256
|
}
|
|
257
257
|
|
|
@@ -265,7 +265,7 @@ export function duplicatePropertyNames(duplicates) {
|
|
|
265
265
|
|
|
266
266
|
export function invalidConstructorCall(grammar, ctorName, children) {
|
|
267
267
|
return createError(
|
|
268
|
-
|
|
268
|
+
'Attempt to invoke constructor ' + ctorName + ' with invalid or unexpected arguments'
|
|
269
269
|
);
|
|
270
270
|
}
|
|
271
271
|
|
|
@@ -280,12 +280,12 @@ export function multipleErrors(errors) {
|
|
|
280
280
|
|
|
281
281
|
export function missingSemanticAction(ctorName, name, type, stack) {
|
|
282
282
|
let stackTrace = stack
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
283
|
+
.slice(0, -1)
|
|
284
|
+
.map(info => {
|
|
285
|
+
const ans = ' ' + info[0].name + ' > ' + info[1];
|
|
286
|
+
return info.length === 3 ? ans + " for '" + info[2] + "'" : ans;
|
|
287
|
+
})
|
|
288
|
+
.join('\n');
|
|
289
289
|
stackTrace += '\n ' + name + ' > ' + ctorName;
|
|
290
290
|
|
|
291
291
|
let moreInfo = '';
|
package/src/main.js
CHANGED
|
@@ -35,8 +35,8 @@ export function grammar(source, optNamespace) {
|
|
|
35
35
|
const secondGrammar = ns[grammarNames[1]];
|
|
36
36
|
const interval = secondGrammar.source;
|
|
37
37
|
throw new Error(
|
|
38
|
-
|
|
39
|
-
'Found more than one grammar definition -- use ohm.grammars() instead.'
|
|
38
|
+
util.getLineAndColumnMessage(interval.sourceString, interval.startIdx) +
|
|
39
|
+
'Found more than one grammar definition -- use ohm.grammars() instead.'
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
return ns[grammarNames[0]]; // Return the one and only grammar.
|
|
@@ -50,7 +50,7 @@ export function grammars(source, optNamespace) {
|
|
|
50
50
|
source = source.toString();
|
|
51
51
|
} else {
|
|
52
52
|
throw new TypeError(
|
|
53
|
-
|
|
53
|
+
'Expected string as first argument, got ' + common.unexpectedObjToString(source)
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
}
|