Browse Source

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 1 year ago
parent
commit
8b7bff7ac3
44 changed files with 462 additions and 482 deletions
  1. +12
    -2
      .eslintrc.js
  2. +1
    -1
      docs/.vuepress/config.js
  3. +1
    -1
      docs/.vuepress/config/nav.js
  4. +1
    -1
      package.json
  5. +1
    -1
      packages/pegjs/bin/options.js
  6. +1
    -0
      packages/pegjs/lib/ast/Grammar.js
  7. +5
    -5
      packages/pegjs/lib/compiler/index.js
  8. +1
    -1
      packages/pegjs/lib/compiler/opcodes.js
  9. +1
    -1
      packages/pegjs/lib/compiler/passes/calc-report-failures.js
  10. +18
    -18
      packages/pegjs/lib/compiler/passes/generate-bytecode.js
  11. +56
    -60
      packages/pegjs/lib/compiler/passes/generate-js.js
  12. +1
    -1
      packages/pegjs/lib/compiler/passes/inference-match-result.js
  13. +1
    -1
      packages/pegjs/lib/compiler/passes/remove-proxy-rules.js
  14. +1
    -1
      packages/pegjs/lib/compiler/passes/report-duplicate-labels.js
  15. +1
    -1
      packages/pegjs/lib/compiler/passes/report-duplicate-rules.js
  16. +1
    -1
      packages/pegjs/lib/compiler/passes/report-infinite-recursion.js
  17. +1
    -1
      packages/pegjs/lib/compiler/passes/report-infinite-repetition.js
  18. +1
    -1
      packages/pegjs/lib/compiler/passes/report-undefined-rules.js
  19. +2
    -2
      packages/pegjs/lib/peg.js
  20. +11
    -9
      packages/pegjs/lib/util/js.js
  21. +1
    -1
      src/pegjs.config.js
  22. +14
    -14
      test/api/generated-parser-api.spec.js
  23. +4
    -4
      test/api/pegjs-api.spec.js
  24. +7
    -7
      test/api/pegjs-util.spec.js
  25. +8
    -8
      test/api/plugin-api.spec.js
  26. +147
    -149
      test/behavior/generated-parser-behavior.spec.js
  27. +2
    -0
      test/browser.stub.js
  28. +62
    -76
      test/unit/compiler/passes/generate-bytecode.spec.js
  29. +6
    -3
      test/unit/compiler/passes/inference-match-result.spec.js
  30. +9
    -9
      test/unit/compiler/passes/remove-proxy-rules.spec.js
  31. +4
    -4
      test/unit/compiler/passes/report-duplicate-labels.spec.js
  32. +3
    -3
      test/unit/compiler/passes/report-duplicate-rules.spec.js
  33. +2
    -2
      test/unit/compiler/passes/report-incorrect-plucking.spec.js
  34. +9
    -9
      test/unit/compiler/passes/report-infinite-recursion.spec.js
  35. +8
    -8
      test/unit/compiler/passes/report-infinite-repetition.spec.js
  36. +11
    -7
      test/unit/compiler/passes/report-undefined-rules.spec.js
  37. +2
    -2
      test/unit/compiler/passes/report-unused-rules.spec.js
  38. +28
    -50
      test/unit/parser.spec.js
  39. +4
    -4
      tools/benchmark/benchmarks.js
  40. +3
    -3
      tools/benchmark/browser.stub.js
  41. +1
    -1
      tools/benchmark/index.js
  42. +2
    -2
      tools/benchmark/runner.js
  43. +5
    -5
      tools/bundler/babel.config.js
  44. +2
    -2
      tools/bundler/target.js

+ 12
- 2
.eslintrc.js View File

@@ -2,7 +2,13 @@

module.exports = {

"extends": "@futagoza",
"extends": [

"@futagoza/node/6",
// "@futagoza/typescript",
"@futagoza/vue",

],

"rules": {

@@ -13,7 +19,11 @@ module.exports = {

"overrides": [ {

"files": [ "*.spec.js", "*.test.js" ],
"files": [
"test/unit/compiler/passes/helpers.js",
"*.spec.js",
"*.test.js"
],
"extends": "@futagoza/dev/test",
"rules": {



+ 1
- 1
docs/.vuepress/config.js View File

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

};

+ 1
- 1
docs/.vuepress/config/nav.js View File

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



+ 1
- 1
package.json View File

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


+ 1
- 1
packages/pegjs/bin/options.js View File

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

const EXPORT_VAR_FORMATS = [ "globals", "umd" ];


+ 1
- 0
packages/pegjs/lib/ast/Grammar.js View File

@@ -15,6 +15,7 @@ class Grammar extends Node {
this.comments = comments;
this.rules = rules;

// eslint-disable-next-line no-use-before-define
this._alwaysConsumesOnSuccess = new AlwaysConsumesOnSuccess( this );

}


+ 5
- 5
packages/pegjs/lib/compiler/index.js View File

@@ -35,14 +35,14 @@ const compiler = {
reportIncorrectPlucking: reportIncorrectPlucking,
},
transform: {
removeProxyRules: removeProxyRules
removeProxyRules: removeProxyRules,
},
generate: {
calcReportFailures: calcReportFailures,
inferenceMatchResult: inferenceMatchResult,
generateBytecode: generateBytecode,
generateJS: generateJS
}
generateJS: generateJS,
},
},

// Generates a parser from a specified grammar AST. Throws |peg.GrammarError|
@@ -62,7 +62,7 @@ const compiler = {
header: null,
optimize: "speed",
output: "parser",
trace: false
trace: false,
} );

// We want `session.vm.evalModule` to return the parser
@@ -91,7 +91,7 @@ const compiler = {

}

}
},

};



