Resolve linting errors

This also temporarliy disables linting '.ts' files due to the fact that the currect '.d.ts' files contain too many errors/warnings that need to be manually fixed, but since I'm going to be rewriting the whole module in TypeScript anyway, resolving these ESLint error's is a pointless waste of time.
master
Futago-za Ryuu 5 years ago
parent 61377b1bd7
commit 8b7bff7ac3

@ -2,7 +2,13 @@
module.exports = { module.exports = {
"extends": "@futagoza", "extends": [
"@futagoza/node/6",
// "@futagoza/typescript",
"@futagoza/vue",
],
"rules": { "rules": {
@ -13,7 +19,11 @@ module.exports = {
"overrides": [ { "overrides": [ {
"files": [ "*.spec.js", "*.test.js" ], "files": [
"test/unit/compiler/passes/helpers.js",
"*.spec.js",
"*.test.js"
],
"extends": "@futagoza/dev/test", "extends": "@futagoza/dev/test",
"rules": { "rules": {

@ -40,6 +40,6 @@ module.exports = {
extraWatchFiles: [ extraWatchFiles: [
require.resolve( "./config/nav.js" ), require.resolve( "./config/nav.js" ),
require.resolve( "./config/sidebar.js" ), require.resolve( "./config/sidebar.js" ),
] ],
}; };

@ -73,7 +73,7 @@ module.exports = [
{ {
text: "Plugins", text: "Plugins",
link: "https://www.npmjs.com/search?q=pegjs%20plugin", link: "https://www.npmjs.com/search?q=pegjs%20plugin",
} },
], ],
}, },

@ -7,7 +7,7 @@
"test" "test"
], ],
"scripts": { "scripts": {
"lint": "eslint --ext .js,.ts,.vue . docs/.vuepress", "lint": "eslint --ext .js,.vue . docs/.vuepress",
"spec": "mocha --reporter progress", "spec": "mocha --reporter progress",
"benchmark": "node tools/benchmark", "benchmark": "node tools/benchmark",
"build-docs": "vuepress build docs", "build-docs": "vuepress build docs",

@ -19,7 +19,7 @@ let options = {
"output": "source", "output": "source",
"parser": {}, "parser": {},
"plugins": [], "plugins": [],
"trace": false "trace": false,
}; };
const EXPORT_VAR_FORMATS = [ "globals", "umd" ]; const EXPORT_VAR_FORMATS = [ "globals", "umd" ];

@ -15,6 +15,7 @@ class Grammar extends Node {
this.comments = comments; this.comments = comments;
this.rules = rules; this.rules = rules;
// eslint-disable-next-line no-use-before-define
this._alwaysConsumesOnSuccess = new AlwaysConsumesOnSuccess( this ); this._alwaysConsumesOnSuccess = new AlwaysConsumesOnSuccess( this );
} }

@ -35,14 +35,14 @@ const compiler = {
reportIncorrectPlucking: reportIncorrectPlucking, reportIncorrectPlucking: reportIncorrectPlucking,
}, },
transform: { transform: {
removeProxyRules: removeProxyRules removeProxyRules: removeProxyRules,
}, },
generate: { generate: {
calcReportFailures: calcReportFailures, calcReportFailures: calcReportFailures,
inferenceMatchResult: inferenceMatchResult, inferenceMatchResult: inferenceMatchResult,
generateBytecode: generateBytecode, generateBytecode: generateBytecode,
generateJS: generateJS generateJS: generateJS,
} },
}, },
// Generates a parser from a specified grammar AST. Throws |peg.GrammarError| // Generates a parser from a specified grammar AST. Throws |peg.GrammarError|
@ -62,7 +62,7 @@ const compiler = {
header: null, header: null,
optimize: "speed", optimize: "speed",
output: "parser", output: "parser",
trace: false trace: false,
} ); } );
// We want `session.vm.evalModule` to return the parser // We want `session.vm.evalModule` to return the parser
@ -91,7 +91,7 @@ const compiler = {
} }
} },
}; };

@ -53,7 +53,7 @@ const opcodes = {
SILENT_FAILS_OFF: 29, // SILENT_FAILS_OFF SILENT_FAILS_OFF: 29, // SILENT_FAILS_OFF
EXPECT_NS_BEGIN: 38, // EXPECT_NS_BEGIN EXPECT_NS_BEGIN: 38, // EXPECT_NS_BEGIN
EXPECT_NS_END: 39 // EXPECT_NS_END invert EXPECT_NS_END: 39, // EXPECT_NS_END invert
}; };

@ -51,7 +51,7 @@ function calcReportFailures( ast, session, options ) {
} }
} },
} ); } );
while ( changedRules.length > 0 ) { while ( changedRules.length > 0 ) {

@ -219,7 +219,7 @@ function generateBytecode( ast, session ) {
const cls = { const cls = {
value: node.parts, value: node.parts,
inverted: node.inverted, inverted: node.inverted,
ignoreCase: node.ignoreCase ignoreCase: node.ignoreCase,
}; };
const pattern = JSON.stringify( cls ); const pattern = JSON.stringify( cls );
const index = util.findIndex( classes, c => JSON.stringify( c ) === pattern ); const index = util.findIndex( classes, c => JSON.stringify( c ) === pattern );
@ -282,7 +282,7 @@ function generateBytecode( ast, session ) {
sp: context.sp + 1, sp: context.sp + 1,
env: util.clone( context.env ), env: util.clone( context.env ),
action: null, action: null,
reportFailures: context.reportFailures reportFailures: context.reportFailures,
} ), } ),
[ op.EXPECT_NS_END, negative ? 1 : 0 ], [ op.EXPECT_NS_END, negative ? 1 : 0 ],
buildCondition( buildCondition(
@ -346,7 +346,7 @@ function generateBytecode( ast, session ) {
sp: -1, // stack pointer sp: -1, // stack pointer
env: { }, // mapping of label names to stack positions env: { }, // mapping of label names to stack positions
action: null, // action nodes pass themselves to children here action: null, // action nodes pass themselves to children here
reportFailures: node.reportFailures // if `false`, suppress generation of EXPECT opcodes reportFailures: node.reportFailures, // if `false`, suppress generation of EXPECT opcodes
} ); } );
}, },
@ -361,7 +361,7 @@ function generateBytecode( ast, session ) {
sp: context.sp, sp: context.sp,
env: context.env, env: context.env,
action: context.action, action: context.action,
reportFailures: false reportFailures: false,
} ); } );
// No need to disable report failures if it already disabled // No need to disable report failures if it already disabled
@ -383,7 +383,7 @@ function generateBytecode( ast, session ) {
sp: context.sp, sp: context.sp,
env: util.clone( context.env ), env: util.clone( context.env ),
action: null, action: null,
reportFailures: context.reportFailures reportFailures: context.reportFailures,
} ), } ),
alternatives.length < 2 alternatives.length < 2
? [] ? []
@ -413,7 +413,7 @@ function generateBytecode( ast, session ) {
sp: context.sp + ( emitCall ? 1 : 0 ), sp: context.sp + ( emitCall ? 1 : 0 ),
env: env, env: env,
action: node, action: node,
reportFailures: context.reportFailures reportFailures: context.reportFailures,
} ); } );
const match = node.expression.match|0; const match = node.expression.match|0;
const functionIndex = emitCall && match >= 0 const functionIndex = emitCall && match >= 0
@ -455,7 +455,7 @@ function generateBytecode( ast, session ) {
env: context.env, env: context.env,
pluck: context.pluck, pluck: context.pluck,
action: null, action: null,
reportFailures: context.reportFailures reportFailures: context.reportFailures,
} ), } ),
buildCondition( buildCondition(
elements[ 0 ].match|0, elements[ 0 ].match|0,
@ -465,7 +465,7 @@ function generateBytecode( ast, session ) {
env: context.env, env: context.env,
pluck: context.pluck, pluck: context.pluck,
action: context.action, action: context.action,
reportFailures: context.reportFailures reportFailures: context.reportFailures,
} ), } ),
buildSequence( buildSequence(
processedCount > 1 ? [ op.POP_N, processedCount ] : [ op.POP ], processedCount > 1 ? [ op.POP_N, processedCount ] : [ op.POP ],
@ -511,7 +511,7 @@ function generateBytecode( ast, session ) {
env: context.env, env: context.env,
pluck: [], pluck: [],
action: context.action, action: context.action,
reportFailures: context.reportFailures reportFailures: context.reportFailures,
} ) } )
); );
@ -538,7 +538,7 @@ function generateBytecode( ast, session ) {
sp: context.sp, sp: context.sp,
env: env, env: env,
action: null, action: null,
reportFailures: context.reportFailures reportFailures: context.reportFailures,
} ); } );
}, },
@ -551,7 +551,7 @@ function generateBytecode( ast, session ) {
sp: context.sp + 1, sp: context.sp + 1,
env: util.clone( context.env ), env: util.clone( context.env ),
action: null, action: null,
reportFailures: context.reportFailures reportFailures: context.reportFailures,
} ), } ),
buildCondition( buildCondition(
node.expression.match|0, node.expression.match|0,
@ -582,7 +582,7 @@ function generateBytecode( ast, session ) {
sp: context.sp, sp: context.sp,
env: util.clone( context.env ), env: util.clone( context.env ),
action: null, action: null,
reportFailures: context.reportFailures reportFailures: context.reportFailures,
} ), } ),
buildCondition( buildCondition(
// If expression always match no need replace FAILED to NULL // If expression always match no need replace FAILED to NULL
@ -601,7 +601,7 @@ function generateBytecode( ast, session ) {
sp: context.sp + 1, sp: context.sp + 1,
env: util.clone( context.env ), env: util.clone( context.env ),
action: null, action: null,
reportFailures: context.reportFailures reportFailures: context.reportFailures,
} ); } );
return buildSequence( return buildSequence(
@ -619,7 +619,7 @@ function generateBytecode( ast, session ) {
sp: context.sp + 1, sp: context.sp + 1,
env: util.clone( context.env ), env: util.clone( context.env ),
action: null, action: null,
reportFailures: context.reportFailures reportFailures: context.reportFailures,
} ); } );
return buildSequence( return buildSequence(
@ -641,7 +641,7 @@ function generateBytecode( ast, session ) {
sp: context.sp, sp: context.sp,
env: util.clone( context.env ), env: util.clone( context.env ),
action: null, action: null,
reportFailures: context.reportFailures reportFailures: context.reportFailures,
} ); } );
}, },
@ -677,7 +677,7 @@ function generateBytecode( ast, session ) {
const expectedIndex = context.reportFailures ? addExpectedConst( { const expectedIndex = context.reportFailures ? addExpectedConst( {
type: "literal", type: "literal",
value: node.value, value: node.value,
ignoreCase: node.ignoreCase ignoreCase: node.ignoreCase,
} ) : null; } ) : null;
// For case-sensitive strings the value must match the beginning of the // For case-sensitive strings the value must match the beginning of the
@ -712,7 +712,7 @@ function generateBytecode( ast, session ) {
type: "class", type: "class",
value: node.parts, value: node.parts,
inverted: node.inverted, inverted: node.inverted,
ignoreCase: node.ignoreCase ignoreCase: node.ignoreCase,
} ) : null; } ) : null;
return buildSequence( return buildSequence(
@ -744,7 +744,7 @@ function generateBytecode( ast, session ) {
) )
); );
} },
} ); } );
generate( ast ); generate( ast );

