diff --git a/benchmark/index.js b/benchmark/index.js index 0bd78e7..03ae562 100644 --- a/benchmark/index.js +++ b/benchmark/index.js @@ -72,7 +72,7 @@ $("#run").click(() => { } Runner.run(benchmarks, runCount, options, { - readFile: function(file) { + readFile(file) { return $.ajax({ type: "GET", url: file, @@ -81,11 +81,11 @@ $("#run").click(() => { }).responseText; }, - testStart: function() { + testStart() { // Nothing to do. }, - testFinish: function(benchmark, test, inputSize, parseTime) { + testFinish(benchmark, test, inputSize, parseTime) { appendResult( "individual", test.title, @@ -95,11 +95,11 @@ $("#run").click(() => { ); }, - benchmarkStart: function(benchmark) { + benchmarkStart(benchmark) { appendHeading(benchmark.title); }, - benchmarkFinish: function(benchmark, inputSize, parseTime) { + benchmarkFinish(benchmark, inputSize, parseTime) { appendResult( "benchmark-total", benchmark.title + " total", @@ -109,14 +109,14 @@ $("#run").click(() => { ); }, - start: function() { + start() { $("#run-count, #cache, #run").attr("disabled", "disabled"); resultsTable.show(); $("#results-table tr").slice(1).remove(); }, - finish: function(inputSize, parseTime) { + finish(inputSize, parseTime) { appendResult( "total", "Total", diff --git a/benchmark/run b/benchmark/run index 8071a75..6f60592 100755 --- a/benchmark/run +++ b/benchmark/run @@ -163,32 +163,32 @@ if (args.length > 0) { } Runner.run(benchmarks, runCount, options, { - readFile: function(file) { + readFile(file) { return fs.readFileSync(__dirname + "/" + file, "utf8"); }, - testStart: function() { + testStart() { // Nothing to do. }, - testFinish: function(benchmark, test, inputSize, parseTime) { + testFinish(benchmark, test, inputSize, parseTime) { writeResult(test.title, inputSize, parseTime); }, - benchmarkStart: function(benchmark) { + benchmarkStart(benchmark) { writeHeading(benchmark.title); }, - benchmarkFinish: function(benchmark, inputSize, parseTime) { + benchmarkFinish(benchmark, inputSize, parseTime) { writeSeparator(); writeResult(benchmark.title + " total", inputSize, parseTime); }, - start: function() { + start() { writeTableHeader(); }, - finish: function(inputSize, parseTime) { + finish(inputSize, parseTime) { writeSeparator(); writeResult("Total", inputSize, parseTime); writeTableFooter(); diff --git a/benchmark/runner.js b/benchmark/runner.js index b885851..861bf7a 100644 --- a/benchmark/runner.js +++ b/benchmark/runner.js @@ -5,17 +5,17 @@ let peg = require("../lib/peg"); let Runner = { - run: function(benchmarks, runCount, options, callbacks) { + run(benchmarks, runCount, options, callbacks) { // Queue let Q = { functions: [], - add: function(f) { + add(f) { this.functions.push(f); }, - run: function() { + run() { if (this.functions.length > 0) { this.functions.shift()(); diff --git a/lib/compiler/asts.js b/lib/compiler/asts.js index cfb1f72..e7f383a 100644 --- a/lib/compiler/asts.js +++ b/lib/compiler/asts.js @@ -4,7 +4,7 @@ let visitor = require("./visitor"); // AST utilities. let asts = { - findRule: function(ast, name) { + findRule(ast, name) { for (let i = 0; i < ast.rules.length; i++) { if (ast.rules[i].name === name) { return ast.rules[i]; @@ -14,7 +14,7 @@ let asts = { return undefined; }, - indexOfRule: function(ast, name) { + indexOfRule(ast, name) { for (let i = 0; i < ast.rules.length; i++) { if (ast.rules[i].name === name) { return i; @@ -24,7 +24,7 @@ let asts = { return -1; }, - alwaysConsumesOnSuccess: function(ast, node) { + alwaysConsumesOnSuccess(ast, node) { function consumesTrue() { return true; } function consumesFalse() { return false; } @@ -36,13 +36,13 @@ let asts = { rule: consumesExpression, named: consumesExpression, - choice: function(node) { + choice(node) { return node.alternatives.every(consumes); }, action: consumesExpression, - sequence: function(node) { + sequence(node) { return node.elements.some(consumes); }, @@ -57,11 +57,11 @@ let asts = { semantic_and: consumesFalse, semantic_not: consumesFalse, - rule_ref: function(node) { + rule_ref(node) { return consumes(asts.findRule(ast, node.name)); }, - literal: function(node) { + literal(node) { return node.value !== ""; }, diff --git a/lib/compiler/index.js b/lib/compiler/index.js index e763fa2..c1f383a 100644 --- a/lib/compiler/index.js +++ b/lib/compiler/index.js @@ -47,7 +47,7 @@ let compiler = { // if the AST contains a semantic error. Note that not all errors are detected // during the generation and some may protrude to the generated parser and // cause its malfunction. - compile: function(ast, passes, options) { + compile(ast, passes, options) { options = options !== undefined ? options : {}; options = processOptions(options, { diff --git a/lib/compiler/js.js b/lib/compiler/js.js index afe2ee1..5a2bea4 100644 --- a/lib/compiler/js.js +++ b/lib/compiler/js.js @@ -4,7 +4,7 @@ function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); } // JavaScript code generation helpers. let js = { - stringEscape: function(s) { + stringEscape(s) { // ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a string // literal except for the closing quote character, backslash, carriage // return, line separator, paragraph separator, and line feed. Any character @@ -27,7 +27,7 @@ let js = { .replace(/[\u1000-\uFFFF]/g, ch => "\\u" + hex(ch)); }, - regexpClassEscape: function(s) { + regexpClassEscape(s) { // Based on ECMA-262, 5th ed., 7.8.5 & 15.10.1. // // For portability, we also escape all control and non-ASCII characters. diff --git a/lib/compiler/passes/generate-bytecode.js b/lib/compiler/passes/generate-bytecode.js index fdebde4..d944f28 100644 --- a/lib/compiler/passes/generate-bytecode.js +++ b/lib/compiler/passes/generate-bytecode.js @@ -288,13 +288,13 @@ function generateBytecode(ast) { } let generate = visitor.build({ - grammar: function(node) { + grammar(node) { node.rules.forEach(generate); node.consts = consts; }, - rule: function(node) { + rule(node) { node.bytecode = generate(node.expression, { sp: -1, // stack pointer env: { }, // mapping of label names to stack positions @@ -302,7 +302,7 @@ function generateBytecode(ast) { }); }, - named: function(node, context) { + named(node, context) { let nameIndex = addConst( "peg$otherExpectation(\"" + js.stringEscape(node.name) + "\")" ); @@ -319,7 +319,7 @@ function generateBytecode(ast) { ); }, - choice: function(node, context) { + choice(node, context) { function buildAlternativesCode(alternatives, context) { return buildSequence( generate(alternatives[0], { @@ -343,7 +343,7 @@ function generateBytecode(ast) { return buildAlternativesCode(node.alternatives, context); }, - action: function(node, context) { + action(node, context) { let env = cloneEnv(context.env); let emitCall = node.expression.type !== "sequence" || node.expression.elements.length === 0; @@ -371,7 +371,7 @@ function generateBytecode(ast) { : expressionCode; }, - sequence: function(node, context) { + sequence(node, context) { function buildElementsCode(elements, context) { if (elements.length > 0) { let processedCount = node.elements.length - elements.slice(1).length; @@ -429,7 +429,7 @@ function generateBytecode(ast) { ); }, - labeled: function(node, context) { + labeled(node, context) { let env = cloneEnv(context.env); context.env[node.label] = context.sp + 1; @@ -441,7 +441,7 @@ function generateBytecode(ast) { }); }, - text: function(node, context) { + text(node, context) { return buildSequence( [op.PUSH_CURR_POS], generate(node.expression, { @@ -457,15 +457,15 @@ function generateBytecode(ast) { ); }, - simple_and: function(node, context) { + simple_and(node, context) { return buildSimplePredicate(node.expression, false, context); }, - simple_not: function(node, context) { + simple_not(node, context) { return buildSimplePredicate(node.expression, true, context); }, - optional: function(node, context) { + optional(node, context) { return buildSequence( generate(node.expression, { sp: context.sp, @@ -480,7 +480,7 @@ function generateBytecode(ast) { ); }, - zero_or_more: function(node, context) { + zero_or_more(node, context) { let expressionCode = generate(node.expression, { sp: context.sp + 1, env: cloneEnv(context.env), @@ -495,7 +495,7 @@ function generateBytecode(ast) { ); }, - one_or_more: function(node, context) { + one_or_more(node, context) { let expressionCode = generate(node.expression, { sp: context.sp + 1, env: cloneEnv(context.env), @@ -513,7 +513,7 @@ function generateBytecode(ast) { ); }, - group: function(node, context) { + group(node, context) { return generate(node.expression, { sp: context.sp, env: cloneEnv(context.env), @@ -521,19 +521,19 @@ function generateBytecode(ast) { }); }, - semantic_and: function(node, context) { + semantic_and(node, context) { return buildSemanticPredicate(node.code, false, context); }, - semantic_not: function(node, context) { + semantic_not(node, context) { return buildSemanticPredicate(node.code, true, context); }, - rule_ref: function(node) { + rule_ref(node) { return [op.RULE, asts.indexOfRule(ast, node.name)]; }, - literal: function(node) { + literal(node) { if (node.value.length > 0) { let stringIndex = addConst("\"" + js.stringEscape( @@ -567,7 +567,7 @@ function generateBytecode(ast) { } }, - class: function(node) { + class(node) { let regexp = "/^[" + (node.inverted ? "^" : "") + node.parts.map(part => @@ -601,7 +601,7 @@ function generateBytecode(ast) { ); }, - any: function() { + any() { let expectedIndex = addConst("peg$anyExpectation()"); return buildCondition( diff --git a/lib/compiler/passes/generate-js.js b/lib/compiler/passes/generate-js.js index 4cc64a3..d0e3a69 100644 --- a/lib/compiler/passes/generate-js.js +++ b/lib/compiler/passes/generate-js.js @@ -414,7 +414,7 @@ function generateJS(ast, options) { sp: -1, maxSp: -1, - push: function(exprCode) { + push(exprCode) { let code = s(++this.sp) + " = " + exprCode + ";"; if (this.sp > this.maxSp) { this.maxSp = this.sp; } @@ -422,7 +422,7 @@ function generateJS(ast, options) { return code; }, - pop: function(n) { + pop(n) { if (n === undefined) { return s(this.sp--); } else { @@ -438,11 +438,11 @@ function generateJS(ast, options) { } }, - top: function() { + top() { return s(this.sp); }, - index: function(i) { + index(i) { return s(this.sp - i); } }; @@ -1223,7 +1223,7 @@ function generateJS(ast, options) { } let generators = { - bare: function() { + bare() { return [ generateGeneratedByComment(), "(function() {", @@ -1236,7 +1236,7 @@ function generateJS(ast, options) { ].join("\n"); }, - commonjs: function() { + commonjs() { let parts = []; let dependencyVars = Object.keys(options.dependencies); @@ -1268,7 +1268,7 @@ function generateJS(ast, options) { return parts.join("\n"); }, - amd: function() { + amd() { let dependencyVars = Object.keys(options.dependencies); let dependencyIds = dependencyIds.map(v => options.dependencies[v]); let dependencies = "[" @@ -1291,7 +1291,7 @@ function generateJS(ast, options) { ].join("\n"); }, - globals: function() { + globals() { return [ generateGeneratedByComment(), "(function(root) {", @@ -1305,7 +1305,7 @@ function generateJS(ast, options) { ].join("\n"); }, - umd: function() { + umd() { let parts = []; let dependencyVars = Object.keys(options.dependencies); let dependencyIds = dependencyIds.map(v => options.dependencies[v]); diff --git a/lib/compiler/passes/remove-proxy-rules.js b/lib/compiler/passes/remove-proxy-rules.js index c208fe3..a95cc3c 100644 --- a/lib/compiler/passes/remove-proxy-rules.js +++ b/lib/compiler/passes/remove-proxy-rules.js @@ -10,7 +10,7 @@ function removeProxyRules(ast, options) { function replaceRuleRefs(ast, from, to) { let replace = visitor.build({ - rule_ref: function(node) { + rule_ref(node) { if (node.name === from) { node.name = to; } diff --git a/lib/compiler/passes/report-duplicate-labels.js b/lib/compiler/passes/report-duplicate-labels.js index c3f4da4..1c83e56 100644 --- a/lib/compiler/passes/report-duplicate-labels.js +++ b/lib/compiler/passes/report-duplicate-labels.js @@ -20,11 +20,11 @@ function reportDuplicateLabels(ast) { } let check = visitor.build({ - rule: function(node) { + rule(node) { check(node.expression, { }); }, - choice: function(node, env) { + choice(node, env) { node.alternatives.forEach(alternative => { check(alternative, cloneEnv(env)); }); @@ -32,7 +32,7 @@ function reportDuplicateLabels(ast) { action: checkExpressionWithClonedEnv, - labeled: function(node, env) { + labeled(node, env) { if (env.hasOwnProperty(node.label)) { throw new GrammarError( "Label \"" + node.label + "\" is already defined " diff --git a/lib/compiler/passes/report-duplicate-rules.js b/lib/compiler/passes/report-duplicate-rules.js index 73ca831..72c3e9b 100644 --- a/lib/compiler/passes/report-duplicate-rules.js +++ b/lib/compiler/passes/report-duplicate-rules.js @@ -8,7 +8,7 @@ function reportDuplicateRules(ast) { let rules = {}; let check = visitor.build({ - rule: function(node) { + rule(node) { if (rules.hasOwnProperty(node.name)) { throw new GrammarError( "Rule \"" + node.name + "\" is already defined " diff --git a/lib/compiler/passes/report-infinite-recursion.js b/lib/compiler/passes/report-infinite-recursion.js index 229f0d8..d5ba312 100644 --- a/lib/compiler/passes/report-infinite-recursion.js +++ b/lib/compiler/passes/report-infinite-recursion.js @@ -18,13 +18,13 @@ function reportInfiniteRecursion(ast) { let visitedRules = []; let check = visitor.build({ - rule: function(node) { + rule(node) { visitedRules.push(node.name); check(node.expression); visitedRules.pop(node.name); }, - sequence: function(node) { + sequence(node) { node.elements.every(element => { check(element); @@ -32,7 +32,7 @@ function reportInfiniteRecursion(ast) { }); }, - rule_ref: function(node) { + rule_ref(node) { if (visitedRules.indexOf(node.name) !== -1) { visitedRules.push(node.name); diff --git a/lib/compiler/passes/report-infinite-repetition.js b/lib/compiler/passes/report-infinite-repetition.js index 088a596..f521931 100644 --- a/lib/compiler/passes/report-infinite-repetition.js +++ b/lib/compiler/passes/report-infinite-repetition.js @@ -8,7 +8,7 @@ let visitor = require("../visitor"); // grammar, which prevents infinite loops in the generated parser. function reportInfiniteRepetition(ast) { let check = visitor.build({ - zero_or_more: function(node) { + zero_or_more(node) { if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) { throw new GrammarError( "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).", @@ -17,7 +17,7 @@ function reportInfiniteRepetition(ast) { } }, - one_or_more: function(node) { + one_or_more(node) { if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) { throw new GrammarError( "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).", diff --git a/lib/compiler/passes/report-undefined-rules.js b/lib/compiler/passes/report-undefined-rules.js index 9fd8276..0f5d941 100644 --- a/lib/compiler/passes/report-undefined-rules.js +++ b/lib/compiler/passes/report-undefined-rules.js @@ -7,7 +7,7 @@ let visitor = require("../visitor"); // Checks that all referenced rules exist. function reportUndefinedRules(ast) { let check = visitor.build({ - rule_ref: function(node) { + rule_ref(node) { if (!asts.findRule(ast, node.name)) { throw new GrammarError( "Rule \"" + node.name + "\" is not defined.", diff --git a/lib/compiler/visitor.js b/lib/compiler/visitor.js index 9bcf186..54446e6 100644 --- a/lib/compiler/visitor.js +++ b/lib/compiler/visitor.js @@ -2,7 +2,7 @@ // Simple AST node visitor builder. let visitor = { - build: function(functions) { + build(functions) { function visit(node) { return functions[node.type].apply(null, arguments); } @@ -26,7 +26,7 @@ let visitor = { } const DEFAULT_FUNCTIONS = { - grammar: function(node) { + grammar(node) { let extraArgs = Array.prototype.slice.call(arguments, 1); if (node.initializer) { diff --git a/lib/peg.js b/lib/peg.js index 39ac51a..9dfb7b0 100644 --- a/lib/peg.js +++ b/lib/peg.js @@ -17,7 +17,7 @@ let peg = { // |peg.GrammarError| if it contains a semantic error. Note that not all // errors are detected during the generation and some may protrude to the // generated parser and cause its malfunction. - generate: function(grammar, options) { + generate(grammar, options) { options = options !== undefined ? options : {}; function convertPasses(passes) { diff --git a/spec/api/plugin-api.spec.js b/spec/api/plugin-api.spec.js index 56db185..8646e38 100644 --- a/spec/api/plugin-api.spec.js +++ b/spec/api/plugin-api.spec.js @@ -5,7 +5,7 @@ let peg = require("../../lib/peg"); describe("plugin API", function() { beforeEach(function() { this.addMatchers({ - toBeObject: function() { + toBeObject() { this.message = () => "Expected " + jasmine.pp(this.actual) + " " + (this.isNot ? "not " : "") @@ -14,7 +14,7 @@ describe("plugin API", function() { return this.actual !== null && typeof this.actual === "object"; }, - toBeArray: function() { + toBeArray() { this.message = () => "Expected " + jasmine.pp(this.actual) + " " + (this.isNot ? "not " : "") @@ -23,7 +23,7 @@ describe("plugin API", function() { return Object.prototype.toString.apply(this.actual) === "[object Array]"; }, - toBeFunction: function() { + toBeFunction() { this.message = () => "Expected " + jasmine.pp(this.actual) + " " + (this.isNot ? "not " : "") @@ -40,9 +40,9 @@ describe("plugin API", function() { it("is called for each plugin", function() { let pluginsUsed = [false, false, false]; let plugins = [ - { use: function() { pluginsUsed[0] = true; } }, - { use: function() { pluginsUsed[1] = true; } }, - { use: function() { pluginsUsed[2] = true; } } + { use() { pluginsUsed[0] = true; } }, + { use() { pluginsUsed[1] = true; } }, + { use() { pluginsUsed[2] = true; } } ]; peg.generate(grammar, { plugins: plugins }); @@ -52,7 +52,7 @@ describe("plugin API", function() { it("receives configuration", function() { let plugin = { - use: function(config) { + use(config) { expect(config).toBeObject(); expect(config.parser).toBeObject(); @@ -82,7 +82,7 @@ describe("plugin API", function() { it("receives options", function() { let plugin = { - use: function(config, options) { + use(config, options) { expect(options).toEqual(generateOptions); } }; @@ -93,7 +93,7 @@ describe("plugin API", function() { it("can replace parser", function() { let plugin = { - use: function(config) { + use(config) { let parser = peg.generate([ "start = .* {", " return {", @@ -119,7 +119,7 @@ describe("plugin API", function() { it("can change compiler passes", function() { let plugin = { - use: function(config) { + use(config) { let pass = ast => { ast.code = "({ parse: function() { return 42; } })"; }; @@ -139,7 +139,7 @@ describe("plugin API", function() { "c = 'x'" ].join("\n"); let plugin = { - use: function(config, options) { + use(config, options) { options.allowedStartRules = ["b", "c"]; } }; diff --git a/spec/behavior/generated-parser-behavior.spec.js b/spec/behavior/generated-parser-behavior.spec.js index 23656bd..c3bbcd8 100644 --- a/spec/behavior/generated-parser-behavior.spec.js +++ b/spec/behavior/generated-parser-behavior.spec.js @@ -38,7 +38,7 @@ describe("generated parser behavior", function() { beforeEach(function() { this.addMatchers({ - toParse: function(input, expected, options) { + toParse(input, expected, options) { options = options !== undefined ? options : {}; let result; @@ -70,7 +70,7 @@ describe("generated parser behavior", function() { } }, - toFailToParse: function(input, details, options) { + toFailToParse(input, details, options) { options = options !== undefined ? options : {}; let result; diff --git a/spec/unit/compiler/passes/helpers.js b/spec/unit/compiler/passes/helpers.js index b622127..8d07551 100644 --- a/spec/unit/compiler/passes/helpers.js +++ b/spec/unit/compiler/passes/helpers.js @@ -4,7 +4,7 @@ let peg = require("../../../../lib/peg"); beforeEach(function() { this.addMatchers({ - toChangeAST: function(grammar, details, options) { + toChangeAST(grammar, details, options) { options = options !== undefined ? options : {}; function matchDetails(value, details) { @@ -58,7 +58,7 @@ beforeEach(function() { return matchDetails(ast, details); }, - toReportError: function(grammar, details) { + toReportError(grammar, details) { let ast = peg.parser.parse(grammar); try { diff --git a/spec/unit/parser.spec.js b/spec/unit/parser.spec.js index 10a2859..04bcc9c 100644 --- a/spec/unit/parser.spec.js +++ b/spec/unit/parser.spec.js @@ -129,7 +129,7 @@ describe("PEG.js grammar parser", function() { } let strip = buildVisitor({ - grammar: function(node) { + grammar(node) { delete node.location; if (node.initializer) { @@ -165,7 +165,7 @@ describe("PEG.js grammar parser", function() { beforeEach(function() { this.addMatchers({ - toParseAs: function(expected) { + toParseAs(expected) { let result; try { @@ -191,7 +191,7 @@ describe("PEG.js grammar parser", function() { return this.env.equals_(result, expected); }, - toFailToParse: function(details) { + toFailToParse(details) { let result; try {