+ 1
- 1
packages/pegjs/lib/compiler/opcodes.js View File

@@ -53,7 +53,7 @@ const opcodes = {
SILENT_FAILS_OFF: 29, // SILENT_FAILS_OFF

EXPECT_NS_BEGIN: 38, // EXPECT_NS_BEGIN
EXPECT_NS_END: 39 // EXPECT_NS_END invert
EXPECT_NS_END: 39, // EXPECT_NS_END invert

};



+ 1
- 1
packages/pegjs/lib/compiler/passes/calc-report-failures.js View File

@@ -51,7 +51,7 @@ function calcReportFailures( ast, session, options ) {

}

}
},
} );

while ( changedRules.length > 0 ) {


+ 18
- 18
packages/pegjs/lib/compiler/passes/generate-bytecode.js View File

@@ -219,7 +219,7 @@ function generateBytecode( ast, session ) {
const cls = {
value: node.parts,
inverted: node.inverted,
ignoreCase: node.ignoreCase
ignoreCase: node.ignoreCase,
};
const pattern = JSON.stringify( cls );
const index = util.findIndex( classes, c => JSON.stringify( c ) === pattern );
@@ -282,7 +282,7 @@ function generateBytecode( ast, session ) {
sp: context.sp + 1,
env: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures
reportFailures: context.reportFailures,
} ),
[ op.EXPECT_NS_END, negative ? 1 : 0 ],
buildCondition(
@@ -346,7 +346,7 @@ function generateBytecode( ast, session ) {
sp: -1, // stack pointer
env: { }, // mapping of label names to stack positions
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,
env: context.env,
action: context.action,
reportFailures: false
reportFailures: false,
} );

// No need to disable report failures if it already disabled
@@ -383,7 +383,7 @@ function generateBytecode( ast, session ) {
sp: context.sp,
env: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures
reportFailures: context.reportFailures,
} ),
alternatives.length < 2
? []
@@ -413,7 +413,7 @@ function generateBytecode( ast, session ) {
sp: context.sp + ( emitCall ? 1 : 0 ),
env: env,
action: node,
reportFailures: context.reportFailures
reportFailures: context.reportFailures,
} );
const match = node.expression.match|0;
const functionIndex = emitCall && match >= 0
@@ -455,7 +455,7 @@ function generateBytecode( ast, session ) {
env: context.env,
pluck: context.pluck,
action: null,
reportFailures: context.reportFailures
reportFailures: context.reportFailures,
} ),
buildCondition(
elements[ 0 ].match|0,
@@ -465,7 +465,7 @@ function generateBytecode( ast, session ) {
env: context.env,
pluck: context.pluck,
action: context.action,
reportFailures: context.reportFailures
reportFailures: context.reportFailures,
} ),
buildSequence(
processedCount > 1 ? [ op.POP_N, processedCount ] : [ op.POP ],
@@ -511,7 +511,7 @@ function generateBytecode( ast, session ) {
env: context.env,
pluck: [],
action: context.action,
reportFailures: context.reportFailures
reportFailures: context.reportFailures,
} )
);

@@ -538,7 +538,7 @@ function generateBytecode( ast, session ) {
sp: context.sp,
env: env,
action: null,
reportFailures: context.reportFailures
reportFailures: context.reportFailures,
} );

},
@@ -551,7 +551,7 @@ function generateBytecode( ast, session ) {
sp: context.sp + 1,
env: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures
reportFailures: context.reportFailures,
} ),
buildCondition(
node.expression.match|0,
@@ -582,7 +582,7 @@ function generateBytecode( ast, session ) {
sp: context.sp,
env: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures
reportFailures: context.reportFailures,
} ),
buildCondition(
// If expression always match no need replace FAILED to NULL
@@ -601,7 +601,7 @@ function generateBytecode( ast, session ) {
sp: context.sp + 1,
env: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures
reportFailures: context.reportFailures,
} );

return buildSequence(
@@ -619,7 +619,7 @@ function generateBytecode( ast, session ) {
sp: context.sp + 1,
env: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures
reportFailures: context.reportFailures,
} );

return buildSequence(
@@ -641,7 +641,7 @@ function generateBytecode( ast, session ) {
sp: context.sp,
env: util.clone( context.env ),
action: null,
reportFailures: context.reportFailures
reportFailures: context.reportFailures,
} );

},
@@ -677,7 +677,7 @@ function generateBytecode( ast, session ) {
const expectedIndex = context.reportFailures ? addExpectedConst( {
type: "literal",
value: node.value,
ignoreCase: node.ignoreCase
ignoreCase: node.ignoreCase,
} ) : null;

// For case-sensitive strings the value must match the beginning of the
@@ -712,7 +712,7 @@ function generateBytecode( ast, session ) {
type: "class",
value: node.parts,
inverted: node.inverted,
ignoreCase: node.ignoreCase
ignoreCase: node.ignoreCase,
} ) : null;

return buildSequence(
@@ -744,7 +744,7 @@ function generateBytecode( ast, session ) {
)
);

}
},
} );

generate( ast );


+ 56
- 60
packages/pegjs/lib/compiler/passes/generate-js.js View File