@ -87,8 +87,7 @@ function generateJS( ast, session, options ) {
const parts = e.value.map( part => const parts = e.value.map( part =>
( Array.isArray( part ) ( Array.isArray( part )
? `["${ util.stringEscape( part[ 0 ] ) }", "${ util.stringEscape( part[ 1 ] ) }"]` ? `["${ util.stringEscape( part[ 0 ] ) }", "${ util.stringEscape( part[ 1 ] ) }"]`
: `"${ util.stringEscape( part ) }"` ) : `"${ util.stringEscape( part ) }"` ) );
);
return "peg$classExpectation([" return "peg$classExpectation(["
+ parts.join( ", " ) + "], " + parts.join( ", " ) + "], "
@ -137,13 +136,10 @@ function generateJS( ast, session, options ) {
`peg$decode("${ `peg$decode("${
util.stringEscape( rule.bytecode util.stringEscape( rule.bytecode
.map( b => String.fromCharCode( b + 32 ) ) .map( b => String.fromCharCode( b + 32 ) )
.join( "" ) .join( "" ) )
) }")` )
}")` .join( ",\n" ) ),
) "];",
.join( ",\n" )
),
"];"
].join( "\n" ); ].join( "\n" );
} }
@ -172,7 +168,7 @@ function generateJS( ast, session, options ) {
"var rule$expects = function (expected) {", "var rule$expects = function (expected) {",
" if (peg$silentFails === 0) peg$expect(expected);", " if (peg$silentFails === 0) peg$expect(expected);",
"}", "}",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
if ( options.trace ) { if ( options.trace ) {
@ -183,7 +179,7 @@ function generateJS( ast, session, options ) {
" rule: " + ruleNameCode + ",", " rule: " + ruleNameCode + ",",
" location: peg$computeLocation(startPos, startPos)", " location: peg$computeLocation(startPos, startPos)",
"});", "});",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
} }
@ -207,7 +203,7 @@ function generateJS( ast, session, options ) {
" if (peg$silentFails === 0) {", " if (peg$silentFails === 0) {",
" rule$expectations.forEach(peg$expect);", " rule$expectations.forEach(peg$expect);",
" }", " }",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
if ( options.trace ) { if ( options.trace ) {
@ -227,7 +223,7 @@ function generateJS( ast, session, options ) {
" location: peg$computeLocation(startPos, startPos)", " location: peg$computeLocation(startPos, startPos)",
" });", " });",
"}", "}",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
} }
@ -235,7 +231,7 @@ function generateJS( ast, session, options ) {
parts.push( [ parts.push( [
" return cached.result;", " return cached.result;",
"}", "}",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
} }
@ -256,7 +252,7 @@ function generateJS( ast, session, options ) {
" nextPos: peg$currPos,", " nextPos: peg$currPos,",
" result: " + resultCode + ",", " result: " + resultCode + ",",
" expectations: rule$expectations", " expectations: rule$expectations",
"};" "};",
].join( "\n" ) ); ].join( "\n" ) );
} }
@ -278,14 +274,14 @@ function generateJS( ast, session, options ) {
" rule: " + ruleNameCode + ",", " rule: " + ruleNameCode + ",",
" location: peg$computeLocation(startPos, startPos)", " location: peg$computeLocation(startPos, startPos)",
" });", " });",
"}" "}",
].join( "\n" ) ); ].join( "\n" ) );
} }
parts.push( [ parts.push( [
"", "",
"return " + resultCode + ";" "return " + resultCode + ";",
].join( "\n" ) ); ].join( "\n" ) );
return parts.join( "\n" ); return parts.join( "\n" );
@ -314,7 +310,7 @@ function generateJS( ast, session, options ) {
" ip += " + baseLength + " + " + thenLengthCode + ";", " ip += " + baseLength + " + " + thenLengthCode + ";",
"}", "}",
"", "",
"break;" "break;",
].join( "\n" ); ].join( "\n" );
} }
@ -335,7 +331,7 @@ function generateJS( ast, session, options ) {
" ip += " + baseLength + " + " + bodyLengthCode + ";", " ip += " + baseLength + " + " + bodyLengthCode + ";",
"}", "}",
"", "",
"break;" "break;",
].join( "\n" ); ].join( "\n" );
} }
@ -356,7 +352,7 @@ function generateJS( ast, session, options ) {
");", ");",
"", "",
"ip += " + baseLength + " + " + paramsLengthCode + ";", "ip += " + baseLength + " + " + paramsLengthCode + ";",
"break;" "break;",
].join( "\n" ); ].join( "\n" );
} }
@ -366,7 +362,7 @@ function generateJS( ast, session, options ) {
" return s.split(\"\").map(function(ch) { return ch.charCodeAt(0) - 32; });", " return s.split(\"\").map(function(ch) { return ch.charCodeAt(0) - 32; });",
"}", "}",
"", "",
"function peg$parseRule(index) {" "function peg$parseRule(index) {",
].join( "\n" ) ); ].join( "\n" ) );
if ( options.trace ) { if ( options.trace ) {
@ -379,7 +375,7 @@ function generateJS( ast, session, options ) {
" var ends = [];", " var ends = [];",
" var stack = [];", " var stack = [];",
" var startPos = peg$currPos;", " var startPos = peg$currPos;",
" var params, paramsLength, paramsN;" " var params, paramsLength, paramsN;",
].join( "\n" ) ); ].join( "\n" ) );
} else { } else {
@ -391,7 +387,7 @@ function generateJS( ast, session, options ) {
" var end = bc.length;", " var end = bc.length;",
" var ends = [];", " var ends = [];",
" var stack = [];", " var stack = [];",
" var params, paramsLength, paramsN;" " var params, paramsLength, paramsN;",
].join( "\n" ) ); ].join( "\n" ) );
} }
@ -501,9 +497,11 @@ function generateJS( ast, session, options ) {
"", "",
" case " + op.IF_NOT_ERROR + ":", // IF_NOT_ERROR t, f " case " + op.IF_NOT_ERROR + ":", // IF_NOT_ERROR t, f
indent10( indent10(
generateCondition( "stack[stack.length - 1] !== peg$FAILED", generateCondition(
"stack[stack.length - 1] !== peg$FAILED",
0 0
) ), )
),
"", "",
" case " + op.WHILE_NOT_ERROR + ":", // WHILE_NOT_ERROR b " case " + op.WHILE_NOT_ERROR + ":", // WHILE_NOT_ERROR b
indent10( generateLoop( "stack[stack.length - 1] !== peg$FAILED" ) ), indent10( generateLoop( "stack[stack.length - 1] !== peg$FAILED" ) ),
@ -599,7 +597,7 @@ function generateJS( ast, session, options ) {
" } else {", " } else {",
" break;", " break;",
" }", " }",
" }" " }",
].join( "\n" ) ); ].join( "\n" ) );
parts.push( indent2( generateRuleFooter( "peg$ruleNames[index]", "stack[0]" ) ) ); parts.push( indent2( generateRuleFooter( "peg$ruleNames[index]", "stack[0]" ) ) );
@ -662,7 +660,7 @@ function generateJS( ast, session, options ) {
return s( this.sp - i ); return s( this.sp - i );
} },
}; };
function compile( bc ) { function compile( bc ) {
@ -1152,7 +1150,7 @@ function generateJS( ast, session, options ) {
"", "",
" return \"Expected \" + describeExpected(expected) + \" but \" + describeFound(found) + \" found.\";", " return \"Expected \" + describeExpected(expected) + \" but \" + describeFound(found) + \" found.\";",
"};", "};",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
if ( options.trace ) { if ( options.trace ) {
@ -1213,7 +1211,7 @@ function generateJS( ast, session, options ) {
" throw new Error(\"Invalid event type: \" + event.type + \".\");", " throw new Error(\"Invalid event type: \" + event.type + \".\");",
" }", " }",
"};", "};",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
else else
@ -1222,7 +1220,7 @@ function generateJS( ast, session, options ) {
"var peg$FauxTracer = {", "var peg$FauxTracer = {",
" trace: function(event) { }", " trace: function(event) { }",
"};", "};",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
} }
@ -1232,7 +1230,7 @@ function generateJS( ast, session, options ) {
" options = options !== undefined ? options : {};", " options = options !== undefined ? options : {};",
"", "",
" var peg$FAILED = {};", " var peg$FAILED = {};",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
if ( options.optimize === "size" ) { if ( options.optimize === "size" ) {
@ -1246,7 +1244,7 @@ function generateJS( ast, session, options ) {
parts.push( [ parts.push( [
" var peg$startRuleIndices = " + startRuleIndices + ";", " var peg$startRuleIndices = " + startRuleIndices + ";",
" var peg$startRuleIndex = " + startRuleIndex + ";" " var peg$startRuleIndex = " + startRuleIndex + ";",
].join( "\n" ) ); ].join( "\n" ) );
} else { } else {
@ -1260,7 +1258,7 @@ function generateJS( ast, session, options ) {
parts.push( [ parts.push( [
" var peg$startRuleFunctions = " + startRuleFunctions + ";", " var peg$startRuleFunctions = " + startRuleFunctions + ";",
" var peg$startRuleFunction = " + startRuleFunction + ";" " var peg$startRuleFunction = " + startRuleFunction + ";",
].join( "\n" ) ); ].join( "\n" ) );
} }
@ -1276,14 +1274,14 @@ function generateJS( ast, session, options ) {
" var peg$posDetailsCache = [{ line: 1, column: 1 }];", " var peg$posDetailsCache = [{ line: 1, column: 1 }];",
" var peg$expected = [];", " var peg$expected = [];",
" var peg$silentFails = 0;", // 0 = report failures, > 0 = silence failures " var peg$silentFails = 0;", // 0 = report failures, > 0 = silence failures
"" "",
].join( "\n" ) ); ].join( "\n" ) );
if ( options.cache ) { if ( options.cache ) {
parts.push( [ parts.push( [
" var peg$resultsCache = {};", " var peg$resultsCache = {};",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
} }
@ -1300,7 +1298,7 @@ function generateJS( ast, session, options ) {
parts.push( [ parts.push( [
" var peg$ruleNames = " + ruleNames + ";", " var peg$ruleNames = " + ruleNames + ";",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
} }
@ -1309,21 +1307,21 @@ function generateJS( ast, session, options ) {
parts.push( [ parts.push( [
" var peg$tracer = \"tracer\" in options ? options.tracer : new peg$DefaultTracer();", " var peg$tracer = \"tracer\" in options ? options.tracer : new peg$DefaultTracer();",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
else else
parts.push( [ parts.push( [
" var peg$tracer = \"tracer\" in options ? options.tracer : peg$FauxTracer;", " var peg$tracer = \"tracer\" in options ? options.tracer : peg$FauxTracer;",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
} }
parts.push( [ parts.push( [
" var peg$result;", " var peg$result;",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
if ( options.optimize === "size" ) { if ( options.optimize === "size" ) {
@ -1335,7 +1333,7 @@ function generateJS( ast, session, options ) {
" }", " }",
"", "",
" peg$startRuleIndex = peg$startRuleIndices[options.startRule];", " peg$startRuleIndex = peg$startRuleIndices[options.startRule];",
" }" " }",
].join( "\n" ) ); ].join( "\n" ) );
} else { } else {
@ -1347,7 +1345,7 @@ function generateJS( ast, session, options ) {
" }", " }",
"", "",
" peg$startRuleFunction = peg$startRuleFunctions[options.startRule];", " peg$startRuleFunction = peg$startRuleFunctions[options.startRule];",
" }" " }",
].join( "\n" ) ); ].join( "\n" ) );
} }
@ -1568,7 +1566,7 @@ function generateJS( ast, session, options ) {
" : peg$computeLocation(failPos, failPos)", " : peg$computeLocation(failPos, failPos)",
" );", " );",
" }", " }",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
if ( options.optimize === "size" ) { if ( options.optimize === "size" ) {
@ -1617,7 +1615,7 @@ function generateJS( ast, session, options ) {
"", "",
" throw peg$buildError();", " throw peg$buildError();",
" }", " }",
"}" "}",
].join( "\n" ) ); ].join( "\n" ) );
return parts.join( "\n" ); return parts.join( "\n" );
@ -1658,13 +1656,13 @@ function generateJS( ast, session, options ) {
" SyntaxError: peg$SyntaxError,", " SyntaxError: peg$SyntaxError,",
" DefaultTracer: peg$DefaultTracer,", " DefaultTracer: peg$DefaultTracer,",
" parse: peg$parse", " parse: peg$parse",
"}" "}",
].join( "\n" ) ].join( "\n" )
: [ : [
"{", "{",
" SyntaxError: peg$SyntaxError,", " SyntaxError: peg$SyntaxError,",
" parse: peg$parse", " parse: peg$parse",
"}" "}",
].join( "\n" ); ].join( "\n" );
} }
@ -1677,13 +1675,13 @@ function generateJS( ast, session, options ) {
" peg$SyntaxError as SyntaxError,", " peg$SyntaxError as SyntaxError,",
" peg$DefaultTracer as DefaultTracer,", " peg$DefaultTracer as DefaultTracer,",
" peg$parse as parse", " peg$parse as parse",
"}" "}",
].join( "\n" ) ].join( "\n" )
: [ : [
"{", "{",
" peg$SyntaxError as SyntaxError,", " peg$SyntaxError as SyntaxError,",
" peg$parse as parse", " peg$parse as parse",
"}" "}",
].join( "\n" ); ].join( "\n" );
} }
@ -1699,7 +1697,7 @@ function generateJS( ast, session, options ) {
indent2( toplevelCode ), indent2( toplevelCode ),
"", "",
indent2( "return " + generateParserObject() + ";" ), indent2( "return " + generateParserObject() + ";" ),
"})()" "})()",
].join( "\n" ); ].join( "\n" );
}, },
@ -1713,7 +1711,7 @@ function generateJS( ast, session, options ) {
generateHeaderComment(), generateHeaderComment(),
"", "",
"\"use strict\";", "\"use strict\";",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
if ( dependencyVars.length > 0 ) { if ( dependencyVars.length > 0 ) {
@ -1723,8 +1721,7 @@ function generateJS( ast, session, options ) {
parts.push( "var " + variable parts.push( "var " + variable
+ " = require(\"" + " = require(\""
+ util.stringEscape( options.dependencies[ variable ] ) + util.stringEscape( options.dependencies[ variable ] )
+ "\");" + "\");" );
);
} ); } );
parts.push( "" ); parts.push( "" );
@ -1735,7 +1732,7 @@ function generateJS( ast, session, options ) {
toplevelCode, toplevelCode,
"", "",
"module.exports = " + generateParserObject() + ";", "module.exports = " + generateParserObject() + ";",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
return parts.join( "\n" ); return parts.join( "\n" );
@ -1759,8 +1756,7 @@ function generateJS( ast, session, options ) {
parts.push( "import " + variable parts.push( "import " + variable
+ " from \"" + " from \""
+ util.stringEscape( options.dependencies[ variable ] ) + util.stringEscape( options.dependencies[ variable ] )
+ "\";" + "\";" );
);
} ); } );
parts.push( "" ); parts.push( "" );
@ -1800,7 +1796,7 @@ function generateJS( ast, session, options ) {
"", "",
indent2( "return " + generateParserObject() + ";" ), indent2( "return " + generateParserObject() + ";" ),
"});", "});",
"" "",
].join( "\n" ); ].join( "\n" );
}, },
@ -1816,7 +1812,7 @@ function generateJS( ast, session, options ) {
"", "",
indent2( "root." + options.exportVar + " = " + generateParserObject() + ";" ), indent2( "root." + options.exportVar + " = " + generateParserObject() + ";" ),
"})(this);", "})(this);",
"" "",
].join( "\n" ); ].join( "\n" );
}, },
@ -1843,14 +1839,14 @@ function generateJS( ast, session, options ) {
" if (typeof define === \"function\" && define.amd) {", " if (typeof define === \"function\" && define.amd) {",
" define(" + dependencies + ", factory);", " define(" + dependencies + ", factory);",
" } else if (typeof module === \"object\" && module.exports) {", " } else if (typeof module === \"object\" && module.exports) {",
" module.exports = factory(" + requires + ");" " module.exports = factory(" + requires + ");",
].join( "\n" ) ); ].join( "\n" ) );
if ( options.exportVar !== null ) { if ( options.exportVar !== null ) {
parts.push( [ parts.push( [
" } else {", " } else {",
" root." + options.exportVar + " = factory(" + args + ");" " root." + options.exportVar + " = factory(" + args + ");",
].join( "\n" ) ); ].join( "\n" ) );
} }
@ -1864,12 +1860,12 @@ function generateJS( ast, session, options ) {
"", "",
indent2( "return " + generateParserObject() + ";" ), indent2( "return " + generateParserObject() + ";" ),
"});", "});",
"" "",
].join( "\n" ) ); ].join( "\n" ) );
return parts.join( "\n" ); return parts.join( "\n" );
} },
}; };
return generators[ options.format ](); return generators[ options.format ]();

@ -159,7 +159,7 @@ function inferenceMatchResult( ast, session ) {
}, },
// |any| not match on empty input // |any| not match on empty input
any: sometimesMatch any: sometimesMatch,
} ); } );
inference( ast ); inference( ast );

@ -15,7 +15,7 @@ function removeProxyRules( ast, session, options ) {
if ( node.name === proxy ) node.name = real; if ( node.name === proxy ) node.name = real;
} },
} ); } );

@ -60,7 +60,7 @@ function reportDuplicateLabels( ast, session ) {
optional: checkExpressionWithClonedEnv, optional: checkExpressionWithClonedEnv,
zero_or_more: checkExpressionWithClonedEnv, zero_or_more: checkExpressionWithClonedEnv,
one_or_more: checkExpressionWithClonedEnv, one_or_more: checkExpressionWithClonedEnv,
group: checkExpressionWithClonedEnv group: checkExpressionWithClonedEnv,
} ); } );
check( ast ); check( ast );

@ -25,7 +25,7 @@ function reportDuplicateRules( ast, session ) {
rules[ node.name ] = node.location; rules[ node.name ] = node.location;
} },
} ); } );
check( ast ); check( ast );

@ -51,7 +51,7 @@ function reportInfiniteRecursion( ast, session ) {
check( ast.findRule( node.name ) ); check( ast.findRule( node.name ) );
} },
} ); } );
check( ast ); check( ast );

@ -29,7 +29,7 @@ function reportInfiniteRepetition( ast, session ) {
} }
} },
} ); } );
check( ast ); check( ast );

@ -15,7 +15,7 @@ function reportUndefinedRules( ast, session, options ) {
} }
} },
} ); } );
check( ast ); check( ast );

@ -28,7 +28,7 @@ const peg = {
generate( grammar, options = {} ) { generate( grammar, options = {} ) {
const session = new compiler.Session( { const session = new compiler.Session( {
passes: util.convertPasses( compiler.passes ) passes: util.convertPasses( compiler.passes ),
} ); } );
if ( Array.isArray( options.plugins ) ) if ( Array.isArray( options.plugins ) )
@ -47,7 +47,7 @@ const peg = {
options options
); );
} },
}; };
module.exports = peg; module.exports = peg;

