diff --git a/.eslintrc.js b/.eslintrc.js index 0589eb8..1e644dd 100644 --- a/.eslintrc.js +++ b/.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": { diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 6d40c30..f6ad4f6 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -40,6 +40,6 @@ module.exports = { extraWatchFiles: [ require.resolve( "./config/nav.js" ), require.resolve( "./config/sidebar.js" ), - ] + ], }; diff --git a/docs/.vuepress/config/nav.js b/docs/.vuepress/config/nav.js index d466aec..d15db61 100644 --- a/docs/.vuepress/config/nav.js +++ b/docs/.vuepress/config/nav.js @@ -73,7 +73,7 @@ module.exports = [ { text: "Plugins", link: "https://www.npmjs.com/search?q=pegjs%20plugin", - } + }, ], }, diff --git a/package.json b/package.json index 2c38eb8..3922b1d 100644 --- a/package.json +++ b/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", diff --git a/packages/pegjs/bin/options.js b/packages/pegjs/bin/options.js index 31af1f5..fdecf22 100644 --- a/packages/pegjs/bin/options.js +++ b/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" ]; diff --git a/packages/pegjs/lib/ast/Grammar.js b/packages/pegjs/lib/ast/Grammar.js index 0300695..3c7ad64 100644 --- a/packages/pegjs/lib/ast/Grammar.js +++ b/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 ); } diff --git a/packages/pegjs/lib/compiler/index.js b/packages/pegjs/lib/compiler/index.js index 3620086..98306b3 100644 --- a/packages/pegjs/lib/compiler/index.js +++ b/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 = { } - } + }, }; diff --git a/packages/pegjs/lib/compiler/opcodes.js b/packages/pegjs/lib/compiler/opcodes.js index 1402072..0f722b3 100644 --- a/packages/pegjs/lib/compiler/opcodes.js +++ b/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 }; diff --git a/packages/pegjs/lib/compiler/passes/calc-report-failures.js b/packages/pegjs/lib/compiler/passes/calc-report-failures.js index 23b8c4b..569f6b9 100644 --- a/packages/pegjs/lib/compiler/passes/calc-report-failures.js +++ b/packages/pegjs/lib/compiler/passes/calc-report-failures.js @@ -51,7 +51,7 @@ function calcReportFailures( ast, session, options ) { } - } + }, } ); while ( changedRules.length > 0 ) { diff --git a/packages/pegjs/lib/compiler/passes/generate-bytecode.js b/packages/pegjs/lib/compiler/passes/generate-bytecode.js index 8278edb..77faf86 100644 --- a/packages/pegjs/lib/compiler/passes/generate-bytecode.js +++ b/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 ); diff --git a/packages/pegjs/lib/compiler/passes/generate-js.js b/packages/pegjs/lib/compiler/passes/generate-js.js index 7591e44..c69c225 100644 --- a/packages/pegjs/lib/compiler/passes/generate-js.js +++ b/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 ](); diff --git a/packages/pegjs/lib/compiler/passes/inference-match-result.js b/packages/pegjs/lib/compiler/passes/inference-match-result.js index 47f984b..e3ff81e 100644 --- a/packages/pegjs/lib/compiler/passes/inference-match-result.js +++ b/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 ); diff --git a/packages/pegjs/lib/compiler/passes/remove-proxy-rules.js b/packages/pegjs/lib/compiler/passes/remove-proxy-rules.js index 2365a05..749ca31 100644 --- a/packages/pegjs/lib/compiler/passes/remove-proxy-rules.js +++ b/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; - } + }, } ); diff --git a/packages/pegjs/lib/compiler/passes/report-duplicate-labels.js b/packages/pegjs/lib/compiler/passes/report-duplicate-labels.js index c4811a0..27ad6d7 100644 --- a/packages/pegjs/lib/compiler/passes/report-duplicate-labels.js +++ b/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 ); diff --git a/packages/pegjs/lib/compiler/passes/report-duplicate-rules.js b/packages/pegjs/lib/compiler/passes/report-duplicate-rules.js index 908ff99..1dc6b75 100644 --- a/packages/pegjs/lib/compiler/passes/report-duplicate-rules.js +++ b/packages/pegjs/lib/compiler/passes/report-duplicate-rules.js @@ -25,7 +25,7 @@ function reportDuplicateRules( ast, session ) { rules[ node.name ] = node.location; - } + }, } ); check( ast ); diff --git a/packages/pegjs/lib/compiler/passes/report-infinite-recursion.js b/packages/pegjs/lib/compiler/passes/report-infinite-recursion.js index fab4109..b840fe7 100644 --- a/packages/pegjs/lib/compiler/passes/report-infinite-recursion.js +++ b/packages/pegjs/lib/compiler/passes/report-infinite-recursion.js @@ -51,7 +51,7 @@ function reportInfiniteRecursion( ast, session ) { check( ast.findRule( node.name ) ); - } + }, } ); check( ast ); diff --git a/packages/pegjs/lib/compiler/passes/report-infinite-repetition.js b/packages/pegjs/lib/compiler/passes/report-infinite-repetition.js index ef6548d..c53befb 100644 --- a/packages/pegjs/lib/compiler/passes/report-infinite-repetition.js +++ b/packages/pegjs/lib/compiler/passes/report-infinite-repetition.js @@ -29,7 +29,7 @@ function reportInfiniteRepetition( ast, session ) { } - } + }, } ); check( ast ); diff --git a/packages/pegjs/lib/compiler/passes/report-undefined-rules.js b/packages/pegjs/lib/compiler/passes/report-undefined-rules.js index e26c092..e12b6e3 100644 --- a/packages/pegjs/lib/compiler/passes/report-undefined-rules.js +++ b/packages/pegjs/lib/compiler/passes/report-undefined-rules.js @@ -15,7 +15,7 @@ function reportUndefinedRules( ast, session, options ) { } - } + }, } ); check( ast ); diff --git a/packages/pegjs/lib/peg.js b/packages/pegjs/lib/peg.js index 15e9e26..97c807b 100644 --- a/packages/pegjs/lib/peg.js +++ b/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; diff --git a/packages/pegjs/lib/util/js.js b/packages/pegjs/lib/util/js.js index b3e8392..40f1f24 100644 --- a/packages/pegjs/lib/util/js.js +++ b/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 ); }, diff --git a/src/pegjs.config.js b/src/pegjs.config.js index d5468b8..c1614a4 100644 --- a/src/pegjs.config.js +++ b/src/pegjs.config.js @@ -10,7 +10,7 @@ module.exports = { dependencies: { ast: "./ast", - util: "./util" + util: "./util", }, diff --git a/test/api/generated-parser-api.spec.js b/test/api/generated-parser-api.spec.js index 9544fa1..452564a 100644 --- a/test/api/generated-parser-api.spec.js +++ b/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() }; diff --git a/test/api/pegjs-api.spec.js b/test/api/pegjs-api.spec.js index b73268d..4f4f334 100644 --- a/test/api/pegjs-api.spec.js +++ b/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 ); diff --git a/test/api/pegjs-util.spec.js b/test/api/pegjs-util.spec.js index a5dfa3d..d4c4d44 100644 --- a/test/api/pegjs-util.spec.js +++ b/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, + ], } ) ); } ); diff --git a/test/api/plugin-api.spec.js b/test/api/plugin-api.spec.js index de3e610..bef8839 100644 --- a/test/api/plugin-api.spec.js +++ b/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( () => { diff --git a/test/behavior/generated-parser-behavior.spec.js b/test/behavior/generated-parser-behavior.spec.js index 6e5cde0..e37e00a 100644 --- a/test/behavior/generated-parser-behavior.spec.js +++ b/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" + 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 expect( parser ).to.parse( "1\nx", { // Unix 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 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", location: { 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 },", " end: { offset: 2, line: 1, column: 3 }", " });", - "}" + "}", ].join( "\n" ), options ); expect( parser ).to.failToParse( "a", { @@ -1707,8 +1705,8 @@ describe( "generated parser behavior", function () { found: "a", location: { 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, location: { 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 },", " end: { offset: 2, line: 1, column: 3 }", " });", - "}" + "}", ].join( "\n" ), options ); expect( parser ).to.failToParse( "a", { @@ -1753,8 +1751,8 @@ describe( "generated parser behavior", function () { found: null, location: { 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 ); 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 ); 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 ); 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: [ { type: "literal", text: "a", 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( [ "Statement = '{' __ !Statement Statement __ '}'", - "__ = [ ]*" + "__ = [ ]*", ].join( "\n" ), options ); expect( parser ).to.failToParse( "{x}", { expected: [ { type: "class", parts: [ " " ], inverted: false, 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 @@ -1894,14 +1892,14 @@ describe( "generated parser behavior", function () { parser = peg.generate( [ "Start = Char+ End", "End = 'e'", - "Char = !End [a-z]" + "Char = !End [a-z]", ].join( "\n" ), options ); expect( parser ).to.failToParse( "a", { expected: [ { 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( [ "Start = Char+ End", "End 'end' = 'e'", - "Char = !End [a-z]" + "Char = !End [a-z]", ].join( "\n" ), options ); expect( parser ).to.failToParse( "a", { expected: [ { 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 ); 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 ); 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 ); 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 ); 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 ); 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 ); 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 ); 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( "", { location: { 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", { location: { 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", { location: { 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)*", "line = digit (' '+ digit)*", "digit = [0-9]", - "nl = '\\r'? '\\n'" + "nl = '\\r'? '\\n'", ].join( "\n" ), options ); expect( parser ).to.failToParse( "1\n2\n\n3\n\n\n4 5 x", { location: { start: { offset: 13, line: 7, column: 5 }, - end: { offset: 14, line: 7, column: 6 } - } + end: { offset: 14, line: 7, column: 6 }, + }, } ); // Newline representations expect( parser ).to.failToParse( "1\nx", { // Old Mac location: { 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 location: { 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);", " }", "Value = digits:[0-9]+ { return parseInt(digits.join(''), 10); }", - " / '(' expr:Expr ')' { return expr; }" + " / '(' expr:Expr ')' { return expr; }", ].join( "\n" ), options ); // The "value" rule @@ -2162,7 +2160,7 @@ describe( "generated parser behavior", function () { const parser = peg.generate( [ "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(''); }", - "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 ); expect( parser ).to.parse( "abc", "abc" ); @@ -2189,7 +2187,7 @@ describe( "generated parser behavior", function () { " / !Begin !End z:Z { return z; }", "Z = .", "Begin = '(*'", - "End = '*)'" + "End = '*)'", ].join( "\n" ), options ); expect( parser ).to.parse( "(**)", "(**)" ); diff --git a/test/browser.stub.js b/test/browser.stub.js index e374d93..218a4a1 100644 --- a/test/browser.stub.js +++ b/test/browser.stub.js @@ -1,3 +1,5 @@ +/* globals mocha */ + "use strict"; /* diff --git a/test/unit/compiler/passes/generate-bytecode.spec.js b/test/unit/compiler/passes/generate-bytecode.spec.js index b027f13..0c4fac8 100644 --- a/test/unit/compiler/passes/generate-bytecode.spec.js +++ b/test/unit/compiler/passes/generate-bytecode.spec.js @@ -1,3 +1,5 @@ +/* eslint-disable function-call-argument-newline */ + "use strict"; const chai = require( "chai" ); @@ -13,7 +15,7 @@ describe( "compiler pass |generateBytecode|", function () { function bytecodeDetails( bytecode ) { return { - rules: [ { bytecode: bytecode } ] + rules: [ { bytecode: bytecode } ], }; } @@ -24,7 +26,7 @@ describe( "compiler pass |generateBytecode|", function () { literals: literals, classes: classes, expectations: expectations, - functions: functions + functions: functions, }; } @@ -36,13 +38,13 @@ describe( "compiler pass |generateBytecode|", function () { expect( pass ).to.changeAST( [ "a = 'a'", "b = 'b'", - "c = 'c'" + "c = 'c'", ].join( "\n" ), { rules: [ { bytecode: [ 23, 0, 18, 0, 2, 1, 22, 0, 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( [ "a = 'a'", "b = 'b'", - "c = 'c'" + "c = 'c'", ].join( "\n" ), constsDetails( [ "a", "b", "c" ], [], [ { type: "literal", value: "a", 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 () { expect( pass ).to.changeAST( "start = 'a'", bytecodeDetails( [ - 23, 0, 18, 0, 2, 1, 22, 0, 3 // + 23, 0, 18, 0, 2, 1, 22, 0, 3, // ] ) ); } ); @@ -94,19 +96,19 @@ describe( "compiler pass |generateBytecode|", function () { 23, 0, // EXPECT <0> 28, // SILENT_FAILS_ON 17, 2, 1, 21, 1, 3, // - 29 // SILENT_FAILS_OFF + 29, // SILENT_FAILS_OFF ] ) ); expect( pass ).to.changeAST( grammar2, bytecodeDetails( [ 23, 0, // EXPECT <0> 28, // SILENT_FAILS_ON 18, 0, 2, 1, 22, 0, 3, // - 29 // SILENT_FAILS_OFF + 29, // SILENT_FAILS_OFF ] ) ); expect( pass ).to.changeAST( grammar3, bytecodeDetails( [ 23, 0, // EXPECT <0> 28, // SILENT_FAILS_ON 20, 0, 2, 1, 21, 1, 3, // - 29 // SILENT_FAILS_OFF + 29, // SILENT_FAILS_OFF ] ) ); } ); @@ -154,15 +156,9 @@ describe( "compiler pass |generateBytecode|", function () { it( "defines correct constants", function () { - expect( pass ).to.changeAST( grammar1, constsDetails( - [], [], [], [] - ), {}, { 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 } ); + expect( pass ).to.changeAST( grammar1, constsDetails( [], [], [], [] ), {}, { 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, // 14, 10, 0, // IF_ERROR 6, // * POP - 23, 2, 18, 2, 2, 1, 22, 2, 3 // + 23, 2, 18, 2, 2, 1, 22, 2, 3, // ] ) ); } ); @@ -202,7 +198,7 @@ describe( "compiler pass |generateBytecode|", function () { 15, 6, 0, // IF_NOT_ERROR 24, 1, // * LOAD_SAVED_POS 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 24, 1, // * LOAD_SAVED_POS 26, 0, 1, 1, 0, // CALL <0> - 9 // NIP + 9, // NIP ] ) ); } ); @@ -274,7 +270,7 @@ describe( "compiler pass |generateBytecode|", function () { 3, // PUSH_FAILED 6, // * POP 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: "b", ignoreCase: false }, - { type: "literal", value: "c", ignoreCase: false } + { type: "literal", value: "c", ignoreCase: false }, ], [ { predicate: false, params: [ "a", "b", "c" ], body: " code " } ] ) ); @@ -322,7 +318,7 @@ describe( "compiler pass |generateBytecode|", function () { 3, // PUSH_FAILED 6, // * POP 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: "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 () { expect( pass ).to.changeAST( "start = a:'a'", bytecodeDetails( [ - 23, 0, 18, 0, 2, 1, 22, 0, 3 // + 23, 0, 18, 0, 2, 1, 22, 0, 3, // ] ) ); } ); @@ -410,7 +406,7 @@ describe( "compiler pass |generateBytecode|", function () { 15, 2, 1, // IF_NOT_ERROR 6, // * POP 12, // TEXT - 9 // * NIP + 9, // * NIP ] ) ); } ); @@ -434,7 +430,7 @@ describe( "compiler pass |generateBytecode|", function () { 1, // PUSH_UNDEFINED 6, // * POP 6, // POP - 3 // PUSH_FAILED + 3, // PUSH_FAILED ] ) ); } ); @@ -469,7 +465,7 @@ describe( "compiler pass |generateBytecode|", function () { 1, // PUSH_UNDEFINED 6, // * POP 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, // 14, 2, 0, // IF_ERROR 6, // * POP - 2 // PUSH_NULL + 2, // PUSH_NULL ] ) ); } ); @@ -527,7 +523,7 @@ describe( "compiler pass |generateBytecode|", function () { 16, 10, // WHILE_NOT_ERROR 10, // * APPEND 23, 0, 18, 0, 2, 1, 22, 0, 3, // - 6 // POP + 6, // POP ] ) ); } ); @@ -561,7 +557,7 @@ describe( "compiler pass |generateBytecode|", function () { 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 () { expect( pass ).to.changeAST( grammar, bytecodeDetails( [ - 23, 0, 18, 0, 2, 1, 22, 0, 3 // + 23, 0, 18, 0, 2, 1, 22, 0, 3, // ] ) ); } ); @@ -619,7 +615,7 @@ describe( "compiler pass |generateBytecode|", function () { 6, // * POP 1, // PUSH_UNDEFINED 6, // * POP - 3 // PUSH_FAILED + 3, // PUSH_FAILED ] ) ); } ); @@ -670,7 +666,7 @@ describe( "compiler pass |generateBytecode|", function () { 3, // PUSH_FAILED 6, // * POP 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: "b", ignoreCase: false }, - { type: "literal", value: "c", ignoreCase: false } + { type: "literal", value: "c", ignoreCase: false }, ], [ { predicate: true, params: [ "a", "b", "c" ], body: " code " } ] ) ); @@ -709,7 +705,7 @@ describe( "compiler pass |generateBytecode|", function () { 6, // * POP 3, // PUSH_FAILED 6, // * POP - 1 // PUSH_UNDEFINED + 1, // PUSH_UNDEFINED ] ) ); } ); @@ -760,7 +756,7 @@ describe( "compiler pass |generateBytecode|", function () { 3, // PUSH_FAILED 6, // * POP 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: "b", ignoreCase: false }, - { type: "literal", value: "c", ignoreCase: false } + { type: "literal", value: "c", ignoreCase: false }, ], [ { predicate: true, params: [ "a", "b", "c" ], body: " code " } ] ) ); @@ -790,14 +786,14 @@ describe( "compiler pass |generateBytecode|", function () { expect( pass ).to.changeAST( [ "start = other", - "other = 'other'" + "other = 'other'", ].join( "\n" ), { rules: [ { - bytecode: [ 27, 1 ] // RULE + bytecode: [ 27, 1 ], // RULE }, - { } - ] + { }, + ], } ); } ); @@ -815,7 +811,7 @@ describe( "compiler pass |generateBytecode|", function () { it( "generates correct bytecode", function () { 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> 18, 0, 2, 1, // MATCH_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> 19, 0, 2, 1, // MATCH_STRING_IC <0> 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 () { expect( pass ).to.changeAST( grammar, bytecodeDetails( [ - 0 // PUSH_EMPTY_STRING + 0, // PUSH_EMPTY_STRING ] ), {}, { reportFailures: false } ); } ); @@ -917,16 +913,14 @@ describe( "compiler pass |generateBytecode|", function () { expect( pass ).to.changeAST( grammar, bytecodeDetails( [ 18, 0, 2, 1, // MATCH_STRING <0> 22, 0, // * ACCEPT_STRING <0> - 3 // * PUSH_FAILED + 3, // * PUSH_FAILED ] ), {}, { reportFailures: false } ); } ); it( "defines correct constants", function () { - expect( pass ).to.changeAST( grammar, constsDetails( - [ "a" ], [], [], [] - ), {}, { reportFailures: false } ); + expect( pass ).to.changeAST( grammar, constsDetails( [ "a" ], [], [], [] ), {}, { reportFailures: false } ); } ); @@ -941,16 +935,14 @@ describe( "compiler pass |generateBytecode|", function () { expect( pass ).to.changeAST( grammar, bytecodeDetails( [ 19, 0, 2, 1, // MATCH_STRING_IC <0> 21, 1, // * ACCEPT_N <1> - 3 // * PUSH_FAILED + 3, // * PUSH_FAILED ] ), {}, { reportFailures: false } ); } ); it( "defines correct constants", function () { - expect( pass ).to.changeAST( grammar, constsDetails( - [ "a" ], [], [], [] - ), {}, { reportFailures: false } ); + expect( pass ).to.changeAST( grammar, constsDetails( [ "a" ], [], [], [] ), {}, { reportFailures: false } ); } ); @@ -970,7 +962,7 @@ describe( "compiler pass |generateBytecode|", function () { 23, 0, // EXPECT <0> 20, 0, 2, 1, // MATCH_CLASS <0> 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" ] ], inverted: false, - ignoreCase: false - } + ignoreCase: false, + }, ], [ { type: "class", value: [ "a", [ "b", "d" ], "e", [ "f", "h" ], "i", [ "j", "l" ] ], inverted: false, - ignoreCase: false - } + ignoreCase: false, + }, ], [] ) ); @@ -1057,7 +1049,7 @@ describe( "compiler pass |generateBytecode|", function () { expect( pass ).to.changeAST( "start = [a]", bytecodeDetails( [ 20, 0, 2, 1, // MATCH_CLASS <0> 21, 1, // * ACCEPT_N <1> - 3 // * PUSH_FAILED + 3, // * PUSH_FAILED ] ), {}, { reportFailures: false } ); } ); @@ -1066,9 +1058,7 @@ describe( "compiler pass |generateBytecode|", function () { it( "defines correct constants", function () { - expect( pass ).to.changeAST( "start = [a]", constsDetails( - [], [ { value: [ "a" ], inverted: false, ignoreCase: false } ], [], [] - ), {}, { reportFailures: false } ); + expect( pass ).to.changeAST( "start = [a]", constsDetails( [], [ { value: [ "a" ], inverted: false, ignoreCase: false } ], [], [] ), {}, { reportFailures: false } ); } ); @@ -1078,9 +1068,7 @@ describe( "compiler pass |generateBytecode|", function () { it( "defines correct constants", function () { - expect( pass ).to.changeAST( "start = [^a]", constsDetails( - [], [ { value: [ "a" ], inverted: true, ignoreCase: false } ], [], [] - ), {}, { reportFailures: false } ); + expect( pass ).to.changeAST( "start = [^a]", constsDetails( [], [ { value: [ "a" ], inverted: true, ignoreCase: false } ], [], [] ), {}, { reportFailures: false } ); } ); @@ -1090,9 +1078,7 @@ describe( "compiler pass |generateBytecode|", function () { it( "defines correct constants", function () { - expect( pass ).to.changeAST( "start = [a]i", constsDetails( - [], [ { value: [ "a" ], inverted: false, ignoreCase: true } ], [], [] - ), {}, { reportFailures: false } ); + expect( pass ).to.changeAST( "start = [a]i", constsDetails( [], [ { 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" ] ], inverted: false, - ignoreCase: false - } + ignoreCase: false, + }, ], [], [] @@ -1135,7 +1121,7 @@ describe( "compiler pass |generateBytecode|", function () { 23, 0, // EXPECT <0> 17, 2, 1, // MATCH_ANY 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( [ 17, 2, 1, // MATCH_ANY 21, 1, // * ACCEPT_N <1> - 3 // * PUSH_FAILED + 3, // * PUSH_FAILED ] ), {}, { reportFailures: false } ); } ); diff --git a/test/unit/compiler/passes/inference-match-result.spec.js b/test/unit/compiler/passes/inference-match-result.spec.js index 14e69c5..3e4542e 100644 --- a/test/unit/compiler/passes/inference-match-result.spec.js +++ b/test/unit/compiler/passes/inference-match-result.spec.js @@ -140,17 +140,20 @@ describe( "compiler pass |inferenceMatchResult|", function () { expect( pass ).to.changeAST( [ "start = end", "end = . " ].join( "\n" ), { rules: [ { match: 0 }, { match: 0 } ] }, - {}, {} + {}, + {} ); expect( pass ).to.changeAST( [ "start = end", "end = ''" ].join( "\n" ), { rules: [ { match: 1 }, { match: 1 } ] }, - {}, {} + {}, + {} ); expect( pass ).to.changeAST( [ "start = end", "end = []" ].join( "\n" ), { rules: [ { match: -1 }, { match: -1 } ] }, - {}, {} + {}, + {} ); expect( pass ).to.changeAST( "start = . start", { rules: [ { match: 0 } ] }, {}, {} ); diff --git a/test/unit/compiler/passes/remove-proxy-rules.spec.js b/test/unit/compiler/passes/remove-proxy-rules.spec.js index 4b4520a..287bc22 100644 --- a/test/unit/compiler/passes/remove-proxy-rules.spec.js +++ b/test/unit/compiler/passes/remove-proxy-rules.spec.js @@ -18,16 +18,16 @@ describe( "compiler pass |removeProxyRules|", function () { [ "start = proxy", "proxy = proxied", - "proxied = 'a'" + "proxied = 'a'", ].join( "\n" ), { rules: [ { name: "start", - expression: { type: "rule_ref", name: "proxied" } + expression: { type: "rule_ref", name: "proxied" }, }, - { name: "proxied" } - ] + { name: "proxied" }, + ], }, { allowedStartRules: [ "start" ] } ); @@ -44,20 +44,20 @@ describe( "compiler pass |removeProxyRules|", function () { [ "start = proxy", "proxy = proxied", - "proxied = 'a'" + "proxied = 'a'", ].join( "\n" ), { rules: [ { name: "start", - expression: { type: "rule_ref", name: "proxied" } + expression: { type: "rule_ref", name: "proxied" }, }, { name: "proxy", - expression: { type: "rule_ref", name: "proxied" } + expression: { type: "rule_ref", name: "proxied" }, }, - { name: "proxied" } - ] + { name: "proxied" }, + ], }, { allowedStartRules: [ "start", "proxy" ] } ); diff --git a/test/unit/compiler/passes/report-duplicate-labels.spec.js b/test/unit/compiler/passes/report-duplicate-labels.spec.js index fb4e01c..d9ae327 100644 --- a/test/unit/compiler/passes/report-duplicate-labels.spec.js +++ b/test/unit/compiler/passes/report-duplicate-labels.spec.js @@ -18,8 +18,8 @@ describe( "compiler pass |reportDuplicateLabels|", function () { message: "Label \"a\" is already defined at line 1, column 9.", location: { 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.", location: { start: { offset: 15, line: 1, column: 16 }, - end: { offset: 20, line: 1, column: 21 } - } + end: { offset: 20, line: 1, column: 21 }, + }, } ); } ); diff --git a/test/unit/compiler/passes/report-duplicate-rules.spec.js b/test/unit/compiler/passes/report-duplicate-rules.spec.js index 7b405ff..a593e5c 100644 --- a/test/unit/compiler/passes/report-duplicate-rules.spec.js +++ b/test/unit/compiler/passes/report-duplicate-rules.spec.js @@ -14,13 +14,13 @@ describe( "compiler pass |reportDuplicateRules|", function () { expect( pass ).to.reportError( [ "start = 'a'", - "start = 'b'" + "start = 'b'", ].join( "\n" ), { message: "Rule \"start\" is already defined at line 1, column 1.", location: { start: { offset: 12, line: 2, column: 1 }, - end: { offset: 23, line: 2, column: 12 } - } + end: { offset: 23, line: 2, column: 12 }, + }, } ); } ); diff --git a/test/unit/compiler/passes/report-incorrect-plucking.spec.js b/test/unit/compiler/passes/report-incorrect-plucking.spec.js index 0901a6c..72cbd6d 100644 --- a/test/unit/compiler/passes/report-incorrect-plucking.spec.js +++ b/test/unit/compiler/passes/report-incorrect-plucking.spec.js @@ -21,14 +21,14 @@ describe( "compiler pass |reportIncorrectPlucking|", function () { reports( `"@" cannot be used with an 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.`, [ `start1 = 'a' @&{ /* semantic_and */ } 'c'`, - `start2 = 'a' @!{ /* semantic_not */ } 'c'` + `start2 = 'a' @!{ /* semantic_not */ } 'c'`, ] ); diff --git a/test/unit/compiler/passes/report-infinite-recursion.spec.js b/test/unit/compiler/passes/report-infinite-recursion.spec.js index d99f2a8..d38ea5e 100644 --- a/test/unit/compiler/passes/report-infinite-recursion.spec.js +++ b/test/unit/compiler/passes/report-infinite-recursion.spec.js @@ -16,8 +16,8 @@ describe( "compiler pass |reportInfiniteRecursion|", function () { message: "Possible infinite loop when parsing (left recursion: start -> start).", location: { 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( [ "start = stop", - "stop = start" + "stop = start", ].join( "\n" ), { message: "Possible infinite loop when parsing (left recursion: start -> stop -> start).", location: { 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( [ "start = a start", - "a 'a' = ''" + "a 'a' = ''", ].join( "\n" ) ); expect( pass ).to.not.reportError( [ "start = a start", - "a 'a' = 'a'" + "a 'a' = 'a'", ].join( "\n" ) ); expect( pass ).to.reportError( "start = ('' / 'a' / 'b') start" ); @@ -114,11 +114,11 @@ describe( "compiler pass |reportInfiniteRecursion|", function () { expect( pass ).to.reportError( [ "start = a start", - "a = ''" + "a = ''", ].join( "\n" ) ); expect( pass ).to.not.reportError( [ "start = a start", - "a = 'a'" + "a = 'a'", ].join( "\n" ) ); expect( pass ).to.reportError( "start = '' start" ); diff --git a/test/unit/compiler/passes/report-infinite-repetition.spec.js b/test/unit/compiler/passes/report-infinite-repetition.spec.js index cd7ac97..168a50a 100644 --- a/test/unit/compiler/passes/report-infinite-repetition.spec.js +++ b/test/unit/compiler/passes/report-infinite-repetition.spec.js @@ -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).", location: { 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).", location: { 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( [ "start = a*", - "a 'a' = ''" + "a 'a' = ''", ].join( "\n" ) ); expect( pass ).to.not.reportError( [ "start = a*", - "a 'a' = 'a'" + "a 'a' = 'a'", ].join( "\n" ) ); expect( pass ).to.reportError( "start = ('' / 'a' / 'b')*" ); @@ -88,11 +88,11 @@ describe( "compiler pass |reportInfiniteRepetition|", function () { expect( pass ).to.reportError( [ "start = a*", - "a = ''" + "a = ''", ].join( "\n" ) ); expect( pass ).to.not.reportError( [ "start = a*", - "a = 'a'" + "a = 'a'", ].join( "\n" ) ); expect( pass ).to.reportError( "start = ''*" ); diff --git a/test/unit/compiler/passes/report-undefined-rules.spec.js b/test/unit/compiler/passes/report-undefined-rules.spec.js index 09eebf2..3955fbc 100644 --- a/test/unit/compiler/passes/report-undefined-rules.spec.js +++ b/test/unit/compiler/passes/report-undefined-rules.spec.js @@ -16,19 +16,23 @@ describe( "compiler pass |reportUndefinedRules|", function () { message: "Rule \"undefined\" is not defined.", location: { 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 () { - expect( pass ).to.reportError( "start = 'a'", { - message: "Start rule \"missing\" is not defined." - }, { - allowedStartRules: [ "missing" ] - } ); + expect( pass ).to.reportError( + "start = 'a'", + { + message: "Start rule \"missing\" is not defined.", + }, + { + allowedStartRules: [ "missing" ], + } + ); } ); diff --git a/test/unit/compiler/passes/report-unused-rules.spec.js b/test/unit/compiler/passes/report-unused-rules.spec.js index 3638357..fae13d3 100644 --- a/test/unit/compiler/passes/report-unused-rules.spec.js +++ b/test/unit/compiler/passes/report-unused-rules.spec.js @@ -28,7 +28,7 @@ describe( "compiler pass |reportUnusedRules|", function () { `, [ `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, { - allowedStartRules: [ "b", "c" ] + allowedStartRules: [ "b", "c" ], } ); diff --git a/test/unit/parser.spec.js b/test/unit/parser.spec.js index d05ea3a..5e298f7 100644 --- a/test/unit/parser.spec.js +++ b/test/unit/parser.spec.js @@ -17,7 +17,7 @@ function varyParserOptions( block ) { const optionsVariants = [ { }, { extractComments: false }, - { extractComments: true } + { extractComments: true }, ]; optionsVariants.forEach( variant => { @@ -53,15 +53,15 @@ describe( "PEG.js grammar parser", function () { const labeledSimpleNot = { type: "labeled", label: "a", expression: simpleNotAbcd }; const sequence = { type: "sequence", - elements: [ literalAbcd, literalEfgh, literalIjkl ] + elements: [ literalAbcd, literalEfgh, literalIjkl ], }; const sequence2 = { type: "sequence", - elements: [ labeledAbcd, labeledEfgh ] + elements: [ labeledAbcd, labeledEfgh ], }; const sequence4 = { type: "sequence", - elements: [ labeledAbcd, labeledEfgh, labeledIjkl, labeledMnop ] + elements: [ labeledAbcd, labeledEfgh, labeledIjkl, labeledMnop ], }; const groupLabeled = { type: "group", expression: labeledAbcd }; 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 choice = { type: "choice", - alternatives: [ literalAbcd, literalEfgh, literalIjkl ] + alternatives: [ literalAbcd, literalEfgh, literalIjkl ], }; const choice2 = { type: "choice", - alternatives: [ actionAbcd, actionEfgh ] + alternatives: [ actionAbcd, actionEfgh ], }; const choice4 = { type: "choice", - alternatives: [ actionAbcd, actionEfgh, actionIjkl, actionMnop ] + alternatives: [ actionAbcd, actionEfgh, actionIjkl, actionMnop ], }; const named = { type: "named", name: "start rule", expression: literalAbcd }; const ruleA = { type: "rule", name: "a", expression: literalAbcd }; @@ -95,7 +95,7 @@ describe( "PEG.js grammar parser", function () { type: "grammar", initializer: 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", parts: parts, inverted: inverted, - ignoreCase: ignoreCase + ignoreCase: ignoreCase, } ); } @@ -145,7 +145,7 @@ describe( "PEG.js grammar parser", function () { result[ comment.offset ] = { text: comment.text, - multiline: comment.multiline + multiline: comment.multiline, }; return result; @@ -163,7 +163,7 @@ describe( "PEG.js grammar parser", function () { type: "grammar", initializer: null, comments: null, - rules: [ ruleA, ruleB ] + rules: [ ruleA, ruleB ], }; const stripProperties = ( function () { @@ -235,7 +235,7 @@ describe( "PEG.js grammar parser", function () { rule_ref: stripLeaf, literal: stripLeaf, class: stripLeaf, - any: stripLeaf + any: stripLeaf, } ); return strip; @@ -327,7 +327,7 @@ describe( "PEG.js grammar parser", function () { const grammar = ruleRefGrammar( "a" ); grammar.initializer = { "type": "initializer", - "code": "" + "code": "", }; expect( "{}\nstart = a" ).to.parseAs( grammar ); @@ -432,7 +432,7 @@ describe( "PEG.js grammar parser", function () { return oneRuleGrammar( { type: "sequence", - elements: elements + elements: elements, } ); } @@ -442,7 +442,7 @@ describe( "PEG.js grammar parser", function () { type: "labeled", pick: true, label: label, - expression: expression + expression: expression, }; } @@ -591,27 +591,17 @@ describe( "PEG.js grammar parser", function () { // Canonical Comment is "/* comment */". it( "parses Comment", function () { - expect( "start =// comment\n'abcd'" ).to.parseAs( commented( - trivialGrammar, [ { offset: 7, text: " comment", multiline: false } ], options - ), options ); - expect( "start =/* comment */'abcd'" ).to.parseAs( commented( - trivialGrammar, [ { offset: 7, text: " comment ", multiline: true } ], options - ), options ); + expect( "start =// comment\n'abcd'" ).to.parseAs( commented( trivialGrammar, [ { offset: 7, text: " comment", multiline: false } ], options ), options ); + expect( "start =/* comment */'abcd'" ).to.parseAs( commented( trivialGrammar, [ { offset: 7, text: " comment ", multiline: true } ], options ), options ); } ); // Canonical MultiLineComment is "/* comment */". it( "parses MultiLineComment", function () { - expect( "start =/**/'abcd'" ).to.parseAs( commented( - trivialGrammar, [ { offset: 7, text: "", 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.parseAs( commented( trivialGrammar, [ { offset: 7, text: "", 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(); @@ -620,15 +610,9 @@ describe( "PEG.js grammar parser", function () { // Canonical MultiLineCommentNoLineTerminator is "/* comment */". it( "parses MultiLineCommentNoLineTerminator", function () { - expect( "a = 'abcd'/**/\r\nb = 'efgh'" ).to.parseAs( commented( - twoRuleGrammar, [ { offset: 10, text: "", 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.parseAs( commented( twoRuleGrammar, [ { offset: 10, text: "", 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'/*\n*/\r\nb = 'efgh'" ).to.failToParse(); @@ -638,15 +622,9 @@ describe( "PEG.js grammar parser", function () { // Canonical SingleLineComment is "// comment". it( "parses SingleLineComment", function () { - expect( "start =//\n'abcd'" ).to.parseAs( commented( - trivialGrammar, [ { offset: 7, text: "", 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'abcd'" ).to.parseAs( commented( trivialGrammar, [ { offset: 7, text: "", 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(); @@ -780,7 +758,7 @@ describe( "PEG.js grammar parser", function () { expect( "start = [a-a]" ).to.parseAs( classGrammar( [ [ "a", "a" ] ], false, false ) ); 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 errorLocation = { 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 ) ) .to.throw( "Unbalanced brace." ) diff --git a/tools/benchmark/benchmarks.js b/tools/benchmark/benchmarks.js index 4a67732..223f1ca 100644 --- a/tools/benchmark/benchmarks.js +++ b/tools/benchmark/benchmarks.js @@ -10,8 +10,8 @@ const benchmarks = [ { file: "example2.json", title: "Example 2" }, { file: "example3.json", title: "Example 3" }, { 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/print.css", title: "Blueprint - print.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)" }, + ], }, ]; diff --git a/tools/benchmark/browser.stub.js b/tools/benchmark/browser.stub.js index 1c9b1d2..2e4e2a2 100644 --- a/tools/benchmark/browser.stub.js +++ b/tools/benchmark/browser.stub.js @@ -63,7 +63,7 @@ $( "#run" ).click( () => { const runCount = parseInt( $( "#run-count" ).val(), 10 ); const options = { cache: $( "#cache" ).is( ":checked" ), - optimize: $( "#optimize" ).val() + optimize: $( "#optimize" ).val(), }; if ( isNaN( runCount ) || runCount <= 0 ) { @@ -82,7 +82,7 @@ $( "#run" ).click( () => { type: "GET", url: `https://raw.githubusercontent.com/pegjs/pegjs/${ BRANCH }/` + file, dataType: "text", - async: false + async: false, } ).responseText; }, @@ -149,7 +149,7 @@ $( "#run" ).click( () => { $.scrollTo( "max", { axis: "y", duration: 500 } ); $( "#run-count, #cache, #run" ).removeAttr( "disabled" ); - } + }, } ); diff --git a/tools/benchmark/index.js b/tools/benchmark/index.js index f137940..8b6ee28 100644 --- a/tools/benchmark/index.js +++ b/tools/benchmark/index.js @@ -140,7 +140,7 @@ function nextArg() { let runCount = 10; const options = { cache: false, - optimize: "speed" + optimize: "speed", }; while ( args.length > 0 && isOption( args[ 0 ] ) ) { diff --git a/tools/benchmark/runner.js b/tools/benchmark/runner.js index 01094dd..7a5f20e 100644 --- a/tools/benchmark/runner.js +++ b/tools/benchmark/runner.js @@ -34,7 +34,7 @@ const Runner = { } - } + }, }; @@ -147,7 +147,7 @@ const Runner = { Q.run(); - } + }, }; diff --git a/tools/bundler/babel.config.js b/tools/bundler/babel.config.js index 29e462d..41f14c5 100644 --- a/tools/bundler/babel.config.js +++ b/tools/bundler/babel.config.js @@ -10,10 +10,10 @@ module.exports = { { "modules": false, "targets": { - "ie": 11 - } - } - ] - ] + "ie": 11, + }, + }, + ], + ], }; diff --git a/tools/bundler/target.js b/tools/bundler/target.js index e8c0ebd..802cb5d 100644 --- a/tools/bundler/target.js +++ b/tools/bundler/target.js @@ -50,7 +50,7 @@ function target( { entry, library, output } ) { hints: false, }, resolve: { - extensions: [ ".ts", ".js" ] + extensions: [ ".ts", ".js" ], }, module: { rules: [ @@ -72,7 +72,7 @@ function target( { entry, library, output } ) { new webpack.BannerPlugin( { banner: HEADER, raw: true, - } ) + } ), ], };