@@ -87,8 +87,7 @@ function generateJS( ast, session, options ) {
const parts = e.value.map( part =>
( Array.isArray( part )
? `["${ util.stringEscape( part[ 0 ] ) }", "${ util.stringEscape( part[ 1 ] ) }"]`
: `"${ util.stringEscape( part ) }"` )
);
: `"${ util.stringEscape( part ) }"` ) );

return "peg$classExpectation(["
+ parts.join( ", " ) + "], "
@@ -137,13 +136,10 @@ function generateJS( ast, session, options ) {
`peg$decode("${
util.stringEscape( rule.bytecode
.map( b => String.fromCharCode( b + 32 ) )
.join( "" )
)
}")`
)
.join( ",\n" )
),
"];"
.join( "" ) )
}")` )
.join( ",\n" ) ),
"];",
].join( "\n" );

}
@@ -172,7 +168,7 @@ function generateJS( ast, session, options ) {
"var rule$expects = function (expected) {",
" if (peg$silentFails === 0) peg$expect(expected);",
"}",
""
"",
].join( "\n" ) );

if ( options.trace ) {
@@ -183,7 +179,7 @@ function generateJS( ast, session, options ) {
" rule: " + ruleNameCode + ",",
" location: peg$computeLocation(startPos, startPos)",
"});",
""
"",
].join( "\n" ) );

}
@@ -207,7 +203,7 @@ function generateJS( ast, session, options ) {
" if (peg$silentFails === 0) {",
" rule$expectations.forEach(peg$expect);",
" }",
""
"",
].join( "\n" ) );

if ( options.trace ) {
@@ -227,7 +223,7 @@ function generateJS( ast, session, options ) {
" location: peg$computeLocation(startPos, startPos)",
" });",
"}",
""
"",
].join( "\n" ) );

}
@@ -235,7 +231,7 @@ function generateJS( ast, session, options ) {
parts.push( [
" return cached.result;",
"}",
""
"",
].join( "\n" ) );

}
@@ -256,7 +252,7 @@ function generateJS( ast, session, options ) {
" nextPos: peg$currPos,",
" result: " + resultCode + ",",
" expectations: rule$expectations",
"};"
"};",
].join( "\n" ) );

}
@@ -278,14 +274,14 @@ function generateJS( ast, session, options ) {
" rule: " + ruleNameCode + ",",
" location: peg$computeLocation(startPos, startPos)",
" });",
"}"
"}",
].join( "\n" ) );

}

parts.push( [
"",
"return " + resultCode + ";"
"return " + resultCode + ";",
].join( "\n" ) );

return parts.join( "\n" );
@@ -314,7 +310,7 @@ function generateJS( ast, session, options ) {
" ip += " + baseLength + " + " + thenLengthCode + ";",
"}",
"",
"break;"
"break;",
].join( "\n" );

}
@@ -335,7 +331,7 @@ function generateJS( ast, session, options ) {
" ip += " + baseLength + " + " + bodyLengthCode + ";",
"}",
"",
"break;"
"break;",
].join( "\n" );

}
@@ -356,7 +352,7 @@ function generateJS( ast, session, options ) {
");",
"",
"ip += " + baseLength + " + " + paramsLengthCode + ";",
"break;"
"break;",
].join( "\n" );

}
@@ -366,7 +362,7 @@ function generateJS( ast, session, options ) {
" return s.split(\"\").map(function(ch) { return ch.charCodeAt(0) - 32; });",
"}",
"",
"function peg$parseRule(index) {"
"function peg$parseRule(index) {",
].join( "\n" ) );

if ( options.trace ) {
@@ -379,7 +375,7 @@ function generateJS( ast, session, options ) {
" var ends = [];",
" var stack = [];",
" var startPos = peg$currPos;",
" var params, paramsLength, paramsN;"
" var params, paramsLength, paramsN;",
].join( "\n" ) );

} else {
@@ -391,7 +387,7 @@ function generateJS( ast, session, options ) {
" var end = bc.length;",
" var ends = [];",
" var stack = [];",
" var params, paramsLength, paramsN;"
" var params, paramsLength, paramsN;",
].join( "\n" ) );

}
@@ -501,9 +497,11 @@ function generateJS( ast, session, options ) {
"",
" case " + op.IF_NOT_ERROR + ":", // IF_NOT_ERROR t, f
indent10(
generateCondition( "stack[stack.length - 1] !== peg$FAILED",
generateCondition(
"stack[stack.length - 1] !== peg$FAILED",
0
) ),
)
),
"",
" case " + op.WHILE_NOT_ERROR + ":", // WHILE_NOT_ERROR b
indent10( generateLoop( "stack[stack.length - 1] !== peg$FAILED" ) ),
@@ -599,7 +597,7 @@ function generateJS( ast, session, options ) {
" } else {",
" break;",
" }",
" }"
" }",
].join( "\n" ) );

parts.push( indent2( generateRuleFooter( "peg$ruleNames[index]", "stack[0]" ) ) );
@@ -662,7 +660,7 @@ function generateJS( ast, session, options ) {

return s( this.sp - i );

}
},
};

function compile( bc ) {
@@ -1152,7 +1150,7 @@ function generateJS( ast, session, options ) {
"",
" return \"Expected \" + describeExpected(expected) + \" but \" + describeFound(found) + \" found.\";",
"};",
""
"",
].join( "\n" ) );