@ -36,9 +36,10 @@ const js = {
*/ */
stringEscape( s ) { stringEscape( s ) {
return sourceEscape( s return sourceEscape(
.replace( /\\/g, "\\\\" ) // backslash s
.replace( /"/g, "\\\"" ) // closing double quote .replace( /\\/g, "\\\\" ) // backslash
.replace( /"/g, "\\\"" ) // closing double quote
); );
}, },
@ -50,12 +51,13 @@ const js = {
*/ */
regexpEscape( s ) { regexpEscape( s ) {
return sourceEscape( s return sourceEscape(
.replace( /\\/g, "\\\\" ) // backslash s
.replace( /\//g, "\\/" ) // closing slash .replace( /\\/g, "\\\\" ) // backslash
.replace( /]/g, "\\]" ) // closing bracket .replace( /\//g, "\\/" ) // closing slash
.replace( /\^/g, "\\^" ) // caret .replace( /]/g, "\\]" ) // closing bracket
.replace( /-/g, "\\-" ) // dash .replace( /\^/g, "\\^" ) // caret
.replace( /-/g, "\\-" ) // dash
); );
}, },

@ -10,7 +10,7 @@ module.exports = {
dependencies: { dependencies: {
ast: "./ast", ast: "./ast",
util: "./util" util: "./util",
}, },

@ -95,7 +95,7 @@ describe( "generated parser API", function () {
"1:1-1:1 rule.fail a", "1:1-1:1 rule.fail a",
"1:1-1:1 rule.enter b", "1:1-1:1 rule.enter b",
"1:1-1:2 rule.match b", "1:1-1:2 rule.match b",
"1:1-1:2 rule.match start" "1:1-1:2 rule.match start",
]; ];
if ( typeof console === "object" ) sinon.stub( console, "log" ); if ( typeof console === "object" ) sinon.stub( console, "log" );
@ -138,32 +138,32 @@ describe( "generated parser API", function () {
rule: "start", rule: "start",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 } end: { offset: 0, line: 1, column: 1 },
} },
}, },
{ {
type: "rule.enter", type: "rule.enter",
rule: "a", rule: "a",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 } end: { offset: 0, line: 1, column: 1 },
} },
}, },
{ {
type: "rule.fail", type: "rule.fail",
rule: "a", rule: "a",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 } end: { offset: 0, line: 1, column: 1 },
} },
}, },
{ {
type: "rule.enter", type: "rule.enter",
rule: "b", rule: "b",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 } end: { offset: 0, line: 1, column: 1 },
} },
}, },
{ {
type: "rule.match", type: "rule.match",
@ -171,8 +171,8 @@ describe( "generated parser API", function () {
result: "b", result: "b",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 1, line: 1, column: 2 } end: { offset: 1, line: 1, column: 2 },
} },
}, },
{ {
type: "rule.match", type: "rule.match",
@ -180,9 +180,9 @@ describe( "generated parser API", function () {
result: "b", result: "b",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 1, line: 1, column: 2 } end: { offset: 1, line: 1, column: 2 },
} },
} },
]; ];
const tracer = { trace: sinon.spy() }; const tracer = { trace: sinon.spy() };

