|
|
|
@ -59,12 +59,14 @@ function generateJS( ast, session, options ) {
|
|
|
|
|
|
|
|
|
|
case "rule":
|
|
|
|
|
return `peg$otherExpectation("${ js.stringEscape( e.value ) }")`;
|
|
|
|
|
|
|
|
|
|
case "literal":
|
|
|
|
|
return "peg$literalExpectation(\""
|
|
|
|
|
+ js.stringEscape( e.value )
|
|
|
|
|
+ "\", "
|
|
|
|
|
+ e.ignoreCase
|
|
|
|
|
+ ")";
|
|
|
|
|
|
|
|
|
|
case "class": {
|
|
|
|
|
|
|
|
|
|
const parts = e.value.map( part =>
|
|
|
|
@ -80,9 +82,13 @@ function generateJS( ast, session, options ) {
|
|
|
|
|
+ ")";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
case "any": return "peg$anyExpectation()";
|
|
|
|
|
|
|
|
|
|
case "any":
|
|
|
|
|
return "peg$anyExpectation()";
|
|
|
|
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
default: throw new Error( `Unknown expectation type (${ JSON.stringify( e ) })` );
|
|
|
|
|
default:
|
|
|
|
|
session.fatal( `Unknown expectation type (${ JSON.stringify( e ) })` );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -578,7 +584,7 @@ function generateJS( ast, session, options ) {
|
|
|
|
|
function s( i ) {
|
|
|
|
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
if ( i < 0 ) throw new Error( "Rule '" + rule.name + "': Var stack underflow: attempt to use var at index " + i );
|
|
|
|
|
if ( i < 0 ) session.fail( "Rule '" + rule.name + "': Var stack underflow: attempt to use var at index " + i );
|
|
|
|
|
|
|
|
|
|
return "s" + i;
|
|
|
|
|
|
|
|
|
@ -657,7 +663,7 @@ function generateJS( ast, session, options ) {
|
|
|
|
|
// istanbul ignore if
|
|
|
|
|
if ( thenSp !== elseSp ) {
|
|
|
|
|
|
|
|
|
|
throw new Error(
|
|
|
|
|
session.fail(
|
|
|
|
|
"Rule '" + rule.name + "', position " + pos + ": "
|
|
|
|
|
+ "Branches of a condition can't move the stack pointer differently "
|
|
|
|
|
+ "(before: " + baseSp + ", after then: " + thenSp + ", after else: " + elseSp + ")."
|
|
|
|
@ -695,7 +701,7 @@ function generateJS( ast, session, options ) {
|
|
|
|
|
// istanbul ignore if
|
|
|
|
|
if ( bodySp !== baseSp ) {
|
|
|
|
|
|
|
|
|
|
throw new Error(
|
|
|
|
|
session.fail(
|
|
|
|
|
"Rule '" + rule.name + "', position " + pos + ": "
|
|
|
|
|
+ "Body of a loop can't move the stack pointer "
|
|
|
|
|
+ "(before: " + baseSp + ", after: " + bodySp + ")."
|
|
|
|
@ -921,7 +927,7 @@ function generateJS( ast, session, options ) {
|
|
|
|
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
default:
|
|
|
|
|
throw new Error(
|
|
|
|
|
session.fail(
|
|
|
|
|
"Rule '" + rule.name + "', position " + ip + ": "
|
|
|
|
|
+ "Invalid opcode " + bc[ ip ] + "."
|
|
|
|
|
);
|
|
|
|
|