if ( options.trace ) {
@@ -1213,7 +1211,7 @@ function generateJS( ast, session, options ) {
" throw new Error(\"Invalid event type: \" + event.type + \".\");",
" }",
"};",
""
"",
].join( "\n" ) );

else
@@ -1222,7 +1220,7 @@ function generateJS( ast, session, options ) {
"var peg$FauxTracer = {",
" trace: function(event) { }",
"};",
""
"",
].join( "\n" ) );

}
@@ -1232,7 +1230,7 @@ function generateJS( ast, session, options ) {
" options = options !== undefined ? options : {};",
"",
" var peg$FAILED = {};",
""
"",
].join( "\n" ) );

if ( options.optimize === "size" ) {
@@ -1246,7 +1244,7 @@ function generateJS( ast, session, options ) {

parts.push( [
" var peg$startRuleIndices = " + startRuleIndices + ";",
" var peg$startRuleIndex = " + startRuleIndex + ";"
" var peg$startRuleIndex = " + startRuleIndex + ";",
].join( "\n" ) );

} else {
@@ -1260,7 +1258,7 @@ function generateJS( ast, session, options ) {

parts.push( [
" var peg$startRuleFunctions = " + startRuleFunctions + ";",
" var peg$startRuleFunction = " + startRuleFunction + ";"
" var peg$startRuleFunction = " + startRuleFunction + ";",
].join( "\n" ) );

}
@@ -1276,14 +1274,14 @@ function generateJS( ast, session, options ) {
" var peg$posDetailsCache = [{ line: 1, column: 1 }];",
" var peg$expected = [];",
" var peg$silentFails = 0;", // 0 = report failures, > 0 = silence failures
""
"",
].join( "\n" ) );

if ( options.cache ) {

parts.push( [
" var peg$resultsCache = {};",
""
"",
].join( "\n" ) );

}
@@ -1300,7 +1298,7 @@ function generateJS( ast, session, options ) {

parts.push( [
" var peg$ruleNames = " + ruleNames + ";",
""
"",
].join( "\n" ) );

}
@@ -1309,21 +1307,21 @@ function generateJS( ast, session, options ) {

parts.push( [
" var peg$tracer = \"tracer\" in options ? options.tracer : new peg$DefaultTracer();",
""
"",
].join( "\n" ) );

else

parts.push( [
" var peg$tracer = \"tracer\" in options ? options.tracer : peg$FauxTracer;",
""
"",
].join( "\n" ) );

}

parts.push( [
" var peg$result;",
""
"",
].join( "\n" ) );

if ( options.optimize === "size" ) {
@@ -1335,7 +1333,7 @@ function generateJS( ast, session, options ) {
" }",
"",
" peg$startRuleIndex = peg$startRuleIndices[options.startRule];",
" }"
" }",
].join( "\n" ) );

} else {
@@ -1347,7 +1345,7 @@ function generateJS( ast, session, options ) {
" }",
"",
" peg$startRuleFunction = peg$startRuleFunctions[options.startRule];",
" }"
" }",
].join( "\n" ) );

}
@@ -1568,7 +1566,7 @@ function generateJS( ast, session, options ) {
" : peg$computeLocation(failPos, failPos)",
" );",
" }",
""
"",
].join( "\n" ) );

if ( options.optimize === "size" ) {
@@ -1617,7 +1615,7 @@ function generateJS( ast, session, options ) {
"",
" throw peg$buildError();",
" }",
"}"
"}",
].join( "\n" ) );

return parts.join( "\n" );
@@ -1658,13 +1656,13 @@ function generateJS( ast, session, options ) {
" SyntaxError: peg$SyntaxError,",
" DefaultTracer: peg$DefaultTracer,",
" parse: peg$parse",
"}"
"}",
].join( "\n" )
: [
"{",
" SyntaxError: peg$SyntaxError,",
" parse: peg$parse",
"}"
"}",
].join( "\n" );

}
@@ -1677,13 +1675,13 @@ function generateJS( ast, session, options ) {
" peg$SyntaxError as SyntaxError,",
" peg$DefaultTracer as DefaultTracer,",
" peg$parse as parse",
"}"
"}",
].join( "\n" )
: [
"{",
" peg$SyntaxError as SyntaxError,",
" peg$parse as parse",
"}"
"}",
].join( "\n" );

}
@@ -1699,7 +1697,7 @@ function generateJS( ast, session, options ) {
indent2( toplevelCode ),
"",
indent2( "return " + generateParserObject() + ";" ),
"})()"
"})()",
].join( "\n" );

},
@@ -1713,7 +1711,7 @@ function generateJS( ast, session, options ) {
generateHeaderComment(),
"",
"\"use strict\";",
""
"",
].join( "\n" ) );

if ( dependencyVars.length > 0 ) {
@@ -1723,8 +1721,7 @@ function generateJS( ast, session, options ) {
parts.push( "var " + variable
+ " = require(\""
+ util.stringEscape( options.dependencies[ variable ] )
+ "\");"
);
+ "\");" );

} );
parts.push( "" );
@@ -1735,7 +1732,7 @@ function generateJS( ast, session, options ) {
toplevelCode,
"",
"module.exports = " + generateParserObject() + ";",
""
"",
].join( "\n" ) );