@ -92,7 +92,7 @@ describe( "PEG.js API", function () {
const parser = peg.generate( grammar, { const parser = peg.generate( grammar, {
optimize: "speed", optimize: "speed",
allowedStartRules: [ "b", "c" ] allowedStartRules: [ "b", "c" ],
} ); } );
expect( () => { expect( () => {
@ -139,7 +139,7 @@ describe( "PEG.js API", function () {
const parser = peg.generate( grammar, { const parser = peg.generate( grammar, {
optimize: "size", optimize: "size",
allowedStartRules: [ "b", "c" ] allowedStartRules: [ "b", "c" ],
} ); } );
expect( () => { expect( () => {
@ -322,7 +322,7 @@ describe( "PEG.js API", function () {
peg.generate( [ peg.generate( [
"start = " + label + ":end", "start = " + label + ":end",
"end = 'a'" "end = 'a'",
].join( "\n" ), { output: "source" } ); ].join( "\n" ), { output: "source" } );
} ).to.throw( peg.parser.SyntaxError ); } ).to.throw( peg.parser.SyntaxError );
@ -343,7 +343,7 @@ describe( "PEG.js API", function () {
peg.generate( [ peg.generate( [
"start = " + rule, "start = " + rule,
rule + " = 'a'" rule + " = 'a'",
].join( "\n" ), { output: "source" } ); ].join( "\n" ), { output: "source" } );
} ).to.not.throw( peg.parser.SyntaxError ); } ).to.not.throw( peg.parser.SyntaxError );

@ -13,15 +13,15 @@ describe( "PEG.js Utility API", function () {
stage1: { stage1: {
pass1() { }, pass1() { },
pass2() { }, pass2() { },
pass3() { } pass3() { },
}, },
stage2: { stage2: {
pass1() { }, pass1() { },
pass2() { } pass2() { },
}, },
stage3: { stage3: {
pass1() { } pass1() { },
} },
}; };
function expectPasses( result ) { function expectPasses( result ) {
@ -54,12 +54,12 @@ describe( "PEG.js Utility API", function () {
stage1: [ stage1: [
passes.stage1.pass1, passes.stage1.pass1,
passes.stage1.pass2, passes.stage1.pass2,
passes.stage1.pass3 passes.stage1.pass3,
], ],
stage2: passes.stage2, stage2: passes.stage2,
stage3: [ stage3: [
passes.stage3.pass1 passes.stage3.pass1,
] ],
} ) ); } ) );
} ); } );

@ -29,7 +29,7 @@ describe( "plugin API", function () {
pluginsUsed[ 2 ] = true; pluginsUsed[ 2 ] = true;
} } } },
]; ];
peg.generate( grammar, { plugins: plugins } ); peg.generate( grammar, { plugins: plugins } );
@ -71,7 +71,7 @@ describe( "plugin API", function () {
} ); } );
} },
}; };
peg.generate( grammar, { plugins: [ plugin ] } ); peg.generate( grammar, { plugins: [ plugin ] } );
@ -86,9 +86,9 @@ describe( "plugin API", function () {
expect( options ).to.equal( generateOptions ); expect( options ).to.equal( generateOptions );
} },
} ], } ],
foo: 42 foo: 42,
}; };
peg.generate( grammar, generateOptions ); peg.generate( grammar, generateOptions );
@ -116,7 +116,7 @@ describe( "plugin API", function () {
`, { context: { ast: peg.ast } } ); `, { context: { ast: peg.ast } } );
} },
}; };
const parser = peg.generate( "a", { plugins: [ plugin ] } ); const parser = peg.generate( "a", { plugins: [ plugin ] } );
@ -137,7 +137,7 @@ describe( "plugin API", function () {
config.passes.generate = [ pass ]; config.passes.generate = [ pass ];
} },
}; };
const parser = peg.generate( grammar, { plugins: [ plugin ] } ); const parser = peg.generate( grammar, { plugins: [ plugin ] } );
@ -159,12 +159,12 @@ describe( "plugin API", function () {
options.allowedStartRules = [ "b", "c" ]; options.allowedStartRules = [ "b", "c" ];
} },
}; };
const parser = peg.generate( grammar, { const parser = peg.generate( grammar, {
allowedStartRules: [ "a" ], allowedStartRules: [ "a" ],
plugins: [ plugin ] plugins: [ plugin ],
} ); } );
expect( () => { expect( () => {

@ -18,7 +18,7 @@ describe( "generated parser behavior", function () {
{ cache: true, optimize: "speed", trace: false }, { cache: true, optimize: "speed", trace: false },
{ cache: true, optimize: "speed", trace: true }, { cache: true, optimize: "speed", trace: true },
{ cache: true, optimize: "size", trace: false }, { cache: true, optimize: "size", trace: false },
{ cache: true, optimize: "size", trace: true } { cache: true, optimize: "size", trace: true },
]; ];
optionsVariants.forEach( variant => { optionsVariants.forEach( variant => {
@ -61,8 +61,7 @@ describe( "generated parser behavior", function () {
options = typeof options !== "undefined" ? options : {}; options = typeof options !== "undefined" ? options : {};
const result = withConsoleStub( () => const result = withConsoleStub( () =>
utils.flag( this, "object" ).parse( input, options ) utils.flag( this, "object" ).parse( input, options ) );
);
if ( typeof expected !== "undefined" ) { if ( typeof expected !== "undefined" ) {
@ -88,8 +87,7 @@ describe( "generated parser behavior", function () {
try { try {
result = withConsoleStub( () => result = withConsoleStub( () =>
utils.flag( this, "object" ).parse( input, options ) utils.flag( this, "object" ).parse( input, options ) );
);
passed = true; passed = true;
} catch ( e ) { } catch ( e ) {
@ -138,7 +136,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"{ var result = 42; }", "{ var result = 42; }",
"start = 'a' { return result; }" "start = 'a' { return result; }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "a", 42 ); expect( parser ).to.parse( "a", 42 );
@ -151,7 +149,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"{ var result = options; }", "{ var result = options; }",
"start = 'a' { return result; }" "start = 'a' { return result; }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "a", { a: 42 }, { a: 42 } ); expect( parser ).to.parse( "a", { a: 42 }, { a: 42 } );
@ -171,7 +169,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"{ var n = 0; }", "{ var n = 0; }",
"start = (a 'b') / (a 'c') { return n; }", "start = (a 'b') / (a 'c') { return n; }",
"a = 'a' { n++; }" "a = 'a' { n++; }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "ac", 1 ); expect( parser ).to.parse( "ac", 1 );
@ -185,7 +183,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"{ var n = 0; }", "{ var n = 0; }",
"start = (a 'b') / (a 'c') { return n; }", "start = (a 'b') / (a 'c') { return n; }",
"a = 'a' { n++; }" "a = 'a' { n++; }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "ac", 2 ); expect( parser ).to.parse( "ac", 2 );
@ -215,7 +213,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'a'" ); const parser = peg.generate( "start = 'a'" );
expect( parser ).to.failToParse( "b", { expect( parser ).to.failToParse( "b", {
expected: [ { type: "literal", text: "a", ignoreCase: false } ] expected: [ { type: "literal", text: "a", ignoreCase: false } ],
} ); } );
} ); } );
@ -229,7 +227,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start 'start' = 'a'" ); const parser = peg.generate( "start 'start' = 'a'" );
expect( parser ).to.failToParse( "b", { expect( parser ).to.failToParse( "b", {
expected: [ { type: "other", description: "start" } ] expected: [ { type: "other", description: "start" } ],
} ); } );
} ); } );
@ -239,7 +237,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start 'start' = 'a'" ); const parser = peg.generate( "start 'start' = 'a'" );
expect( parser ).to.failToParse( "b", { expect( parser ).to.failToParse( "b", {
expected: [ { type: "other", description: "start" } ] expected: [ { type: "other", description: "start" } ],
} ); } );
} ); } );
@ -327,7 +325,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'a'", options ); const parser = peg.generate( "start = 'a'", options );
expect( parser ).to.failToParse( "b", { expect( parser ).to.failToParse( "b", {
expected: [ { type: "literal", text: "a", ignoreCase: false } ] expected: [ { type: "literal", text: "a", ignoreCase: false } ],
} ); } );
} ); } );
@ -426,7 +424,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = [a]", options ); const parser = peg.generate( "start = [a]", options );
expect( parser ).to.failToParse( "b", { expect( parser ).to.failToParse( "b", {
expected: [ { type: "class", parts: [ "a" ], inverted: false, ignoreCase: false } ] expected: [ { type: "class", parts: [ "a" ], inverted: false, ignoreCase: false } ],
} ); } );
} ); } );
@ -478,7 +476,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = .", options ); const parser = peg.generate( "start = .", options );
expect( parser ).to.failToParse( "", { expect( parser ).to.failToParse( "", {
expected: [ { type: "any" } ] expected: [ { type: "any" } ],
} ); } );
} ); } );
@ -495,7 +493,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"start = a", "start = a",
"a = 'a'" "a = 'a'",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "a", "a" ); expect( parser ).to.parse( "a", "a" );
@ -510,7 +508,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"start = a", "start = a",
"a = 'a'" "a = 'a'",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.failToParse( "b" ); expect( parser ).to.failToParse( "b" );
@ -592,48 +590,48 @@ describe( "generated parser behavior", function () {
const testcases = [ const testcases = [
{ {
grammar: "start = (a:'a') &{ return a === 'a'; }", grammar: "start = (a:'a') &{ return a === 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = (a:'a')? &{ return a === 'a'; }", grammar: "start = (a:'a')? &{ return a === 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = (a:'a')* &{ return a === 'a'; }", grammar: "start = (a:'a')* &{ return a === 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = (a:'a')+ &{ return a === 'a'; }", grammar: "start = (a:'a')+ &{ return a === 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = $(a:'a') &{ return a === 'a'; }", grammar: "start = $(a:'a') &{ return a === 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = &(a:'a') 'a' &{ return a === 'a'; }", grammar: "start = &(a:'a') 'a' &{ return a === 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = !(a:'a') 'b' &{ return a === 'a'; }", grammar: "start = !(a:'a') 'b' &{ return a === 'a'; }",
input: "b" input: "b",
}, },
{ {
grammar: "start = b:(a:'a') &{ return a === 'a'; }", grammar: "start = b:(a:'a') &{ return a === 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = ('a' b:'b' 'c') &{ return b === 'b'; }", grammar: "start = ('a' b:'b' 'c') &{ return b === 'b'; }",
input: "abc" input: "abc",
}, },
{ {
grammar: "start = (a:'a' { return a; }) &{ return a === 'a'; }", grammar: "start = (a:'a' { return a; }) &{ return a === 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = ('a' / b:'b' / 'c') &{ return b === 'b'; }", grammar: "start = ('a' / b:'b' / 'c') &{ return b === 'b'; }",
input: "b" input: "b",
} },
]; ];
testcases.forEach( testcase => { testcases.forEach( testcase => {
@ -692,7 +690,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"{ var v = 42 }", "{ var v = 42 }",
"start = &{ return v === 42; }" "start = &{ return v === 42; }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "" ); expect( parser ).to.parse( "" );
@ -703,7 +701,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"{ function f() { return 42; } }", "{ function f() { return 42; } }",
"start = &{ return f() === 42; }" "start = &{ return f() === 42; }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "" ); expect( parser ).to.parse( "" );
@ -718,7 +716,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"{ var result; }", "{ var result; }",
"start = &{ result = options; return true; } { return result; }" "start = &{ result = options; return true; } { return result; }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "", { a: 42 }, { a: 42 } ); expect( parser ).to.parse( "", { a: 42 }, { a: 42 } );
@ -734,22 +732,22 @@ describe( "generated parser behavior", function () {
"thing = digit / mark", "thing = digit / mark",
"digit = [0-9]", "digit = [0-9]",
"mark = &{ result = location(); return true; } 'x'", "mark = &{ result = location(); return true; } 'x'",
"nl = '\\r'? '\\n'" "nl = '\\r'? '\\n'",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "1\n2\n\n3\n\n\n4 5 x", { expect( parser ).to.parse( "1\n2\n\n3\n\n\n4 5 x", {
start: { offset: 13, line: 7, column: 5 }, start: { offset: 13, line: 7, column: 5 },
end: { offset: 13, line: 7, column: 5 } end: { offset: 13, line: 7, column: 5 },
} ); } );
// Newline representations // Newline representations
expect( parser ).to.parse( "1\nx", { // Unix expect( parser ).to.parse( "1\nx", { // Unix
start: { offset: 2, line: 2, column: 1 }, start: { offset: 2, line: 2, column: 1 },
end: { offset: 2, line: 2, column: 1 } end: { offset: 2, line: 2, column: 1 },
} ); } );
expect( parser ).to.parse( "1\r\nx", { // Windows expect( parser ).to.parse( "1\r\nx", { // Windows
start: { offset: 3, line: 2, column: 1 }, start: { offset: 3, line: 2, column: 1 },
end: { offset: 3, line: 2, column: 1 } end: { offset: 3, line: 2, column: 1 },
} ); } );
} ); } );
@ -758,7 +756,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"start = [0-9]+ val:mark { return val; }", "start = [0-9]+ val:mark { return val; }",
"mark = 'xx' { return offset(); }" "mark = 'xx' { return offset(); }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "0123456xx", 7 ); expect( parser ).to.parse( "0123456xx", 7 );
@ -769,7 +767,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"start = [0-9]+ val:mark { return val; }", "start = [0-9]+ val:mark { return val; }",
"mark = 'xx' { return range(); }" "mark = 'xx' { return range(); }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "0123456xx", [ 7, 9 ] ); expect( parser ).to.parse( "0123456xx", [ 7, 9 ] );
@ -851,48 +849,48 @@ describe( "generated parser behavior", function () {
const testcases = [ const testcases = [
{ {
grammar: "start = (a:'a') !{ return a !== 'a'; }", grammar: "start = (a:'a') !{ return a !== 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = (a:'a')? !{ return a !== 'a'; }", grammar: "start = (a:'a')? !{ return a !== 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = (a:'a')* !{ return a !== 'a'; }", grammar: "start = (a:'a')* !{ return a !== 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = (a:'a')+ !{ return a !== 'a'; }", grammar: "start = (a:'a')+ !{ return a !== 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = $(a:'a') !{ return a !== 'a'; }", grammar: "start = $(a:'a') !{ return a !== 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = &(a:'a') 'a' !{ return a !== 'a'; }", grammar: "start = &(a:'a') 'a' !{ return a !== 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = !(a:'a') 'b' !{ return a !== 'a'; }", grammar: "start = !(a:'a') 'b' !{ return a !== 'a'; }",
input: "b" input: "b",
}, },
{ {
grammar: "start = b:(a:'a') !{ return a !== 'a'; }", grammar: "start = b:(a:'a') !{ return a !== 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = ('a' b:'b' 'c') !{ return b !== 'b'; }", grammar: "start = ('a' b:'b' 'c') !{ return b !== 'b'; }",
input: "abc" input: "abc",
}, },
{ {
grammar: "start = (a:'a' { return a; }) !{ return a !== 'a'; }", grammar: "start = (a:'a' { return a; }) !{ return a !== 'a'; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = ('a' / b:'b' / 'c') !{ return b !== 'b'; }", grammar: "start = ('a' / b:'b' / 'c') !{ return b !== 'b'; }",
input: "b" input: "b",
} },
]; ];
testcases.forEach( testcase => { testcases.forEach( testcase => {
@ -951,7 +949,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"{ var v = 42 }", "{ var v = 42 }",
"start = !{ return v !== 42; }" "start = !{ return v !== 42; }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "" ); expect( parser ).to.parse( "" );
@ -962,7 +960,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"{ function f() { return 42; } }", "{ function f() { return 42; } }",
"start = !{ return f() !== 42; }" "start = !{ return f() !== 42; }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "" ); expect( parser ).to.parse( "" );
@ -977,7 +975,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"{ var result; }", "{ var result; }",
"start = !{ result = options; return false; } { return result; }" "start = !{ result = options; return false; } { return result; }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "", { a: 42 }, { a: 42 } ); expect( parser ).to.parse( "", { a: 42 }, { a: 42 } );
@ -993,22 +991,22 @@ describe( "generated parser behavior", function () {
"thing = digit / mark", "thing = digit / mark",
"digit = [0-9]", "digit = [0-9]",
"mark = !{ result = location(); return false; } 'x'", "mark = !{ result = location(); return false; } 'x'",
"nl = '\\r'? '\\n'" "nl = '\\r'? '\\n'",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "1\n2\n\n3\n\n\n4 5 x", { expect( parser ).to.parse( "1\n2\n\n3\n\n\n4 5 x", {
start: { offset: 13, line: 7, column: 5 }, start: { offset: 13, line: 7, column: 5 },
end: { offset: 13, line: 7, column: 5 } end: { offset: 13, line: 7, column: 5 },
} ); } );
// Newline representations // Newline representations
expect( parser ).to.parse( "1\nx", { // Unix expect( parser ).to.parse( "1\nx", { // Unix
start: { offset: 2, line: 2, column: 1 }, start: { offset: 2, line: 2, column: 1 },
end: { offset: 2, line: 2, column: 1 } end: { offset: 2, line: 2, column: 1 },
} ); } );
expect( parser ).to.parse( "1\r\nx", { // Windows expect( parser ).to.parse( "1\r\nx", { // Windows
start: { offset: 3, line: 2, column: 1 }, start: { offset: 3, line: 2, column: 1 },
end: { offset: 3, line: 2, column: 1 } end: { offset: 3, line: 2, column: 1 },
} ); } );
} ); } );
@ -1188,8 +1186,8 @@ describe( "generated parser behavior", function () {
expected: [ expected: [
{ type: "literal", text: "a", ignoreCase: false }, { type: "literal", text: "a", ignoreCase: false },
{ type: "literal", text: "b", ignoreCase: false }, { type: "literal", text: "b", ignoreCase: false },
{ type: "literal", text: "c", ignoreCase: false } { type: "literal", text: "c", ignoreCase: false },
] ],
} ); } );
} ); } );
@ -1201,8 +1199,8 @@ describe( "generated parser behavior", function () {
expect( parser ).to.failToParse( "d", { expect( parser ).to.failToParse( "d", {
expected: [ expected: [
{ type: "literal", text: "a", ignoreCase: false }, { type: "literal", text: "a", ignoreCase: false },
{ type: "literal", text: "b", ignoreCase: false } { type: "literal", text: "b", ignoreCase: false },
] ],
} ); } );
} ); } );
@ -1251,8 +1249,8 @@ describe( "generated parser behavior", function () {
expected: [ expected: [
{ type: "literal", text: "a", ignoreCase: false }, { type: "literal", text: "a", ignoreCase: false },
{ type: "not", expected: { type: "literal", text: "b", ignoreCase: false } }, { type: "not", expected: { type: "literal", text: "b", ignoreCase: false } },
{ type: "literal", text: "c", ignoreCase: false } { type: "literal", text: "c", ignoreCase: false },
] ],
} ); } );
} ); } );
@ -1264,8 +1262,8 @@ describe( "generated parser behavior", function () {
expect( parser ).to.failToParse( "b", { expect( parser ).to.failToParse( "b", {
expected: [ expected: [
{ type: "literal", text: "a", ignoreCase: false }, { type: "literal", text: "a", ignoreCase: false },
{ type: "not", expected: { type: "literal", text: "b", ignoreCase: false } } { type: "not", expected: { type: "literal", text: "b", ignoreCase: false } },
] ],
} ); } );
} ); } );
@ -1276,8 +1274,8 @@ describe( "generated parser behavior", function () {
expect( parser ).to.failToParse( "b", { expect( parser ).to.failToParse( "b", {
expected: [ expected: [
{ type: "literal", text: "a", ignoreCase: false } { type: "literal", text: "a", ignoreCase: false },
] ],
} ); } );
} ); } );
@ -1337,7 +1335,7 @@ describe( "generated parser behavior", function () {
{ {
grammar: "start = 'a' 'b' 'c'", grammar: "start = 'a' 'b' 'c'",
input: "abc", input: "abc",
output: [ "a", "b", "c" ] output: [ "a", "b", "c" ],
}, },
] ); ] );
@ -1345,42 +1343,42 @@ describe( "generated parser behavior", function () {
{ {
grammar: "start = @'a'", grammar: "start = @'a'",
input: "a", input: "a",
output: "a" output: "a",
}, },
{ {
grammar: "start = @'a' / @'b'", grammar: "start = @'a' / @'b'",
input: "a", input: "a",
output: "a" output: "a",
}, },
{ {
grammar: "start = @'a' / @'b'", grammar: "start = @'a' / @'b'",
input: "b", input: "b",
output: "b" output: "b",
}, },
{ {
grammar: "start = 'a' @'b' 'c'", grammar: "start = 'a' @'b' 'c'",
input: "abc", input: "abc",
output: "b" output: "b",
}, },
{ {
grammar: "start = 'a' ( @'b' 'c' )", grammar: "start = 'a' ( @'b' 'c' )",
input: "abc", input: "abc",
output: [ "a", "b" ] output: [ "a", "b" ],
}, },
{ {
grammar: "start = 'a' @( 'b' @'c' 'd' )", grammar: "start = 'a' @( 'b' @'c' 'd' )",
input: "abcd", input: "abcd",
output: "c" output: "c",
}, },
{ {
grammar: "start = 'a' ( @'b' 'c' ) @'d'", grammar: "start = 'a' ( @'b' 'c' ) @'d'",
input: "abcd", input: "abcd",
output: "d" output: "d",
}, },
{ {
grammar: "start = 'a' @'b' 'c' / 'd' 'e' @'f'", grammar: "start = 'a' @'b' 'c' / 'd' 'e' @'f'",
input: "def", input: "def",
output: "f" output: "f",
}, },
] ); ] );
@ -1388,27 +1386,27 @@ describe( "generated parser behavior", function () {
{ {
grammar: "start = 'a' @'b' @'c'", grammar: "start = 'a' @'b' @'c'",
input: "abc", input: "abc",
output: [ "b", "c" ] output: [ "b", "c" ],
}, },
{ {
grammar: "start = 'a' ( @'b' @'c' )", grammar: "start = 'a' ( @'b' @'c' )",
input: "abc", input: "abc",
output: [ "a", [ "b", "c" ] ] output: [ "a", [ "b", "c" ] ],
}, },
{ {
grammar: "start = 'a' @( 'b' @'c' @'d' )", grammar: "start = 'a' @( 'b' @'c' @'d' )",
input: "abcd", input: "abcd",
output: [ "c", "d" ] output: [ "c", "d" ],
}, },
{ {
grammar: "start = 'a' @( @'b' 'c' ) @'d' 'e'", grammar: "start = 'a' @( @'b' 'c' ) @'d' 'e'",
input: "abcde", input: "abcde",
output: [ "b", "d" ] output: [ "b", "d" ],
}, },
{ {
grammar: "start = 'a' @'b' 'c' / @'d' 'e' @'f'", grammar: "start = 'a' @'b' 'c' / @'d' 'e' @'f'",
input: "def", input: "def",
output: [ "d", "f" ] output: [ "d", "f" ],
}, },
] ); ] );
@ -1416,17 +1414,17 @@ describe( "generated parser behavior", function () {
{ {
grammar: "start = @'a' &{ return true; }", grammar: "start = @'a' &{ return true; }",
input: "a", input: "a",
output: "a" output: "a",
}, },
{ {
grammar: "start = @'a' !{ return false; }", grammar: "start = @'a' !{ return false; }",
input: "a", input: "a",
output: "a" output: "a",
}, },
{ {
grammar: "start = @n:[0-9] &{ return n > 0; }", grammar: "start = @n:[0-9] &{ return n > 0; }",
input: "2", input: "2",
output: "2" output: "2",
}, },
] ); ] );
@ -1496,48 +1494,48 @@ describe( "generated parser behavior", function () {
const testcases = [ const testcases = [
{ {
grammar: "start = (a:'a') { return a; }", grammar: "start = (a:'a') { return a; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = (a:'a')? { return a; }", grammar: "start = (a:'a')? { return a; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = (a:'a')* { return a; }", grammar: "start = (a:'a')* { return a; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = (a:'a')+ { return a; }", grammar: "start = (a:'a')+ { return a; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = $(a:'a') { return a; }", grammar: "start = $(a:'a') { return a; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = &(a:'a') 'a' { return a; }", grammar: "start = &(a:'a') 'a' { return a; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = !(a:'a') 'b' { return a; }", grammar: "start = !(a:'a') 'b' { return a; }",
input: "b" input: "b",
}, },
{ {
grammar: "start = b:(a:'a') { return a; }", grammar: "start = b:(a:'a') { return a; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = ('a' b:'b' 'c') { return b; }", grammar: "start = ('a' b:'b' 'c') { return b; }",
input: "abc" input: "abc",
}, },
{ {
grammar: "start = (a:'a' { return a; }) { return a; }", grammar: "start = (a:'a' { return a; }) { return a; }",
input: "a" input: "a",
}, },
{ {
grammar: "start = ('a' / b:'b' / 'c') { return b; }", grammar: "start = ('a' / b:'b' / 'c') { return b; }",
input: "b" input: "b",
} },
]; ];
testcases.forEach( testcase => { testcases.forEach( testcase => {
@ -1596,7 +1594,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"{ var v = 42 }", "{ var v = 42 }",
"start = 'a' { return v; }" "start = 'a' { return v; }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "a", 42 ); expect( parser ).to.parse( "a", 42 );
@ -1607,7 +1605,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"{ function f() { return 42; } }", "{ function f() { return 42; } }",
"start = 'a' { return f(); }" "start = 'a' { return f(); }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "a", 42 ); expect( parser ).to.parse( "a", 42 );
@ -1649,22 +1647,22 @@ describe( "generated parser behavior", function () {
"thing = digit / mark", "thing = digit / mark",
"digit = [0-9]", "digit = [0-9]",
"mark = 'x' { result = location(); }", "mark = 'x' { result = location(); }",
"nl = '\\r'? '\\n'" "nl = '\\r'? '\\n'",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "1\n2\n\n3\n\n\n4 5 x", { expect( parser ).to.parse( "1\n2\n\n3\n\n\n4 5 x", {
start: { offset: 13, line: 7, column: 5 }, start: { offset: 13, line: 7, column: 5 },
end: { offset: 14, line: 7, column: 6 } end: { offset: 14, line: 7, column: 6 },
} ); } );
// Newline representations // Newline representations
expect( parser ).to.parse( "1\nx", { // Unix expect( parser ).to.parse( "1\nx", { // Unix
start: { offset: 2, line: 2, column: 1 }, start: { offset: 2, line: 2, column: 1 },
end: { offset: 3, line: 2, column: 2 } end: { offset: 3, line: 2, column: 2 },
} ); } );
expect( parser ).to.parse( "1\r\nx", { // Windows expect( parser ).to.parse( "1\r\nx", { // Windows
start: { offset: 3, line: 2, column: 1 }, start: { offset: 3, line: 2, column: 1 },
end: { offset: 4, line: 2, column: 2 } end: { offset: 4, line: 2, column: 2 },
} ); } );
} ); } );
@ -1684,8 +1682,8 @@ describe( "generated parser behavior", function () {
found: "a", found: "a",
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 1, line: 1, column: 2 } end: { offset: 1, line: 1, column: 2 },
} },
} ); } );
} ); } );
@ -1698,7 +1696,7 @@ describe( "generated parser behavior", function () {
" start: { offset: 1, line: 1, column: 2 },", " start: { offset: 1, line: 1, column: 2 },",
" end: { offset: 2, line: 1, column: 3 }", " end: { offset: 2, line: 1, column: 3 }",
" });", " });",
"}" "}",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.failToParse( "a", { expect( parser ).to.failToParse( "a", {
@ -1707,8 +1705,8 @@ describe( "generated parser behavior", function () {
found: "a", found: "a",
location: { location: {
start: { offset: 1, line: 1, column: 2 }, start: { offset: 1, line: 1, column: 2 },
end: { offset: 2, line: 1, column: 3 } end: { offset: 2, line: 1, column: 3 },
} },
} ); } );
} ); } );
@ -1730,8 +1728,8 @@ describe( "generated parser behavior", function () {
expected: null, expected: null,
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 1, line: 1, column: 2 } end: { offset: 1, line: 1, column: 2 },
} },
} ); } );
} ); } );
@ -1744,7 +1742,7 @@ describe( "generated parser behavior", function () {
" start: { offset: 1, line: 1, column: 2 },", " start: { offset: 1, line: 1, column: 2 },",
" end: { offset: 2, line: 1, column: 3 }", " end: { offset: 2, line: 1, column: 3 }",
" });", " });",
"}" "}",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.failToParse( "a", { expect( parser ).to.failToParse( "a", {
@ -1753,8 +1751,8 @@ describe( "generated parser behavior", function () {
found: null, found: null,
location: { location: {
start: { offset: 1, line: 1, column: 2 }, start: { offset: 1, line: 1, column: 2 },
end: { offset: 2, line: 1, column: 3 } end: { offset: 2, line: 1, column: 3 },
} },
} ); } );
} ); } );
@ -1829,7 +1827,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'a' 'b' / 'a' 'c' 'd'", options ); const parser = peg.generate( "start = 'a' 'b' / 'a' 'c' 'd'", options );
expect( parser ).to.failToParse( "ace", { expect( parser ).to.failToParse( "ace", {
expected: [ { type: "literal", text: "d", ignoreCase: false } ] expected: [ { type: "literal", text: "d", ignoreCase: false } ],
} ); } );
} ); } );
@ -1843,7 +1841,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'a'", options ); const parser = peg.generate( "start = 'a'", options );
expect( parser ).to.failToParse( "ab", { expect( parser ).to.failToParse( "ab", {
expected: [ { type: "end" } ] expected: [ { type: "end" } ],
} ); } );
} ); } );
@ -1853,7 +1851,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'a'", options ); const parser = peg.generate( "start = 'a'", options );
expect( parser ).to.failToParse( "b", { expect( parser ).to.failToParse( "b", {
expected: [ { type: "literal", text: "a", ignoreCase: false } ] expected: [ { type: "literal", text: "a", ignoreCase: false } ],
} ); } );
} ); } );
@ -1866,8 +1864,8 @@ describe( "generated parser behavior", function () {
expected: [ expected: [
{ type: "literal", text: "a", ignoreCase: false }, { type: "literal", text: "a", ignoreCase: false },
{ type: "literal", text: "b", ignoreCase: false }, { type: "literal", text: "b", ignoreCase: false },
{ type: "literal", text: "c", ignoreCase: false } { type: "literal", text: "c", ignoreCase: false },
] ],
} ); } );
} ); } );
@ -1878,15 +1876,15 @@ describe( "generated parser behavior", function () {
let parser = peg.generate( [ let parser = peg.generate( [
"Statement = '{' __ !Statement Statement __ '}'", "Statement = '{' __ !Statement Statement __ '}'",
"__ = [ ]*" "__ = [ ]*",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.failToParse( "{x}", { expect( parser ).to.failToParse( "{x}", {
expected: [ expected: [
{ type: "class", parts: [ " " ], inverted: false, ignoreCase: false }, { type: "class", parts: [ " " ], inverted: false, ignoreCase: false },
{ type: "not", expected: { type: "literal", text: "{", ignoreCase: false } }, { type: "not", expected: { type: "literal", text: "{", ignoreCase: false } },
{ type: "literal", text: "{", ignoreCase: false } { type: "literal", text: "{", ignoreCase: false },
] ],
} ); } );
// Case 2, by https://github.com/nikku // Case 2, by https://github.com/nikku
@ -1894,14 +1892,14 @@ describe( "generated parser behavior", function () {
parser = peg.generate( [ parser = peg.generate( [
"Start = Char+ End", "Start = Char+ End",
"End = 'e'", "End = 'e'",
"Char = !End [a-z]" "Char = !End [a-z]",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.failToParse( "a", { expect( parser ).to.failToParse( "a", {
expected: [ expected: [
{ type: "class", parts: [ [ "a", "z" ] ], inverted: false, ignoreCase: false }, { type: "class", parts: [ [ "a", "z" ] ], inverted: false, ignoreCase: false },
{ type: "literal", text: "e", ignoreCase: false } { type: "literal", text: "e", ignoreCase: false },
] ],
} ); } );
} ); } );
@ -1911,14 +1909,14 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"Start = Char+ End", "Start = Char+ End",
"End 'end' = 'e'", "End 'end' = 'e'",
"Char = !End [a-z]" "Char = !End [a-z]",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.failToParse( "a", { expect( parser ).to.failToParse( "a", {
expected: [ expected: [
{ type: "class", parts: [ [ "a", "z" ] ], inverted: false, ignoreCase: false }, { type: "class", parts: [ [ "a", "z" ] ], inverted: false, ignoreCase: false },
{ type: "other", description: "end" } { type: "other", description: "end" },
] ],
} ); } );
} ); } );
@ -1952,7 +1950,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'a'", options ); const parser = peg.generate( "start = 'a'", options );
expect( parser ).to.failToParse( "ab", { expect( parser ).to.failToParse( "ab", {
message: "Expected end of input but \"b\" found." message: "Expected end of input but \"b\" found.",
} ); } );
} ); } );
@ -1962,7 +1960,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'a'", options ); const parser = peg.generate( "start = 'a'", options );
expect( parser ).to.failToParse( "b", { expect( parser ).to.failToParse( "b", {
message: "Expected \"a\" but \"b\" found." message: "Expected \"a\" but \"b\" found.",
} ); } );
} ); } );
@ -1972,7 +1970,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'a' / 'b' / 'c'", options ); const parser = peg.generate( "start = 'a' / 'b' / 'c'", options );
expect( parser ).to.failToParse( "d", { expect( parser ).to.failToParse( "d", {
message: "Expected \"a\", \"b\", or \"c\" but \"d\" found." message: "Expected \"a\", \"b\", or \"c\" but \"d\" found.",
} ); } );
} ); } );
@ -1982,7 +1980,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'a'", options ); const parser = peg.generate( "start = 'a'", options );
expect( parser ).to.failToParse( "", { expect( parser ).to.failToParse( "", {
message: "Expected \"a\" but end of input found." message: "Expected \"a\" but end of input found.",
} ); } );
} ); } );
@ -1992,7 +1990,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'a'", options ); const parser = peg.generate( "start = 'a'", options );
expect( parser ).to.failToParse( "b", { expect( parser ).to.failToParse( "b", {
message: "Expected \"a\" but \"b\" found." message: "Expected \"a\" but \"b\" found.",
} ); } );
} ); } );
@ -2002,7 +2000,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'a' / 'a'", options ); const parser = peg.generate( "start = 'a' / 'a'", options );
expect( parser ).to.failToParse( "b", { expect( parser ).to.failToParse( "b", {
message: "Expected \"a\" but \"b\" found." message: "Expected \"a\" but \"b\" found.",
} ); } );
} ); } );
@ -2012,7 +2010,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'c' / 'b' / 'a'", options ); const parser = peg.generate( "start = 'c' / 'b' / 'a'", options );
expect( parser ).to.failToParse( "d", { expect( parser ).to.failToParse( "d", {
message: "Expected \"a\", \"b\", or \"c\" but \"d\" found." message: "Expected \"a\", \"b\", or \"c\" but \"d\" found.",
} ); } );
} ); } );
@ -2028,8 +2026,8 @@ describe( "generated parser behavior", function () {
expect( parser ).to.failToParse( "", { expect( parser ).to.failToParse( "", {
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 } end: { offset: 0, line: 1, column: 1 },
} },
} ); } );
} ); } );
@ -2041,8 +2039,8 @@ describe( "generated parser behavior", function () {
expect( parser ).to.failToParse( "b", { expect( parser ).to.failToParse( "b", {
location: { location: {
start: { offset: 0, line: 1, column: 1 }, start: { offset: 0, line: 1, column: 1 },
end: { offset: 1, line: 1, column: 2 } end: { offset: 1, line: 1, column: 2 },
} },
} ); } );
} ); } );
@ -2054,8 +2052,8 @@ describe( "generated parser behavior", function () {
expect( parser ).to.failToParse( "aa", { expect( parser ).to.failToParse( "aa", {
location: { location: {
start: { offset: 1, line: 1, column: 2 }, start: { offset: 1, line: 1, column: 2 },
end: { offset: 2, line: 1, column: 3 } end: { offset: 2, line: 1, column: 3 },
} },
} ); } );
} ); } );
@ -2066,28 +2064,28 @@ describe( "generated parser behavior", function () {
"start = line (nl+ line)*", "start = line (nl+ line)*",
"line = digit (' '+ digit)*", "line = digit (' '+ digit)*",
"digit = [0-9]", "digit = [0-9]",
"nl = '\\r'? '\\n'" "nl = '\\r'? '\\n'",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.failToParse( "1\n2\n\n3\n\n\n4 5 x", { expect( parser ).to.failToParse( "1\n2\n\n3\n\n\n4 5 x", {
location: { location: {
start: { offset: 13, line: 7, column: 5 }, start: { offset: 13, line: 7, column: 5 },
end: { offset: 14, line: 7, column: 6 } end: { offset: 14, line: 7, column: 6 },
} },
} ); } );
// Newline representations // Newline representations
expect( parser ).to.failToParse( "1\nx", { // Old Mac expect( parser ).to.failToParse( "1\nx", { // Old Mac
location: { location: {
start: { offset: 2, line: 2, column: 1 }, start: { offset: 2, line: 2, column: 1 },
end: { offset: 3, line: 2, column: 2 } end: { offset: 3, line: 2, column: 2 },
} },
} ); } );
expect( parser ).to.failToParse( "1\r\nx", { // Windows expect( parser ).to.failToParse( "1\r\nx", { // Windows
location: { location: {
start: { offset: 3, line: 2, column: 1 }, start: { offset: 3, line: 2, column: 1 },
end: { offset: 4, line: 2, column: 2 } end: { offset: 4, line: 2, column: 2 },
} },
} ); } );
} ); } );
@ -2121,7 +2119,7 @@ describe( "generated parser behavior", function () {
" }, head);", " }, head);",
" }", " }",
"Value = digits:[0-9]+ { return parseInt(digits.join(''), 10); }", "Value = digits:[0-9]+ { return parseInt(digits.join(''), 10); }",
" / '(' expr:Expr ')' { return expr; }" " / '(' expr:Expr ')' { return expr; }",
].join( "\n" ), options ); ].join( "\n" ), options );
// The "value" rule // The "value" rule
@ -2162,7 +2160,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [ const parser = peg.generate( [
"S = &(A 'c') a:'a'+ B:B !('a' / 'b' / 'c') { return a.join('') + B; }", "S = &(A 'c') a:'a'+ B:B !('a' / 'b' / 'c') { return a.join('') + B; }",
"A = a:'a' A:A? b:'b' { return [a, A, b].join(''); }", "A = a:'a' A:A? b:'b' { return [a, A, b].join(''); }",
"B = b:'b' B:B? c:'c' { return [b, B, c].join(''); }" "B = b:'b' B:B? c:'c' { return [b, B, c].join(''); }",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "abc", "abc" ); expect( parser ).to.parse( "abc", "abc" );
@ -2189,7 +2187,7 @@ describe( "generated parser behavior", function () {
" / !Begin !End z:Z { return z; }", " / !Begin !End z:Z { return z; }",
"Z = .", "Z = .",
"Begin = '(*'", "Begin = '(*'",
"End = '*)'" "End = '*)'",
].join( "\n" ), options ); ].join( "\n" ), options );
expect( parser ).to.parse( "(**)", "(**)" ); expect( parser ).to.parse( "(**)", "(**)" );

