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

14
.eslintrc.js

@ -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": {

2
docs/.vuepress/config.js

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

2
docs/.vuepress/config/nav.js

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

2
package.json

@ -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",

2
packages/pegjs/bin/options.js

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

1
packages/pegjs/lib/ast/Grammar.js

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

10
packages/pegjs/lib/compiler/index.js

@ -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 = {
}
}
},
};

2
packages/pegjs/lib/compiler/opcodes.js

@ -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
};

2
packages/pegjs/lib/compiler/passes/calc-report-failures.js

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

36
packages/pegjs/lib/compiler/passes/generate-bytecode.js

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

116
packages/pegjs/lib/compiler/passes/generate-js.js

@ -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 ]();

2
packages/pegjs/lib/compiler/passes/inference-match-result.js

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

2
packages/pegjs/lib/compiler/passes/remove-proxy-rules.js

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

2
packages/pegjs/lib/compiler/passes/report-duplicate-labels.js

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

2
packages/pegjs/lib/compiler/passes/report-duplicate-rules.js

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

2
packages/pegjs/lib/compiler/passes/report-infinite-recursion.js

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

2
packages/pegjs/lib/compiler/passes/report-infinite-repetition.js

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

2
packages/pegjs/lib/compiler/passes/report-undefined-rules.js

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

4
packages/pegjs/lib/peg.js

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

20
packages/pegjs/lib/util/js.js

@ -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
);
},

2
src/pegjs.config.js

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

28
test/api/generated-parser-api.spec.js

@ -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() };

8
test/api/pegjs-api.spec.js

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

14
test/api/pegjs-util.spec.js

@ -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,
],
} ) );
} );

16
test/api/plugin-api.spec.js

@ -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( () => {

296
test/behavior/generated-parser-behavior.spec.js

@ -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"