return parts.join( "\n" );
@@ -1759,8 +1756,7 @@ function generateJS( ast, session, options ) {
parts.push( "import " + variable
+ " from \""
+ util.stringEscape( options.dependencies[ variable ] )
+ "\";"
);
+ "\";" );

} );
parts.push( "" );
@@ -1800,7 +1796,7 @@ function generateJS( ast, session, options ) {
"",
indent2( "return " + generateParserObject() + ";" ),
"});",
""
"",
].join( "\n" );

},
@@ -1816,7 +1812,7 @@ function generateJS( ast, session, options ) {
"",
indent2( "root." + options.exportVar + " = " + generateParserObject() + ";" ),
"})(this);",
""
"",
].join( "\n" );

},
@@ -1843,14 +1839,14 @@ function generateJS( ast, session, options ) {
" if (typeof define === \"function\" && define.amd) {",
" define(" + dependencies + ", factory);",
" } else if (typeof module === \"object\" && module.exports) {",
" module.exports = factory(" + requires + ");"
" module.exports = factory(" + requires + ");",
].join( "\n" ) );

if ( options.exportVar !== null ) {

parts.push( [
" } else {",
" root." + options.exportVar + " = factory(" + args + ");"
" root." + options.exportVar + " = factory(" + args + ");",
].join( "\n" ) );

}
@@ -1864,12 +1860,12 @@ function generateJS( ast, session, options ) {
"",
indent2( "return " + generateParserObject() + ";" ),
"});",
""
"",
].join( "\n" ) );

return parts.join( "\n" );

}
},
};

return generators[ options.format ]();


+ 1
- 1
packages/pegjs/lib/compiler/passes/inference-match-result.js View File

@@ -159,7 +159,7 @@ function inferenceMatchResult( ast, session ) {

},
// |any| not match on empty input
any: sometimesMatch
any: sometimesMatch,
} );

inference( ast );


+ 1
- 1
packages/pegjs/lib/compiler/passes/remove-proxy-rules.js View File

@@ -15,7 +15,7 @@ function removeProxyRules( ast, session, options ) {

if ( node.name === proxy ) node.name = real;

}
},

} );



+ 1
- 1
packages/pegjs/lib/compiler/passes/report-duplicate-labels.js View File

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

check( ast );


+ 1
- 1
packages/pegjs/lib/compiler/passes/report-duplicate-rules.js View File

@@ -25,7 +25,7 @@ function reportDuplicateRules( ast, session ) {

rules[ node.name ] = node.location;

}
},
} );

check( ast );


+ 1
- 1
packages/pegjs/lib/compiler/passes/report-infinite-recursion.js View File

@@ -51,7 +51,7 @@ function reportInfiniteRecursion( ast, session ) {

check( ast.findRule( node.name ) );

}
},
} );

check( ast );


+ 1
- 1
packages/pegjs/lib/compiler/passes/report-infinite-repetition.js View File

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

}

}
},
} );

check( ast );


+ 1
- 1
packages/pegjs/lib/compiler/passes/report-undefined-rules.js View File

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

}

}
},
} );

check( ast );


+ 2
- 2
packages/pegjs/lib/peg.js View File

@@ -28,7 +28,7 @@ const peg = {
generate( grammar, options = {} ) {

const session = new compiler.Session( {
passes: util.convertPasses( compiler.passes )
passes: util.convertPasses( compiler.passes ),
} );

if ( Array.isArray( options.plugins ) )
@@ -47,7 +47,7 @@ const peg = {
options
);

}
},
};

module.exports = peg;

+ 11
- 9
packages/pegjs/lib/util/js.js View File