@ -1,3 +1,5 @@
/* globals mocha */
"use strict"; "use strict";
/* /*

@ -1,3 +1,5 @@
/* eslint-disable function-call-argument-newline */
"use strict"; "use strict";
const chai = require( "chai" ); const chai = require( "chai" );
@ -13,7 +15,7 @@ describe( "compiler pass |generateBytecode|", function () {
function bytecodeDetails( bytecode ) { function bytecodeDetails( bytecode ) {
return { return {
rules: [ { bytecode: bytecode } ] rules: [ { bytecode: bytecode } ],
}; };
} }
@ -24,7 +26,7 @@ describe( "compiler pass |generateBytecode|", function () {
literals: literals, literals: literals,
classes: classes, classes: classes,
expectations: expectations, expectations: expectations,
functions: functions functions: functions,
}; };
} }
@ -36,13 +38,13 @@ describe( "compiler pass |generateBytecode|", function () {
expect( pass ).to.changeAST( [ expect( pass ).to.changeAST( [
"a = 'a'", "a = 'a'",
"b = 'b'", "b = 'b'",
"c = 'c'" "c = 'c'",
].join( "\n" ), { ].join( "\n" ), {
rules: [ rules: [
{ bytecode: [ 23, 0, 18, 0, 2, 1, 22, 0, 3 ] }, { bytecode: [ 23, 0, 18, 0, 2, 1, 22, 0, 3 ] },
{ bytecode: [ 23, 1, 18, 1, 2, 1, 22, 1, 3 ] }, { bytecode: [ 23, 1, 18, 1, 2, 1, 22, 1, 3 ] },
{ bytecode: [ 23, 2, 18, 2, 2, 1, 22, 2, 3 ] } { bytecode: [ 23, 2, 18, 2, 2, 1, 22, 2, 3 ] },
] ],
} ); } );
} ); } );
@ -52,14 +54,14 @@ describe( "compiler pass |generateBytecode|", function () {
expect( pass ).to.changeAST( [ expect( pass ).to.changeAST( [
"a = 'a'", "a = 'a'",
"b = 'b'", "b = 'b'",
"c = 'c'" "c = 'c'",
].join( "\n" ), constsDetails( ].join( "\n" ), constsDetails(
[ "a", "b", "c" ], [ "a", "b", "c" ],
[], [],
[ [
{ type: "literal", value: "a", ignoreCase: false }, { type: "literal", value: "a", ignoreCase: false },
{ type: "literal", value: "b", ignoreCase: false }, { type: "literal", value: "b", ignoreCase: false },
{ type: "literal", value: "c", ignoreCase: false } { type: "literal", value: "c", ignoreCase: false },
], ],
[] []
) ); ) );
@ -73,7 +75,7 @@ describe( "compiler pass |generateBytecode|", function () {
it( "generates correct bytecode", function () { it( "generates correct bytecode", function () {
expect( pass ).to.changeAST( "start = 'a'", bytecodeDetails( [ expect( pass ).to.changeAST( "start = 'a'", bytecodeDetails( [
23, 0, 18, 0, 2, 1, 22, 0, 3 // <expression> 23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
] ) ); ] ) );
} ); } );
@ -94,19 +96,19 @@ describe( "compiler pass |generateBytecode|", function () {
23, 0, // EXPECT <0> 23, 0, // EXPECT <0>
28, // SILENT_FAILS_ON 28, // SILENT_FAILS_ON
17, 2, 1, 21, 1, 3, // <expression> 17, 2, 1, 21, 1, 3, // <expression>
29 // SILENT_FAILS_OFF 29, // SILENT_FAILS_OFF
] ) ); ] ) );
expect( pass ).to.changeAST( grammar2, bytecodeDetails( [ expect( pass ).to.changeAST( grammar2, bytecodeDetails( [
23, 0, // EXPECT <0> 23, 0, // EXPECT <0>
28, // SILENT_FAILS_ON 28, // SILENT_FAILS_ON
18, 0, 2, 1, 22, 0, 3, // <expression> 18, 0, 2, 1, 22, 0, 3, // <expression>
29 // SILENT_FAILS_OFF 29, // SILENT_FAILS_OFF
] ) ); ] ) );
expect( pass ).to.changeAST( grammar3, bytecodeDetails( [ expect( pass ).to.changeAST( grammar3, bytecodeDetails( [
23, 0, // EXPECT <0> 23, 0, // EXPECT <0>
28, // SILENT_FAILS_ON 28, // SILENT_FAILS_ON
20, 0, 2, 1, 21, 1, 3, // <expression> 20, 0, 2, 1, 21, 1, 3, // <expression>
29 // SILENT_FAILS_OFF 29, // SILENT_FAILS_OFF
] ) ); ] ) );
} ); } );
@ -154,15 +156,9 @@ describe( "compiler pass |generateBytecode|", function () {
it( "defines correct constants", function () { it( "defines correct constants", function () {
expect( pass ).to.changeAST( grammar1, constsDetails( expect( pass ).to.changeAST( grammar1, constsDetails( [], [], [], [] ), {}, { reportFailures: false } );
[], [], [], [] expect( pass ).to.changeAST( grammar2, constsDetails( [ "a" ], [], [], [] ), {}, { reportFailures: false } );
), {}, { reportFailures: false } ); expect( pass ).to.changeAST( grammar3, constsDetails( [], [ { value: [ "a" ], inverted: false, ignoreCase: false } ], [], [] ), {}, { reportFailures: false } );
expect( pass ).to.changeAST( grammar2, constsDetails(
[ "a" ], [], [], []
), {}, { reportFailures: false } );
expect( pass ).to.changeAST( grammar3, constsDetails(
[], [ { value: [ "a" ], inverted: false, ignoreCase: false } ], [], []
), {}, { reportFailures: false } );
} ); } );
@ -181,7 +177,7 @@ describe( "compiler pass |generateBytecode|", function () {
23, 1, 18, 1, 2, 1, 22, 1, 3, // <alternatives[1]> 23, 1, 18, 1, 2, 1, 22, 1, 3, // <alternatives[1]>
14, 10, 0, // IF_ERROR 14, 10, 0, // IF_ERROR
6, // * POP 6, // * POP
23, 2, 18, 2, 2, 1, 22, 2, 3 // <alternatives[2]> 23, 2, 18, 2, 2, 1, 22, 2, 3, // <alternatives[2]>
] ) ); ] ) );
} ); } );
@ -202,7 +198,7 @@ describe( "compiler pass |generateBytecode|", function () {
15, 6, 0, // IF_NOT_ERROR 15, 6, 0, // IF_NOT_ERROR
24, 1, // * LOAD_SAVED_POS 24, 1, // * LOAD_SAVED_POS
26, 0, 1, 0, // CALL <0> 26, 0, 1, 0, // CALL <0>
9 // NIP 9, // NIP
] ) ); ] ) );
} ); } );
@ -232,7 +228,7 @@ describe( "compiler pass |generateBytecode|", function () {
15, 7, 0, // IF_NOT_ERROR 15, 7, 0, // IF_NOT_ERROR
24, 1, // * LOAD_SAVED_POS 24, 1, // * LOAD_SAVED_POS
26, 0, 1, 1, 0, // CALL <0> 26, 0, 1, 1, 0, // CALL <0>
9 // NIP 9, // NIP
] ) ); ] ) );
} ); } );
@ -274,7 +270,7 @@ describe( "compiler pass |generateBytecode|", function () {
3, // PUSH_FAILED 3, // PUSH_FAILED
6, // * POP 6, // * POP
7, // POP_CURR_POS 7, // POP_CURR_POS
3 // PUSH_FAILED 3, // PUSH_FAILED
] ) ); ] ) );
} ); } );
@ -287,7 +283,7 @@ describe( "compiler pass |generateBytecode|", function () {
[ [
{ type: "literal", value: "a", ignoreCase: false }, { type: "literal", value: "a", ignoreCase: false },
{ type: "literal", value: "b", ignoreCase: false }, { type: "literal", value: "b", ignoreCase: false },
{ type: "literal", value: "c", ignoreCase: false } { type: "literal", value: "c", ignoreCase: false },
], ],
[ { predicate: false, params: [ "a", "b", "c" ], body: " code " } ] [ { predicate: false, params: [ "a", "b", "c" ], body: " code " } ]
) ); ) );
@ -322,7 +318,7 @@ describe( "compiler pass |generateBytecode|", function () {
3, // PUSH_FAILED 3, // PUSH_FAILED
6, // * POP 6, // * POP
7, // POP_CURR_POS 7, // POP_CURR_POS
3 // PUSH_FAILED 3, // PUSH_FAILED
] ) ); ] ) );
} ); } );
@ -335,7 +331,7 @@ describe( "compiler pass |generateBytecode|", function () {
[ [
{ type: "literal", value: "a", ignoreCase: false }, { type: "literal", value: "a", ignoreCase: false },
{ type: "literal", value: "b", ignoreCase: false }, { type: "literal", value: "b", ignoreCase: false },
{ type: "literal", value: "c", ignoreCase: false } { type: "literal", value: "c", ignoreCase: false },
], ],
[] []
) ); ) );
@ -393,7 +389,7 @@ describe( "compiler pass |generateBytecode|", function () {
it( "generates correct bytecode", function () { it( "generates correct bytecode", function () {
expect( pass ).to.changeAST( "start = a:'a'", bytecodeDetails( [ expect( pass ).to.changeAST( "start = a:'a'", bytecodeDetails( [
23, 0, 18, 0, 2, 1, 22, 0, 3 // <expression> 23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
] ) ); ] ) );
} ); } );
@ -410,7 +406,7 @@ describe( "compiler pass |generateBytecode|", function () {
15, 2, 1, // IF_NOT_ERROR 15, 2, 1, // IF_NOT_ERROR
6, // * POP 6, // * POP
12, // TEXT 12, // TEXT
9 // * NIP 9, // * NIP
] ) ); ] ) );
} ); } );
@ -434,7 +430,7 @@ describe( "compiler pass |generateBytecode|", function () {
1, // PUSH_UNDEFINED 1, // PUSH_UNDEFINED
6, // * POP 6, // * POP
6, // POP 6, // POP
3 // PUSH_FAILED 3, // PUSH_FAILED
] ) ); ] ) );
} ); } );
@ -469,7 +465,7 @@ describe( "compiler pass |generateBytecode|", function () {
1, // PUSH_UNDEFINED 1, // PUSH_UNDEFINED
6, // * POP 6, // * POP
7, // POP_CURR_POS 7, // POP_CURR_POS
3 // PUSH_FAILED 3, // PUSH_FAILED
] ) ); ] ) );
} ); } );
@ -497,7 +493,7 @@ describe( "compiler pass |generateBytecode|", function () {
23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression> 23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
14, 2, 0, // IF_ERROR 14, 2, 0, // IF_ERROR
6, // * POP 6, // * POP
2 // PUSH_NULL 2, // PUSH_NULL
] ) ); ] ) );
} ); } );
@ -527,7 +523,7 @@ describe( "compiler pass |generateBytecode|", function () {
16, 10, // WHILE_NOT_ERROR 16, 10, // WHILE_NOT_ERROR
10, // * APPEND 10, // * APPEND
23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression> 23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
6 // POP 6, // POP
] ) ); ] ) );
} ); } );
@ -561,7 +557,7 @@ describe( "compiler pass |generateBytecode|", function () {
6, // POP 6, // POP
6, // * POP 6, // * POP
6, // POP 6, // POP
3 // PUSH_FAILED 3, // PUSH_FAILED
] ) ); ] ) );
} ); } );
@ -586,7 +582,7 @@ describe( "compiler pass |generateBytecode|", function () {
it( "generates correct bytecode", function () { it( "generates correct bytecode", function () {
expect( pass ).to.changeAST( grammar, bytecodeDetails( [ expect( pass ).to.changeAST( grammar, bytecodeDetails( [
23, 0, 18, 0, 2, 1, 22, 0, 3 // <expression> 23, 0, 18, 0, 2, 1, 22, 0, 3, // <expression>
] ) ); ] ) );
} ); } );
@ -619,7 +615,7 @@ describe( "compiler pass |generateBytecode|", function () {
6, // * POP 6, // * POP
1, // PUSH_UNDEFINED 1, // PUSH_UNDEFINED
6, // * POP 6, // * POP
3 // PUSH_FAILED 3, // PUSH_FAILED
] ) ); ] ) );
} ); } );
@ -670,7 +666,7 @@ describe( "compiler pass |generateBytecode|", function () {
3, // PUSH_FAILED 3, // PUSH_FAILED
6, // * POP 6, // * POP
7, // POP_CURR_POS 7, // POP_CURR_POS
3 // PUSH_FAILED 3, // PUSH_FAILED
] ) ); ] ) );
} ); } );
@ -683,7 +679,7 @@ describe( "compiler pass |generateBytecode|", function () {
[ [
{ type: "literal", value: "a", ignoreCase: false }, { type: "literal", value: "a", ignoreCase: false },
{ type: "literal", value: "b", ignoreCase: false }, { type: "literal", value: "b", ignoreCase: false },
{ type: "literal", value: "c", ignoreCase: false } { type: "literal", value: "c", ignoreCase: false },
], ],
[ { predicate: true, params: [ "a", "b", "c" ], body: " code " } ] [ { predicate: true, params: [ "a", "b", "c" ], body: " code " } ]
) ); ) );
@ -709,7 +705,7 @@ describe( "compiler pass |generateBytecode|", function () {
6, // * POP 6, // * POP
3, // PUSH_FAILED 3, // PUSH_FAILED
6, // * POP 6, // * POP
1 // PUSH_UNDEFINED 1, // PUSH_UNDEFINED
] ) ); ] ) );
} ); } );
@ -760,7 +756,7 @@ describe( "compiler pass |generateBytecode|", function () {
3, // PUSH_FAILED 3, // PUSH_FAILED
6, // * POP 6, // * POP
7, // POP_CURR_POS 7, // POP_CURR_POS
3 // PUSH_FAILED 3, // PUSH_FAILED
] ) ); ] ) );
} ); } );
@ -773,7 +769,7 @@ describe( "compiler pass |generateBytecode|", function () {
[ [
{ type: "literal", value: "a", ignoreCase: false }, { type: "literal", value: "a", ignoreCase: false },
{ type: "literal", value: "b", ignoreCase: false }, { type: "literal", value: "b", ignoreCase: false },
{ type: "literal", value: "c", ignoreCase: false } { type: "literal", value: "c", ignoreCase: false },
], ],
[ { predicate: true, params: [ "a", "b", "c" ], body: " code " } ] [ { predicate: true, params: [ "a", "b", "c" ], body: " code " } ]
) ); ) );
@ -790,14 +786,14 @@ describe( "compiler pass |generateBytecode|", function () {
expect( pass ).to.changeAST( [ expect( pass ).to.changeAST( [
"start = other", "start = other",
"other = 'other'" "other = 'other'",
].join( "\n" ), { ].join( "\n" ), {
rules: [ rules: [
{ {
bytecode: [ 27, 1 ] // RULE bytecode: [ 27, 1 ], // RULE
}, },
{ } { },
] ],
} ); } );
} ); } );
@ -815,7 +811,7 @@ describe( "compiler pass |generateBytecode|", function () {
it( "generates correct bytecode", function () { it( "generates correct bytecode", function () {
expect( pass ).to.changeAST( grammar, bytecodeDetails( [ expect( pass ).to.changeAST( grammar, bytecodeDetails( [
0 // PUSH_EMPTY_STRING 0, // PUSH_EMPTY_STRING
] ) ); ] ) );
} ); } );
@ -838,7 +834,7 @@ describe( "compiler pass |generateBytecode|", function () {
23, 0, // EXPECT <0> 23, 0, // EXPECT <0>
18, 0, 2, 1, // MATCH_STRING <0> 18, 0, 2, 1, // MATCH_STRING <0>
22, 0, // * ACCEPT_STRING <0> 22, 0, // * ACCEPT_STRING <0>
3 // * PUSH_FAILED 3, // * PUSH_FAILED
] ) ); ] ) );
} ); } );
@ -866,7 +862,7 @@ describe( "compiler pass |generateBytecode|", function () {
23, 0, // EXPECT <0> 23, 0, // EXPECT <0>
19, 0, 2, 1, // MATCH_STRING_IC <0> 19, 0, 2, 1, // MATCH_STRING_IC <0>
21, 1, // * ACCEPT_N <1> 21, 1, // * ACCEPT_N <1>
3 // * PUSH_FAILED 3, // * PUSH_FAILED
] ) ); ] ) );
} ); } );
@ -895,7 +891,7 @@ describe( "compiler pass |generateBytecode|", function () {
it( "generates correct bytecode", function () { it( "generates correct bytecode", function () {
expect( pass ).to.changeAST( grammar, bytecodeDetails( [ expect( pass ).to.changeAST( grammar, bytecodeDetails( [
0 // PUSH_EMPTY_STRING 0, // PUSH_EMPTY_STRING
] ), {}, { reportFailures: false } ); ] ), {}, { reportFailures: false } );
} ); } );
@ -917,16 +913,14 @@ describe( "compiler pass |generateBytecode|", function () {
expect( pass ).to.changeAST( grammar, bytecodeDetails( [ expect( pass ).to.changeAST( grammar, bytecodeDetails( [
18, 0, 2, 1, // MATCH_STRING <0> 18, 0, 2, 1, // MATCH_STRING <0>
22, 0, // * ACCEPT_STRING <0> 22, 0, // * ACCEPT_STRING <0>
3 // * PUSH_FAILED 3, // * PUSH_FAILED
] ), {}, { reportFailures: false } ); ] ), {}, { reportFailures: false } );
} ); } );
it( "defines correct constants", function () { it( "defines correct constants", function () {
expect( pass ).to.changeAST( grammar, constsDetails( expect( pass ).to.changeAST( grammar, constsDetails( [ "a" ], [], [], [] ), {}, { reportFailures: false } );
[ "a" ], [], [], []
), {}, { reportFailures: false } );
} ); } );
@ -941,16 +935,14 @@ describe( "compiler pass |generateBytecode|", function () {
expect( pass ).to.changeAST( grammar, bytecodeDetails( [ expect( pass ).to.changeAST( grammar, bytecodeDetails( [
19, 0, 2, 1, // MATCH_STRING_IC <0> 19, 0, 2, 1, // MATCH_STRING_IC <0>
21, 1, // * ACCEPT_N <1> 21, 1, // * ACCEPT_N <1>
3 // * PUSH_FAILED 3, // * PUSH_FAILED
] ), {}, { reportFailures: false } ); ] ), {}, { reportFailures: false } );
} ); } );
it( "defines correct constants", function () { it( "defines correct constants", function () {
expect( pass ).to.changeAST( grammar, constsDetails( expect( pass ).to.changeAST( grammar, constsDetails( [ "a" ], [], [], [] ), {}, { reportFailures: false } );
[ "a" ], [], [], []
), {}, { reportFailures: false } );
} ); } );
@ -970,7 +962,7 @@ describe( "compiler pass |generateBytecode|", function () {
23, 0, // EXPECT <0> 23, 0, // EXPECT <0>
20, 0, 2, 1, // MATCH_CLASS <0> 20, 0, 2, 1, // MATCH_CLASS <0>
21, 1, // * ACCEPT_N <1> 21, 1, // * ACCEPT_N <1>
3 // * PUSH_FAILED 3, // * PUSH_FAILED
] ) ); ] ) );
} ); } );
@ -1030,16 +1022,16 @@ describe( "compiler pass |generateBytecode|", function () {
{ {
value: [ "a", [ "b", "d" ], "e", [ "f", "h" ], "i", [ "j", "l" ] ], value: [ "a", [ "b", "d" ], "e", [ "f", "h" ], "i", [ "j", "l" ] ],
inverted: false, inverted: false,
ignoreCase: false ignoreCase: false,
} },
], ],
[ [
{ {
type: "class", type: "class",
value: [ "a", [ "b", "d" ], "e", [ "f", "h" ], "i", [ "j", "l" ] ], value: [ "a", [ "b", "d" ], "e", [ "f", "h" ], "i", [ "j", "l" ] ],
inverted: false, inverted: false,
ignoreCase: false ignoreCase: false,
} },
], ],
[] []
) ); ) );
@ -1057,7 +1049,7 @@ describe( "compiler pass |generateBytecode|", function () {
expect( pass ).to.changeAST( "start = [a]", bytecodeDetails( [ expect( pass ).to.changeAST( "start = [a]", bytecodeDetails( [
20, 0, 2, 1, // MATCH_CLASS <0> 20, 0, 2, 1, // MATCH_CLASS <0>
21, 1, // * ACCEPT_N <1> 21, 1, // * ACCEPT_N <1>
3 // * PUSH_FAILED 3, // * PUSH_FAILED
] ), {}, { reportFailures: false } ); ] ), {}, { reportFailures: false } );
} ); } );
@ -1066,9 +1058,7 @@ describe( "compiler pass |generateBytecode|", function () {
it( "defines correct constants", function () { it( "defines correct constants", function () {
expect( pass ).to.changeAST( "start = [a]", constsDetails( expect( pass ).to.changeAST( "start = [a]", constsDetails( [], [ { value: [ "a" ], inverted: false, ignoreCase: false } ], [], [] ), {}, { reportFailures: false } );
[], [ { value: [ "a" ], inverted: false, ignoreCase: false } ], [], []
), {}, { reportFailures: false } );
} ); } );
@ -1078,9 +1068,7 @@ describe( "compiler pass |generateBytecode|", function () {
it( "defines correct constants", function () { it( "defines correct constants", function () {
expect( pass ).to.changeAST( "start = [^a]", constsDetails( expect( pass ).to.changeAST( "start = [^a]", constsDetails( [], [ { value: [ "a" ], inverted: true, ignoreCase: false } ], [], [] ), {}, { reportFailures: false } );
[], [ { value: [ "a" ], inverted: true, ignoreCase: false } ], [], []
), {}, { reportFailures: false } );
} ); } );
@ -1090,9 +1078,7 @@ describe( "compiler pass |generateBytecode|", function () {
it( "defines correct constants", function () { it( "defines correct constants", function () {
expect( pass ).to.changeAST( "start = [a]i", constsDetails( expect( pass ).to.changeAST( "start = [a]i", constsDetails( [], [ { value: [ "a" ], inverted: false, ignoreCase: true } ], [], [] ), {}, { reportFailures: false } );
[], [ { value: [ "a" ], inverted: false, ignoreCase: true } ], [], []
), {}, { reportFailures: false } );
} ); } );
@ -1108,8 +1094,8 @@ describe( "compiler pass |generateBytecode|", function () {
{ {
value: [ "a", [ "b", "d" ], "e", [ "f", "h" ], "i", [ "j", "l" ] ], value: [ "a", [ "b", "d" ], "e", [ "f", "h" ], "i", [ "j", "l" ] ],
inverted: false, inverted: false,
ignoreCase: false ignoreCase: false,
} },
], ],
[], [],
[] []
@ -1135,7 +1121,7 @@ describe( "compiler pass |generateBytecode|", function () {
23, 0, // EXPECT <0> 23, 0, // EXPECT <0>
17, 2, 1, // MATCH_ANY 17, 2, 1, // MATCH_ANY
21, 1, // * ACCEPT_N <1> 21, 1, // * ACCEPT_N <1>
3 // * PUSH_FAILED 3, // * PUSH_FAILED
] ) ); ] ) );
} ); } );
@ -1160,7 +1146,7 @@ describe( "compiler pass |generateBytecode|", function () {
expect( pass ).to.changeAST( grammar, bytecodeDetails( [ expect( pass ).to.changeAST( grammar, bytecodeDetails( [
17, 2, 1, // MATCH_ANY 17, 2, 1, // MATCH_ANY
21, 1, // * ACCEPT_N <1> 21, 1, // * ACCEPT_N <1>
3 // * PUSH_FAILED 3, // * PUSH_FAILED
] ), {}, { reportFailures: false } ); ] ), {}, { reportFailures: false } );
} ); } );

@ -140,17 +140,20 @@ describe( "compiler pass |inferenceMatchResult|", function () {
expect( pass ).to.changeAST( expect( pass ).to.changeAST(
[ "start = end", "end = . " ].join( "\n" ), [ "start = end", "end = . " ].join( "\n" ),
{ rules: [ { match: 0 }, { match: 0 } ] }, { rules: [ { match: 0 }, { match: 0 } ] },
{}, {} {},
{}
); );
expect( pass ).to.changeAST( expect( pass ).to.changeAST(
[ "start = end", "end = ''" ].join( "\n" ), [ "start = end", "end = ''" ].join( "\n" ),
{ rules: [ { match: 1 }, { match: 1 } ] }, { rules: [ { match: 1 }, { match: 1 } ] },
{}, {} {},
{}
); );
expect( pass ).to.changeAST( expect( pass ).to.changeAST(
[ "start = end", "end = []" ].join( "\n" ), [ "start = end", "end = []" ].join( "\n" ),
{ rules: [ { match: -1 }, { match: -1 } ] }, { rules: [ { match: -1 }, { match: -1 } ] },
{}, {} {},
{}
); );
expect( pass ).to.changeAST( "start = . start", { rules: [ { match: 0 } ] }, {}, {} ); expect( pass ).to.changeAST( "start = . start", { rules: [ { match: 0 } ] }, {}, {} );

@ -18,16 +18,16 @@ describe( "compiler pass |removeProxyRules|", function () {
[ [
"start = proxy", "start = proxy",
"proxy = proxied", "proxy = proxied",
"proxied = 'a'" "proxied = 'a'",
].join( "\n" ), ].join( "\n" ),
{ {
rules: [ rules: [
{ {
name: "start", name: "start",
expression: { type: "rule_ref", name: "proxied" } expression: { type: "rule_ref", name: "proxied" },
}, },
{ name: "proxied" } { name: "proxied" },
] ],
}, },
{ allowedStartRules: [ "start" ] } { allowedStartRules: [ "start" ] }
); );
@ -44,20 +44,20 @@ describe( "compiler pass |removeProxyRules|", function () {
[ [
"start = proxy", "start = proxy",
"proxy = proxied", "proxy = proxied",
"proxied = 'a'" "proxied = 'a'",
].join( "\n" ), ].join( "\n" ),
{ {
rules: [ rules: [
{ {
name: "start", name: "start",
expression: { type: "rule_ref", name: "proxied" } expression: { type: "rule_ref", name: "proxied" },
}, },
{ {
name: "proxy", name: "proxy",
expression: { type: "rule_ref", name: "proxied" } expression: { type: "rule_ref", name: "proxied" },
}, },
{ name: "proxied" } { name: "proxied" },
] ],
}, },
{ allowedStartRules: [ "start", "proxy" ] } { allowedStartRules: [ "start", "proxy" ] }
); );

@ -18,8 +18,8 @@ describe( "compiler pass |reportDuplicateLabels|", function () {
message: "Label \"a\" is already defined at line 1, column 9.", message: "Label \"a\" is already defined at line 1, column 9.",
location: { location: {
start: { offset: 14, line: 1, column: 15 }, start: { offset: 14, line: 1, column: 15 },
end: { offset: 19, line: 1, column: 20 } end: { offset: 19, line: 1, column: 20 },
} },
} ); } );
} ); } );
@ -60,8 +60,8 @@ describe( "compiler pass |reportDuplicateLabels|", function () {
message: "Label \"a\" is already defined at line 1, column 9.", message: "Label \"a\" is already defined at line 1, column 9.",
location: { location: {
start: { offset: 15, line: 1, column: 16 }, start: { offset: 15, line: 1, column: 16 },
end: { offset: 20, line: 1, column: 21 } end: { offset: 20, line: 1, column: 21 },
} },
} ); } );
} ); } );