@@ -36,9 +36,10 @@ const js = {
*/
stringEscape( s ) {

return sourceEscape( s
.replace( /\\/g, "\\\\" ) // backslash
.replace( /"/g, "\\\"" ) // closing double quote
return sourceEscape(
s
.replace( /\\/g, "\\\\" ) // backslash
.replace( /"/g, "\\\"" ) // closing double quote
);

},
@@ -50,12 +51,13 @@ const js = {
*/
regexpEscape( s ) {

return sourceEscape( s
.replace( /\\/g, "\\\\" ) // backslash
.replace( /\//g, "\\/" ) // closing slash
.replace( /]/g, "\\]" ) // closing bracket
.replace( /\^/g, "\\^" ) // caret
.replace( /-/g, "\\-" ) // dash
return sourceEscape(
s
.replace( /\\/g, "\\\\" ) // backslash
.replace( /\//g, "\\/" ) // closing slash
.replace( /]/g, "\\]" ) // closing bracket
.replace( /\^/g, "\\^" ) // caret
.replace( /-/g, "\\-" ) // dash
);

},


+ 1
- 1
src/pegjs.config.js View File

@@ -10,7 +10,7 @@ module.exports = {
dependencies: {

ast: "./ast",
util: "./util"
util: "./util",

},



+ 14
- 14
test/api/generated-parser-api.spec.js View File

@@ -95,7 +95,7 @@ describe( "generated parser API", function () {
"1:1-1:1 rule.fail a",
"1:1-1:1 rule.enter 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" );
@@ -138,32 +138,32 @@ describe( "generated parser API", function () {
rule: "start",
location: {
start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 }
}
end: { offset: 0, line: 1, column: 1 },
},
},
{
type: "rule.enter",
rule: "a",
location: {
start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 }
}
end: { offset: 0, line: 1, column: 1 },
},
},
{
type: "rule.fail",
rule: "a",
location: {
start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 }
}
end: { offset: 0, line: 1, column: 1 },
},
},
{
type: "rule.enter",
rule: "b",
location: {
start: { offset: 0, line: 1, column: 1 },
end: { offset: 0, line: 1, column: 1 }
}
end: { offset: 0, line: 1, column: 1 },
},
},
{
type: "rule.match",
@@ -171,8 +171,8 @@ describe( "generated parser API", function () {
result: "b",
location: {
start: { offset: 0, line: 1, column: 1 },
end: { offset: 1, line: 1, column: 2 }
}
end: { offset: 1, line: 1, column: 2 },
},
},
{
type: "rule.match",
@@ -180,9 +180,9 @@ describe( "generated parser API", function () {
result: "b",
location: {
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() };


+ 4
- 4
test/api/pegjs-api.spec.js View File

@@ -92,7 +92,7 @@ describe( "PEG.js API", function () {

const parser = peg.generate( grammar, {
optimize: "speed",
allowedStartRules: [ "b", "c" ]
allowedStartRules: [ "b", "c" ],
} );

expect( () => {
@@ -139,7 +139,7 @@ describe( "PEG.js API", function () {

const parser = peg.generate( grammar, {
optimize: "size",
allowedStartRules: [ "b", "c" ]
allowedStartRules: [ "b", "c" ],
} );

expect( () => {
@@ -322,7 +322,7 @@ describe( "PEG.js API", function () {

peg.generate( [
"start = " + label + ":end",
"end = 'a'"
"end = 'a'",
].join( "\n" ), { output: "source" } );

} ).to.throw( peg.parser.SyntaxError );
@@ -343,7 +343,7 @@ describe( "PEG.js API", function () {

peg.generate( [
"start = " + rule,
rule + " = 'a'"
rule + " = 'a'",
].join( "\n" ), { output: "source" } );

} ).to.not.throw( peg.parser.SyntaxError );


+ 7
- 7
test/api/pegjs-util.spec.js View File

@@ -13,15 +13,15 @@ describe( "PEG.js Utility API", function () {
stage1: {
pass1() { },
pass2() { },
pass3() { }
pass3() { },
},
stage2: {
pass1() { },
pass2() { }
pass2() { },
},
stage3: {
pass1() { }
}
pass1() { },
},
};

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

} );


+ 8
- 8
test/api/plugin-api.spec.js View File

@@ -29,7 +29,7 @@ describe( "plugin API", function () {

pluginsUsed[ 2 ] = true;

} }
} },
];

peg.generate( grammar, { plugins: plugins } );
@@ -71,7 +71,7 @@ describe( "plugin API", function () {

} );

}
},
};

peg.generate( grammar, { plugins: [ plugin ] } );
@@ -86,9 +86,9 @@ describe( "plugin API", function () {

expect( options ).to.equal( generateOptions );

}
},
} ],
foo: 42
foo: 42,
};

peg.generate( grammar, generateOptions );
@@ -116,7 +116,7 @@ describe( "plugin API", function () {

`, { context: { ast: peg.ast } } );

}
},
};

const parser = peg.generate( "a", { plugins: [ plugin ] } );
@@ -137,7 +137,7 @@ describe( "plugin API", function () {

config.passes.generate = [ pass ];

}
},
};

const parser = peg.generate( grammar, { plugins: [ plugin ] } );
@@ -159,12 +159,12 @@ describe( "plugin API", function () {

options.allowedStartRules = [ "b", "c" ];

}
},
};

const parser = peg.generate( grammar, {
allowedStartRules: [ "a" ],
plugins: [ plugin ]
plugins: [ plugin ],
} );

expect( () => {


+ 147
- 149
test/behavior/generated-parser-behavior.spec.js View File

@@ -18,7 +18,7 @@ describe( "generated parser behavior", function () {
{ cache: true, optimize: "speed", trace: false },
{ cache: true, optimize: "speed", trace: true },
{ cache: true, optimize: "size", trace: false },
{ cache: true, optimize: "size", trace: true }
{ cache: true, optimize: "size", trace: true },
];

optionsVariants.forEach( variant => {
@@ -61,8 +61,7 @@ describe( "generated parser behavior", function () {
options = typeof options !== "undefined" ? options : {};

const result = withConsoleStub( () =>
utils.flag( this, "object" ).parse( input, options )
);
utils.flag( this, "object" ).parse( input, options ) );

if ( typeof expected !== "undefined" ) {

@@ -88,8 +87,7 @@ describe( "generated parser behavior", function () {
try {

result = withConsoleStub( () =>
utils.flag( this, "object" ).parse( input, options )
);
utils.flag( this, "object" ).parse( input, options ) );
passed = true;

} catch ( e ) {
@@ -138,7 +136,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"{ var result = 42; }",
"start = 'a' { return result; }"
"start = 'a' { return result; }",
].join( "\n" ), options );

expect( parser ).to.parse( "a", 42 );
@@ -151,7 +149,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"{ var result = options; }",
"start = 'a' { return result; }"
"start = 'a' { return result; }",
].join( "\n" ), options );

expect( parser ).to.parse( "a", { a: 42 }, { a: 42 } );
@@ -171,7 +169,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [
"{ var n = 0; }",
"start = (a 'b') / (a 'c') { return n; }",
"a = 'a' { n++; }"
"a = 'a' { n++; }",
].join( "\n" ), options );

expect( parser ).to.parse( "ac", 1 );
@@ -185,7 +183,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( [
"{ var n = 0; }",
"start = (a 'b') / (a 'c') { return n; }",
"a = 'a' { n++; }"
"a = 'a' { n++; }",
].join( "\n" ), options );

expect( parser ).to.parse( "ac", 2 );
@@ -215,7 +213,7 @@ describe( "generated parser behavior", function () {
const parser = peg.generate( "start = 'a'" );

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'" );

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'" );

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 );

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 );

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 );

expect( parser ).to.failToParse( "", {
expected: [ { type: "any" } ]
expected: [ { type: "any" } ],
} );

} );
@@ -495,7 +493,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"start = a",
"a = 'a'"
"a = 'a'",
].join( "\n" ), options );

expect( parser ).to.parse( "a", "a" );
@@ -510,7 +508,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"start = a",
"a = 'a'"
"a = 'a'",
].join( "\n" ), options );

expect( parser ).to.failToParse( "b" );
@@ -592,48 +590,48 @@ describe( "generated parser behavior", function () {
const testcases = [
{
grammar: "start = (a:'a') &{ return a === 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = (a:'a')? &{ return a === 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = (a:'a')* &{ return a === 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = (a:'a')+ &{ return a === 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = $(a:'a') &{ return a === 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = &(a:'a') 'a' &{ return a === 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = !(a:'a') 'b' &{ return a === 'a'; }",
input: "b"
input: "b",
},
{
grammar: "start = b:(a:'a') &{ return a === 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = ('a' b:'b' 'c') &{ return b === 'b'; }",
input: "abc"
input: "abc",
},
{
grammar: "start = (a:'a' { return a; }) &{ return a === 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = ('a' / b:'b' / 'c') &{ return b === 'b'; }",
input: "b"
}
input: "b",
},
];

testcases.forEach( testcase => {
@@ -692,7 +690,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"{ var v = 42 }",
"start = &{ return v === 42; }"
"start = &{ return v === 42; }",
].join( "\n" ), options );

expect( parser ).to.parse( "" );
@@ -703,7 +701,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"{ function f() { return 42; } }",
"start = &{ return f() === 42; }"
"start = &{ return f() === 42; }",
].join( "\n" ), options );

expect( parser ).to.parse( "" );
@@ -718,7 +716,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"{ var result; }",
"start = &{ result = options; return true; } { return result; }"
"start = &{ result = options; return true; } { return result; }",
].join( "\n" ), options );

expect( parser ).to.parse( "", { a: 42 }, { a: 42 } );
@@ -734,22 +732,22 @@ describe( "generated parser behavior", function () {
"thing = digit / mark",
"digit = [0-9]",
"mark = &{ result = location(); return true; } 'x'",
"nl = '\\r'? '\\n'"
"nl = '\\r'? '\\n'",
].join( "\n" ), options );

expect( parser ).to.parse( "1\n2\n\n3\n\n\n4 5 x", {
start: { offset: 13, line: 7, column: 5 },
end: { offset: 13, line: 7, column: 5 }
end: { offset: 13, line: 7, column: 5 },
} );

// Newline representations
expect( parser ).to.parse( "1\nx", { // Unix
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
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( [
"start = [0-9]+ val:mark { return val; }",
"mark = 'xx' { return offset(); }"
"mark = 'xx' { return offset(); }",
].join( "\n" ), options );

expect( parser ).to.parse( "0123456xx", 7 );
@@ -769,7 +767,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"start = [0-9]+ val:mark { return val; }",
"mark = 'xx' { return range(); }"
"mark = 'xx' { return range(); }",
].join( "\n" ), options );

expect( parser ).to.parse( "0123456xx", [ 7, 9 ] );
@@ -851,48 +849,48 @@ describe( "generated parser behavior", function () {
const testcases = [
{
grammar: "start = (a:'a') !{ return a !== 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = (a:'a')? !{ return a !== 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = (a:'a')* !{ return a !== 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = (a:'a')+ !{ return a !== 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = $(a:'a') !{ return a !== 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = &(a:'a') 'a' !{ return a !== 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = !(a:'a') 'b' !{ return a !== 'a'; }",
input: "b"
input: "b",
},
{
grammar: "start = b:(a:'a') !{ return a !== 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = ('a' b:'b' 'c') !{ return b !== 'b'; }",
input: "abc"
input: "abc",
},
{
grammar: "start = (a:'a' { return a; }) !{ return a !== 'a'; }",
input: "a"
input: "a",
},
{
grammar: "start = ('a' / b:'b' / 'c') !{ return b !== 'b'; }",
input: "b"
}
input: "b",
},
];

testcases.forEach( testcase => {
@@ -951,7 +949,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"{ var v = 42 }",
"start = !{ return v !== 42; }"
"start = !{ return v !== 42; }",
].join( "\n" ), options );

expect( parser ).to.parse( "" );
@@ -962,7 +960,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"{ function f() { return 42; } }",
"start = !{ return f() !== 42; }"
"start = !{ return f() !== 42; }",
].join( "\n" ), options );

expect( parser ).to.parse( "" );
@@ -977,7 +975,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"{ var result; }",
"start = !{ result = options; return false; } { return result; }"
"start = !{ result = options; return false; } { return result; }",
].join( "\n" ), options );

expect( parser ).to.parse( "", { a: 42 }, { a: 42 } );
@@ -993,22 +991,22 @@ describe( "generated parser behavior", function () {
"thing = digit / mark",
"digit = [0-9]",
"mark = !{ result = location(); return false; } 'x'",
"nl = '\\r'? '\\n'"
"nl = '\\r'? '\\n'",
].join( "\n" ), options );

expect( parser ).to.parse( "1\n2\n\n3\n\n\n4 5 x", {
start: { offset: 13, line: 7, column: 5 },
end: { offset: 13, line: 7, column: 5 }
end: { offset: 13, line: 7, column: 5 },
} );

// Newline representations
expect( parser ).to.parse( "1\nx", { // Unix
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
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: [
{ type: "literal", text: "a", 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", {
expected: [
{ 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: [
{ type: "literal", text: "a", 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", {
expected: [
{ 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", {
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'",
input: "abc",
output: [ "a", "b", "c" ]
output: [ "a", "b", "c" ],
},
] );

@@ -1345,42 +1343,42 @@ describe( "generated parser behavior", function () {
{
grammar: "start = @'a'",
input: "a",
output: "a"
output: "a",
},
{
grammar: "start = @'a' / @'b'",
input: "a",
output: "a"
output: "a",
},
{
grammar: "start = @'a' / @'b'",
input: "b",
output: "b"
output: "b",
},
{
grammar: "start = 'a' @'b' 'c'",
input: "abc",
output: "b"
output: "b",
},
{
grammar: "start = 'a' ( @'b' 'c' )",
input: "abc",
output: [ "a", "b" ]
output: [ "a", "b" ],
},
{
grammar: "start = 'a' @( 'b' @'c' 'd' )",
input: "abcd",
output: "c"
output: "c",
},
{
grammar: "start = 'a' ( @'b' 'c' ) @'d'",
input: "abcd",
output: "d"
output: "d",
},
{
grammar: "start = 'a' @'b' 'c' / 'd' 'e' @'f'",
input: "def",
output: "f"
output: "f",
},
] );

@@ -1388,27 +1386,27 @@ describe( "generated parser behavior", function () {
{
grammar: "start = 'a' @'b' @'c'",
input: "abc",
output: [ "b", "c" ]
output: [ "b", "c" ],
},
{
grammar: "start = 'a' ( @'b' @'c' )",
input: "abc",
output: [ "a", [ "b", "c" ] ]
output: [ "a", [ "b", "c" ] ],
},
{
grammar: "start = 'a' @( 'b' @'c' @'d' )",
input: "abcd",
output: [ "c", "d" ]
output: [ "c", "d" ],
},
{
grammar: "start = 'a' @( @'b' 'c' ) @'d' 'e'",
input: "abcde",
output: [ "b", "d" ]
output: [ "b", "d" ],
},
{
grammar: "start = 'a' @'b' 'c' / @'d' 'e' @'f'",
input: "def",
output: [ "d", "f" ]
output: [ "d", "f" ],
},
] );

@@ -1416,17 +1414,17 @@ describe( "generated parser behavior", function () {
{
grammar: "start = @'a' &{ return true; }",
input: "a",
output: "a"
output: "a",
},
{
grammar: "start = @'a' !{ return false; }",
input: "a",
output: "a"
output: "a",
},
{
grammar: "start = @n:[0-9] &{ return n > 0; }",
input: "2",
output: "2"
output: "2",
},
] );

@@ -1496,48 +1494,48 @@ describe( "generated parser behavior", function () {
const testcases = [
{
grammar: "start = (a:'a') { return a; }",
input: "a"
input: "a",
},
{
grammar: "start = (a:'a')? { return a; }",
input: "a"
input: "a",
},
{
grammar: "start = (a:'a')* { return a; }",
input: "a"
input: "a",
},
{
grammar: "start = (a:'a')+ { return a; }",
input: "a"
input: "a",
},
{
grammar: "start = $(a:'a') { return a; }",
input: "a"
input: "a",
},
{
grammar: "start = &(a:'a') 'a' { return a; }",
input: "a"
input: "a",
},
{
grammar: "start = !(a:'a') 'b' { return a; }",
input: "b"
input: "b",
},
{
grammar: "start = b:(a:'a') { return a; }",
input: "a"
input: "a",
},
{
grammar: "start = ('a' b:'b' 'c') { return b; }",
input: "abc"
input: "abc",
},
{
grammar: "start = (a:'a' { return a; }) { return a; }",
input: "a"
input: "a",
},
{
grammar: "start = ('a' / b:'b' / 'c') { return b; }",
input: "b"
}
input: "b",
},
];

testcases.forEach( testcase => {
@@ -1596,7 +1594,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"{ var v = 42 }",
"start = 'a' { return v; }"
"start = 'a' { return v; }",
].join( "\n" ), options );

expect( parser ).to.parse( "a", 42 );
@@ -1607,7 +1605,7 @@ describe( "generated parser behavior", function () {

const parser = peg.generate( [
"{ function f() { return 42; } }",
"start = 'a' { return f(); }"
"start = 'a' { return f(); }",
].join( "\n" ), options );

expect( parser ).to.parse( "a", 42 );
@@ -1649,22 +1647,22 @@ describe( "generated parser behavior", function () {
"thing = digit / mark",
"digit = [0-9]",
"mark = 'x' { result = location(); }",
"nl = '\\r'? '\\n'"
"nl = '\\r'? '\\n'",
].join( "\n" ), options );

expect( parser ).to.parse( "1\n2\n\n3\n\n\n4 5 x", {
start: { offset: 13, line: 7, column: 5 },
end: { offset: 14, line: 7, column: 6 }
end: { offset: 14, line: 7, column: 6 },
} );

// Newline representations