@ -14,13 +14,13 @@ describe( "compiler pass |reportDuplicateRules|", function () {
expect( pass ).to.reportError( [ expect( pass ).to.reportError( [
"start = 'a'", "start = 'a'",
"start = 'b'" "start = 'b'",
].join( "\n" ), { ].join( "\n" ), {
message: "Rule \"start\" is already defined at line 1, column 1.", message: "Rule \"start\" is already defined at line 1, column 1.",
location: { location: {
start: { offset: 12, line: 2, column: 1 }, start: { offset: 12, line: 2, column: 1 },
end: { offset: 23, line: 2, column: 12 } end: { offset: 23, line: 2, column: 12 },
} },
} ); } );
} ); } );

@ -21,14 +21,14 @@ describe( "compiler pass |reportIncorrectPlucking|", function () {
reports( `"@" cannot be used with an action block.`, [ reports( `"@" cannot be used with an action block.`, [
`start1 = 'a' @'b' 'c' { /* empty action block */ }`, `start1 = 'a' @'b' 'c' { /* empty action block */ }`,
`start2 = 'a' @('b' @'c' { /* empty action block */ })` `start2 = 'a' @('b' @'c' { /* empty action block */ })`,
] ); ] );
reports( `"@" cannot be used on a semantic predicate.`, [ reports( `"@" cannot be used on a semantic predicate.`, [
`start1 = 'a' @&{ /* semantic_and */ } 'c'`, `start1 = 'a' @&{ /* semantic_and */ } 'c'`,
`start2 = 'a' @!{ /* semantic_not */ } 'c'` `start2 = 'a' @!{ /* semantic_not */ } 'c'`,
] ); ] );

@ -16,8 +16,8 @@ describe( "compiler pass |reportInfiniteRecursion|", function () {
message: "Possible infinite loop when parsing (left recursion: start -> start).", message: "Possible infinite loop when parsing (left recursion: start -> start).",
location: { location: {
start: { offset: 8, line: 1, column: 9 }, start: { offset: 8, line: 1, column: 9 },
end: { offset: 13, line: 1, column: 14 } end: { offset: 13, line: 1, column: 14 },
} },
} ); } );
} ); } );
@ -26,13 +26,13 @@ describe( "compiler pass |reportInfiniteRecursion|", function () {
expect( pass ).to.reportError( [ expect( pass ).to.reportError( [
"start = stop", "start = stop",
"stop = start" "stop = start",
].join( "\n" ), { ].join( "\n" ), {
message: "Possible infinite loop when parsing (left recursion: start -> stop -> start).", message: "Possible infinite loop when parsing (left recursion: start -> stop -> start).",
location: { location: {
start: { offset: 20, line: 2, column: 8 }, start: { offset: 20, line: 2, column: 8 },
end: { offset: 25, line: 2, column: 13 } end: { offset: 25, line: 2, column: 13 },
} },
} ); } );
} ); } );
@ -64,11 +64,11 @@ describe( "compiler pass |reportInfiniteRecursion|", function () {
expect( pass ).to.reportError( [ expect( pass ).to.reportError( [
"start = a start", "start = a start",
"a 'a' = ''" "a 'a' = ''",
].join( "\n" ) ); ].join( "\n" ) );
expect( pass ).to.not.reportError( [ expect( pass ).to.not.reportError( [
"start = a start", "start = a start",
"a 'a' = 'a'" "a 'a' = 'a'",
].join( "\n" ) ); ].join( "\n" ) );
expect( pass ).to.reportError( "start = ('' / 'a' / 'b') start" ); expect( pass ).to.reportError( "start = ('' / 'a' / 'b') start" );
@ -114,11 +114,11 @@ describe( "compiler pass |reportInfiniteRecursion|", function () {
expect( pass ).to.reportError( [ expect( pass ).to.reportError( [
"start = a start", "start = a start",
"a = ''" "a = ''",
].join( "\n" ) ); ].join( "\n" ) );
expect( pass ).to.not.reportError( [ expect( pass ).to.not.reportError( [
"start = a start", "start = a start",
"a = 'a'" "a = 'a'",
].join( "\n" ) ); ].join( "\n" ) );
expect( pass ).to.reportError( "start = '' start" ); expect( pass ).to.reportError( "start = '' start" );

@ -16,8 +16,8 @@ describe( "compiler pass |reportInfiniteRepetition|", function () {
message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).", message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
location: { location: {
start: { offset: 8, line: 1, column: 9 }, start: { offset: 8, line: 1, column: 9 },
end: { offset: 13, line: 1, column: 14 } end: { offset: 13, line: 1, column: 14 },
} },
} ); } );
} ); } );
@ -28,8 +28,8 @@ describe( "compiler pass |reportInfiniteRepetition|", function () {
message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).", message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
location: { location: {
start: { offset: 8, line: 1, column: 9 }, start: { offset: 8, line: 1, column: 9 },
end: { offset: 13, line: 1, column: 14 } end: { offset: 13, line: 1, column: 14 },
} },
} ); } );
} ); } );
@ -38,11 +38,11 @@ describe( "compiler pass |reportInfiniteRepetition|", function () {
expect( pass ).to.reportError( [ expect( pass ).to.reportError( [
"start = a*", "start = a*",
"a 'a' = ''" "a 'a' = ''",
].join( "\n" ) ); ].join( "\n" ) );
expect( pass ).to.not.reportError( [ expect( pass ).to.not.reportError( [
"start = a*", "start = a*",
"a 'a' = 'a'" "a 'a' = 'a'",
].join( "\n" ) ); ].join( "\n" ) );
expect( pass ).to.reportError( "start = ('' / 'a' / 'b')*" ); expect( pass ).to.reportError( "start = ('' / 'a' / 'b')*" );
@ -88,11 +88,11 @@ describe( "compiler pass |reportInfiniteRepetition|", function () {
expect( pass ).to.reportError( [ expect( pass ).to.reportError( [
"start = a*", "start = a*",
"a = ''" "a = ''",
].join( "\n" ) ); ].join( "\n" ) );
expect( pass ).to.not.reportError( [ expect( pass ).to.not.reportError( [
"start = a*", "start = a*",
"a = 'a'" "a = 'a'",
].join( "\n" ) ); ].join( "\n" ) );
expect( pass ).to.reportError( "start = ''*" ); expect( pass ).to.reportError( "start = ''*" );

@ -16,19 +16,23 @@ describe( "compiler pass |reportUndefinedRules|", function () {
message: "Rule \"undefined\" is not defined.", message: "Rule \"undefined\" is not defined.",
location: { location: {
start: { offset: 8, line: 1, column: 9 }, start: { offset: 8, line: 1, column: 9 },
end: { offset: 17, line: 1, column: 18 } end: { offset: 17, line: 1, column: 18 },
} },
} ); } );
} ); } );
it( "checks allowedStartRules", function () { it( "checks allowedStartRules", function () {
expect( pass ).to.reportError( "start = 'a'", { expect( pass ).to.reportError(
message: "Start rule \"missing\" is not defined." "start = 'a'",
}, { {
allowedStartRules: [ "missing" ] message: "Start rule \"missing\" is not defined.",
} ); },
{
allowedStartRules: [ "missing" ],
}
);
} ); } );

@ -28,7 +28,7 @@ describe( "compiler pass |reportUnusedRules|", function () {
`, `,
[ [
`Rule "used" is not referenced.`, `Rule "used" is not referenced.`,
`Rule "unused" is not referenced.` `Rule "unused" is not referenced.`,
] ]
); );
@ -55,7 +55,7 @@ describe( "compiler pass |reportUnusedRules|", function () {
`, `,
null, null,
{ {
allowedStartRules: [ "b", "c" ] allowedStartRules: [ "b", "c" ],
} }
); );

@ -17,7 +17,7 @@ function varyParserOptions( block ) {
const optionsVariants = [ const optionsVariants = [
{ }, { },
{ extractComments: false }, { extractComments: false },
{ extractComments: true } { extractComments: true },
]; ];
optionsVariants.forEach( variant => { optionsVariants.forEach( variant => {
@ -53,15 +53,15 @@ describe( "PEG.js grammar parser", function () {
const labeledSimpleNot = { type: "labeled", label: "a", expression: simpleNotAbcd }; const labeledSimpleNot = { type: "labeled", label: "a", expression: simpleNotAbcd };
const sequence = { const sequence = {
type: "sequence", type: "sequence",
elements: [ literalAbcd, literalEfgh, literalIjkl ] elements: [ literalAbcd, literalEfgh, literalIjkl ],
}; };
const sequence2 = { const sequence2 = {
type: "sequence", type: "sequence",
elements: [ labeledAbcd, labeledEfgh ] elements: [ labeledAbcd, labeledEfgh ],
}; };
const sequence4 = { const sequence4 = {
type: "sequence", type: "sequence",
elements: [ labeledAbcd, labeledEfgh, labeledIjkl, labeledMnop ] elements: [ labeledAbcd, labeledEfgh, labeledIjkl, labeledMnop ],
}; };
const groupLabeled = { type: "group", expression: labeledAbcd }; const groupLabeled = { type: "group", expression: labeledAbcd };
const groupSequence = { type: "group", expression: sequence }; const groupSequence = { type: "group", expression: sequence };
@ -72,15 +72,15 @@ describe( "PEG.js grammar parser", function () {
const actionSequence = { type: "action", expression: sequence, code: " code " }; const actionSequence = { type: "action", expression: sequence, code: " code " };
const choice = { const choice = {
type: "choice", type: "choice",
alternatives: [ literalAbcd, literalEfgh, literalIjkl ] alternatives: [ literalAbcd, literalEfgh, literalIjkl ],
}; };
const choice2 = { const choice2 = {
type: "choice", type: "choice",
alternatives: [ actionAbcd, actionEfgh ] alternatives: [ actionAbcd, actionEfgh ],
}; };
const choice4 = { const choice4 = {
type: "choice", type: "choice",
alternatives: [ actionAbcd, actionEfgh, actionIjkl, actionMnop ] alternatives: [ actionAbcd, actionEfgh, actionIjkl, actionMnop ],
}; };
const named = { type: "named", name: "start rule", expression: literalAbcd }; const named = { type: "named", name: "start rule", expression: literalAbcd };
const ruleA = { type: "rule", name: "a", expression: literalAbcd }; const ruleA = { type: "rule", name: "a", expression: literalAbcd };
@ -95,7 +95,7 @@ describe( "PEG.js grammar parser", function () {
type: "grammar", type: "grammar",
initializer: null, initializer: null,
comments: null, comments: null,
rules: [ { type: "rule", name: "start", expression: expression } ] rules: [ { type: "rule", name: "start", expression: expression } ],
}; };
} }
@ -122,7 +122,7 @@ describe( "PEG.js grammar parser", function () {
type: "class", type: "class",
parts: parts, parts: parts,
inverted: inverted, inverted: inverted,
ignoreCase: ignoreCase ignoreCase: ignoreCase,
} ); } );
} }
@ -145,7 +145,7 @@ describe( "PEG.js grammar parser", function () {
result[ comment.offset ] = { result[ comment.offset ] = {
text: comment.text, text: comment.text,
multiline: comment.multiline multiline: comment.multiline,
}; };
return result; return result;
@ -163,7 +163,7 @@ describe( "PEG.js grammar parser", function () {
type: "grammar", type: "grammar",
initializer: null, initializer: null,
comments: null, comments: null,
rules: [ ruleA, ruleB ] rules: [ ruleA, ruleB ],
}; };
const stripProperties = ( function () { const stripProperties = ( function () {
@ -235,7 +235,7 @@ describe( "PEG.js grammar parser", function () {
rule_ref: stripLeaf, rule_ref: stripLeaf,
literal: stripLeaf, literal: stripLeaf,
class: stripLeaf, class: stripLeaf,
any: stripLeaf any: stripLeaf,
} ); } );
return strip; return strip;
@ -327,7 +327,7 @@ describe( "PEG.js grammar parser", function () {
const grammar = ruleRefGrammar( "a" ); const grammar = ruleRefGrammar( "a" );
grammar.initializer = { grammar.initializer = {
"type": "initializer", "type": "initializer",
"code": "" "code": "",
}; };
expect( "{}\nstart = a" ).to.parseAs( grammar ); expect( "{}\nstart = a" ).to.parseAs( grammar );
@ -432,7 +432,7 @@ describe( "PEG.js grammar parser", function () {
return oneRuleGrammar( { return oneRuleGrammar( {
type: "sequence", type: "sequence",
elements: elements elements: elements,
} ); } );
} }
@ -442,7 +442,7 @@ describe( "PEG.js grammar parser", function () {
type: "labeled", type: "labeled",
pick: true, pick: true,
label: label, label: label,
expression: expression expression: expression,
}; };
} }
@ -591,27 +591,17 @@ describe( "PEG.js grammar parser", function () {
// Canonical Comment is "/* comment */". // Canonical Comment is "/* comment */".
it( "parses Comment", function () { it( "parses Comment", function () {
expect( "start =// comment\n'abcd'" ).to.parseAs( commented( expect( "start =// comment\n'abcd'" ).to.parseAs( commented( trivialGrammar, [ { offset: 7, text: " comment", multiline: false } ], options ), options );
trivialGrammar, [ { offset: 7, text: " comment", multiline: false } ], options expect( "start =/* comment */'abcd'" ).to.parseAs( commented( trivialGrammar, [ { offset: 7, text: " comment ", multiline: true } ], options ), options );
), options );
expect( "start =/* comment */'abcd'" ).to.parseAs( commented(
trivialGrammar, [ { offset: 7, text: " comment ", multiline: true } ], options
), options );
} ); } );
// Canonical MultiLineComment is "/* comment */". // Canonical MultiLineComment is "/* comment */".
it( "parses MultiLineComment", function () { it( "parses MultiLineComment", function () {
expect( "start =/**/'abcd'" ).to.parseAs( commented( expect( "start =/**/'abcd'" ).to.parseAs( commented( trivialGrammar, [ { offset: 7, text: "", multiline: true } ], options ), options );
trivialGrammar, [ { offset: 7, text: "", multiline: true } ], options expect( "start =/*a*/'abcd'" ).to.parseAs( commented( trivialGrammar, [ { offset: 7, text: "a", multiline: true } ], options ), options );
), options ); expect( "start =/*abc*/'abcd'" ).to.parseAs( commented( trivialGrammar, [ { offset: 7, text: "abc", multiline: true } ], options ), options );
expect( "start =/*a*/'abcd'" ).to.parseAs( commented(
trivialGrammar, [ { offset: 7, text: "a", multiline: true } ], options
), options );
expect( "start =/*abc*/'abcd'" ).to.parseAs( commented(
trivialGrammar, [ { offset: 7, text: "abc", multiline: true } ], options
), options );
expect( "start =/**/*/'abcd'" ).to.failToParse(); expect( "start =/**/*/'abcd'" ).to.failToParse();
@ -620,15 +610,9 @@ describe( "PEG.js grammar parser", function () {
// Canonical MultiLineCommentNoLineTerminator is "/* comment */". // Canonical MultiLineCommentNoLineTerminator is "/* comment */".
it( "parses MultiLineCommentNoLineTerminator", function () { it( "parses MultiLineCommentNoLineTerminator", function () {
expect( "a = 'abcd'/**/\r\nb = 'efgh'" ).to.parseAs( commented( expect( "a = 'abcd'/**/\r\nb = 'efgh'" ).to.parseAs( commented( twoRuleGrammar, [ { offset: 10, text: "", multiline: true } ], options ), options );
twoRuleGrammar, [ { offset: 10, text: "", multiline: true } ], options expect( "a = 'abcd'/*a*/\r\nb = 'efgh'" ).to.parseAs( commented( twoRuleGrammar, [ { offset: 10, text: "a", multiline: true } ], options ), options );
), options ); expect( "a = 'abcd'/*abc*/\r\nb = 'efgh'" ).to.parseAs( commented( twoRuleGrammar, [ { offset: 10, text: "abc", multiline: true } ], options ), options );
expect( "a = 'abcd'/*a*/\r\nb = 'efgh'" ).to.parseAs( commented(
twoRuleGrammar, [ { offset: 10, text: "a", multiline: true } ], options
), options );
expect( "a = 'abcd'/*abc*/\r\nb = 'efgh'" ).to.parseAs( commented(
twoRuleGrammar, [ { offset: 10, text: "abc", multiline: true } ], options
), options );
expect( "a = 'abcd'/**/*/\r\nb = 'efgh'" ).to.failToParse(); expect( "a = 'abcd'/**/*/\r\nb = 'efgh'" ).to.failToParse();
expect( "a = 'abcd'/*\n*/\r\nb = 'efgh'" ).to.failToParse(); expect( "a = 'abcd'/*\n*/\r\nb = 'efgh'" ).to.failToParse();
@ -638,15 +622,9 @@ describe( "PEG.js grammar parser", function () {
// Canonical SingleLineComment is "// comment". // Canonical SingleLineComment is "// comment".
it( "parses SingleLineComment", function () { it( "parses SingleLineComment", function () {
expect( "start =//\n'abcd'" ).to.parseAs( commented( expect( "start =//\n'abcd'" ).to.parseAs( commented( trivialGrammar, [ { offset: 7, text: "", multiline: false } ], options ), options );
trivialGrammar, [ { offset: 7, text: "", multiline: false } ], options expect( "start =//a\n'abcd'" ).to.parseAs( commented( trivialGrammar, [ { offset: 7, text: "a", multiline: false } ], options ), options );
), options ); expect( "start =//abc\n'abcd'" ).to.parseAs( commented( trivialGrammar, [ { offset: 7, text: "abc", multiline: false } ], options ), options );
expect( "start =//a\n'abcd'" ).to.parseAs( commented(
trivialGrammar, [ { offset: 7, text: "a", multiline: false } ], options
), options );
expect( "start =//abc\n'abcd'" ).to.parseAs( commented(
trivialGrammar, [ { offset: 7, text: "abc", multiline: false } ], options
), options );
expect( "start =//\n>\n'abcd'" ).to.failToParse(); expect( "start =//\n>\n'abcd'" ).to.failToParse();
@ -780,7 +758,7 @@ describe( "PEG.js grammar parser", function () {
expect( "start = [a-a]" ).to.parseAs( classGrammar( [ [ "a", "a" ] ], false, false ) ); expect( "start = [a-a]" ).to.parseAs( classGrammar( [ [ "a", "a" ] ], false, false ) );
expect( "start = [b-a]" ).to.failToParse( { expect( "start = [b-a]" ).to.failToParse( {
message: "Invalid character range: b-a." message: "Invalid character range: b-a.",
} ); } );
} ); } );
@ -939,7 +917,7 @@ describe( "PEG.js grammar parser", function () {
const text = "rule = \n 'x' { y \n z"; const text = "rule = \n 'x' { y \n z";
const errorLocation = { const errorLocation = {
start: { offset: 13, line: 2, column: 6 }, start: { offset: 13, line: 2, column: 6 },
end: { offset: 14, line: 2, column: 7 } end: { offset: 14, line: 2, column: 7 },
}; };
expect( () => parser.parse( text ) ) expect( () => parser.parse( text ) )
.to.throw( "Unbalanced brace." ) .to.throw( "Unbalanced brace." )

@ -10,8 +10,8 @@ const benchmarks = [
{ file: "example2.json", title: "Example 2" }, { file: "example2.json", title: "Example 2" },
{ file: "example3.json", title: "Example 3" }, { file: "example3.json", title: "Example 3" },
{ file: "example4.json", title: "Example 4" }, { file: "example4.json", title: "Example 4" },
{ file: "example5.json", title: "Example 5" } { file: "example5.json", title: "Example 5" },
] ],
}, },
{ {
@ -32,8 +32,8 @@ const benchmarks = [
{ file: "blueprint/src/grid.css", title: "Blueprint - grid.css (source)" }, { file: "blueprint/src/grid.css", title: "Blueprint - grid.css (source)" },
{ file: "blueprint/src/print.css", title: "Blueprint - print.css (source)" }, { file: "blueprint/src/print.css", title: "Blueprint - print.css (source)" },
{ file: "blueprint/src/reset.css", title: "Blueprint - reset.css (source)" }, { file: "blueprint/src/reset.css", title: "Blueprint - reset.css (source)" },
{ file: "blueprint/src/typography.css", title: "Blueprint - typography.css (source)" } { file: "blueprint/src/typography.css", title: "Blueprint - typography.css (source)" },
] ],
}, },
]; ];

@ -63,7 +63,7 @@ $( "#run" ).click( () => {
const runCount = parseInt( $( "#run-count" ).val(), 10 ); const runCount = parseInt( $( "#run-count" ).val(), 10 );
const options = { const options = {
cache: $( "#cache" ).is( ":checked" ), cache: $( "#cache" ).is( ":checked" ),
optimize: $( "#optimize" ).val() optimize: $( "#optimize" ).val(),
}; };
if ( isNaN( runCount ) || runCount <= 0 ) { if ( isNaN( runCount ) || runCount <= 0 ) {
@ -82,7 +82,7 @@ $( "#run" ).click( () => {
type: "GET", type: "GET",
url: `https://raw.githubusercontent.com/pegjs/pegjs/${ BRANCH }/` + file, url: `https://raw.githubusercontent.com/pegjs/pegjs/${ BRANCH }/` + file,
dataType: "text", dataType: "text",
async: false async: false,
} ).responseText; } ).responseText;
}, },
@ -149,7 +149,7 @@ $( "#run" ).click( () => {
$.scrollTo( "max", { axis: "y", duration: 500 } ); $.scrollTo( "max", { axis: "y", duration: 500 } );
$( "#run-count, #cache, #run" ).removeAttr( "disabled" ); $( "#run-count, #cache, #run" ).removeAttr( "disabled" );
} },
} ); } );

@ -140,7 +140,7 @@ function nextArg() {
let runCount = 10; let runCount = 10;
const options = { const options = {
cache: false, cache: false,
optimize: "speed" optimize: "speed",
}; };
while ( args.length > 0 && isOption( args[ 0 ] ) ) { while ( args.length > 0 && isOption( args[ 0 ] ) ) {

@ -34,7 +34,7 @@ const Runner = {
} }
} },
}; };
@ -147,7 +147,7 @@ const Runner = {
Q.run(); Q.run();
} },
}; };

@ -10,10 +10,10 @@ module.exports = {
{ {
"modules": false, "modules": false,
"targets": { "targets": {
"ie": 11 "ie": 11,
} },
} },
] ],
] ],
}; };

@ -50,7 +50,7 @@ function target( { entry, library, output } ) {
hints: false, hints: false,
}, },
resolve: { resolve: {
extensions: [ ".ts", ".js" ] extensions: [ ".ts", ".js" ],
}, },
module: { module: {
rules: [ rules: [
@ -72,7 +72,7 @@ function target( { entry, library, output } ) {
new webpack.BannerPlugin( { new webpack.BannerPlugin( {
banner: HEADER, banner: HEADER,
raw: true, raw: true,
} ) } ),
], ],
}; };

Loading…
Cancel
Save