Use one var/let/const per variable (for initialized variables)

Use one var/let/const per variable, but only for initialized variables.
Uninitialized variables are still grouped into one var/let/const
declaration as I don't see any value in separating them. This approach
reflects the fact that initialized and uninitialized var/let/const
declarations are really two different things.

See #443.
redux
David Majda 8 years ago
parent 381b5f4db7
commit 516023546d

@ -1,7 +1,7 @@
/* eslint-env browser, jquery */
let benchmarks = require("./benchmarks.js"),
Runner = require("./runner.js");
let benchmarks = require("./benchmarks.js");
let Runner = require("./runner.js");
$("#run").click(() => {
"use strict";
@ -17,8 +17,8 @@ $("#run").click(() => {
}
function appendResult(klass, title, url, inputSize, parseTime) {
const KB = 1024,
MS_IN_S = 1000;
const KB = 1024;
const MS_IN_S = 1000;
resultsTable.append(
"<tr class='" + klass + "'>"
@ -62,8 +62,8 @@ $("#run").click(() => {
* 2. To minimize random errors.
*/
let runCount = parseInt($("#run-count").val(), 10),
options = {
let runCount = parseInt($("#run-count").val(), 10);
let options = {
cache: $("#cache").is(":checked"),
optimize: $("#optimize").val()
};

@ -11,11 +11,11 @@
* served to the browser.
*/
let express = require("express"),
logger = require("morgan"),
glob = require("glob"),
browserify = require("browserify"),
babelify = require("babelify");
let express = require("express");
let logger = require("morgan");
let glob = require("glob");
let browserify = require("browserify");
let babelify = require("babelify");
let app = express();

@ -267,8 +267,7 @@ if (options.exportVar !== null) {
}
}
let inputStream;
let outputStream;
let inputStream, outputStream;
switch (args.length) {
case 0:

@ -1,9 +1,9 @@
"use strict";
let asts = require("../asts"),
visitor = require("../visitor"),
op = require("../opcodes"),
js = require("../js");
let asts = require("../asts");
let visitor = require("../visitor");
let op = require("../opcodes");
let js = require("../js");
/* Generates bytecode.
*
@ -347,15 +347,15 @@ function generateBytecode(ast) {
},
action: function(node, context) {
let env = cloneEnv(context.env),
emitCall = node.expression.type !== "sequence"
|| node.expression.elements.length === 0,
expressionCode = generate(node.expression, {
let env = cloneEnv(context.env);
let emitCall = node.expression.type !== "sequence"
|| node.expression.elements.length === 0;
let expressionCode = generate(node.expression, {
sp: context.sp + (emitCall ? 1 : 0),
env: env,
action: node
}),
functionIndex = addFunctionConst(Object.keys(env), node.code);
});
let functionIndex = addFunctionConst(Object.keys(env), node.code);
return emitCall
? buildSequence(
@ -582,16 +582,16 @@ function generateBytecode(ast) {
+ js.regexpClassEscape(part[1])
: js.regexpClassEscape(part)
).join('')
+ ']/' + (node.ignoreCase ? 'i' : ''),
parts = '['
+ ']/' + (node.ignoreCase ? 'i' : '');
let parts = '['
+ node.parts.map(part =>
Array.isArray(part)
? '["' + js.stringEscape(part[0]) + '", "' + js.stringEscape(part[1]) + '"]'
: '"' + js.stringEscape(part) + '"'
).join(', ')
+ ']',
regexpIndex = addConst(regexp),
expectedIndex = addConst(
+ ']';
let regexpIndex = addConst(regexp);
let expectedIndex = addConst(
'peg$classExpectation('
+ parts + ', '
+ node.inverted + ', '

@ -1,24 +1,23 @@
"use strict";
let asts = require("../asts"),
op = require("../opcodes"),
js = require("../js");
let asts = require("../asts");
let op = require("../opcodes");
let js = require("../js");
/* Generates parser JavaScript code. */
function generateJS(ast, options) {
/* These only indent non-empty lines to avoid trailing whitespace. */
function indent2(code) { return code.replace(/^(.+)$/gm, ' $1'); }
function indent6(code) { return code.replace(/^(.+)$/gm, ' $1'); }
function indent10(code) { return code.replace(/^(.+)$/gm, ' $1'); }
function generateTables() {
if (options.optimize === "size") {
return [
'peg$consts = [',
'var peg$consts = [',
indent2(ast.consts.join(',\n')),
'],',
'];',
'',
'peg$bytecode = [',
'var peg$bytecode = [',
indent2(ast.rules.map(rule =>
'peg$decode("'
+ js.stringEscape(rule.bytecode.map(
@ -26,10 +25,10 @@ function generateJS(ast, options) {
).join(''))
+ '")'
).join(',\n')),
'],'
'];'
].join('\n');
} else {
return ast.consts.map((c, i) => 'peg$c' + i + ' = ' + c + ',').join('\n');
return ast.consts.map((c, i) => 'var peg$c' + i + ' = ' + c + ';').join('\n');
}
}
@ -51,8 +50,8 @@ function generateJS(ast, options) {
if (options.cache) {
parts.push([
'var key = peg$currPos * ' + ast.rules.length + ' + ' + ruleIndexCode + ',',
' cached = peg$resultsCache[key];',
'var key = peg$currPos * ' + ast.rules.length + ' + ' + ruleIndexCode + ';',
'var cached = peg$resultsCache[key];',
'',
'if (cached) {',
' peg$currPos = cached.nextPos;',
@ -131,9 +130,9 @@ function generateJS(ast, options) {
let parts = [];
function generateCondition(cond, argsLength) {
let baseLength = argsLength + 3,
thenLengthCode = 'bc[ip + ' + (baseLength - 2) + ']',
elseLengthCode = 'bc[ip + ' + (baseLength - 1) + ']';
let baseLength = argsLength + 3;
let thenLengthCode = 'bc[ip + ' + (baseLength - 2) + ']';
let elseLengthCode = 'bc[ip + ' + (baseLength - 1) + ']';
return [
'ends.push(end);',
@ -152,8 +151,8 @@ function generateJS(ast, options) {
}
function generateLoop(cond) {
let baseLength = 2,
bodyLengthCode = 'bc[ip + ' + (baseLength - 1) + ']';
let baseLength = 2;
let bodyLengthCode = 'bc[ip + ' + (baseLength - 1) + ']';
return [
'if (' + cond + ') {',
@ -171,8 +170,8 @@ function generateJS(ast, options) {
}
function generateCall() {
let baseLength = 4,
paramsLengthCode = 'bc[ip + ' + (baseLength - 1) + ']';
let baseLength = 4;
let paramsLengthCode = 'bc[ip + ' + (baseLength - 1) + ']';
return [
'params = bc.slice(ip + ' + baseLength + ', ip + ' + baseLength + ' + ' + paramsLengthCode + ')',
@ -199,24 +198,24 @@ function generateJS(ast, options) {
if (options.trace) {
parts.push([
' var bc = peg$bytecode[index],',
' ip = 0,',
' ips = [],',
' end = bc.length,',
' ends = [],',
' stack = [],',
' startPos = peg$currPos,',
' params;'
' var bc = peg$bytecode[index];',
' var ip = 0;',
' var ips = [];',
' var end = bc.length;',
' var ends = [];',
' var stack = [];',
' var startPos = peg$currPos;',
' var params;'
].join('\n'));
} else {
parts.push([
' var bc = peg$bytecode[index],',
' ip = 0,',
' ips = [],',
' end = bc.length,',
' ends = [],',
' stack = [],',
' params;'
' var bc = peg$bytecode[index];',
' var ip = 0;',
' var ips = [];',
' var end = bc.length;',
' var ends = [];',
' var stack = [];',
' var params;'
].join('\n'));
}
@ -406,9 +405,9 @@ function generateJS(ast, options) {
}
function generateRuleFunction(rule) {
let parts = [],
stackVars = [],
code;
let parts = [];
let stackVars = [];
let code;
function c(i) { return "peg$c" + i; } // |consts[i]| of the abstract machine
function s(i) { return "s" + i; } // |stack[i]| of the abstract machine
@ -451,17 +450,17 @@ function generateJS(ast, options) {
};
function compile(bc) {
let ip = 0,
end = bc.length,
parts = [],
value;
let ip = 0;
let end = bc.length;
let parts = [];
let value;
function compileCondition(cond, argCount) {
let baseLength = argCount + 3,
thenLength = bc[ip + baseLength - 2],
elseLength = bc[ip + baseLength - 1],
baseSp = stack.sp,
thenCode, elseCode, thenSp, elseSp;
let baseLength = argCount + 3;
let thenLength = bc[ip + baseLength - 2];
let elseLength = bc[ip + baseLength - 1];
let baseSp = stack.sp;
let thenCode, elseCode, thenSp, elseSp;
ip += baseLength;
thenCode = compile(bc.slice(ip, ip + thenLength));
@ -491,10 +490,10 @@ function generateJS(ast, options) {
}
function compileLoop(cond) {
let baseLength = 2,
bodyLength = bc[ip + baseLength - 1],
baseSp = stack.sp,
bodyCode, bodySp;
let baseLength = 2;
let bodyLength = bc[ip + baseLength - 1];
let baseSp = stack.sp;
let bodyCode, bodySp;
ip += baseLength;
bodyCode = compile(bc.slice(ip, ip + bodyLength));
@ -511,8 +510,8 @@ function generateJS(ast, options) {
}
function compileCall() {
let baseLength = 4,
paramsLength = bc[ip + baseLength - 1];
let baseLength = 4;
let paramsLength = bc[ip + baseLength - 1];
let value = c(bc[ip + 1]) + '('
+ bc.slice(ip + baseLength, ip + baseLength + paramsLength).map(
@ -837,8 +836,8 @@ function generateJS(ast, options) {
' }',
'',
' function describeExpected(expected) {',
' var descriptions = expected.map(describeExpectation),',
' i, j;',
' var descriptions = expected.map(describeExpectation);',
' var i, j;',
'',
' descriptions.sort();',
'',
@ -937,7 +936,7 @@ function generateJS(ast, options) {
'function peg$parse(input, options) {',
' options = options !== undefined ? options : {};',
'',
' var peg$FAILED = {},',
' var peg$FAILED = {};',
''
].join('\n'));
@ -950,8 +949,8 @@ function generateJS(ast, options) {
let startRuleIndex = asts.indexOfRule(ast, options.allowedStartRules[0]);
parts.push([
' peg$startRuleIndices = ' + startRuleIndices + ',',
' peg$startRuleIndex = ' + startRuleIndex + ','
' var peg$startRuleIndices = ' + startRuleIndices + ';',
' var peg$startRuleIndex = ' + startRuleIndex + ';'
].join('\n'));
} else {
let startRuleFunctions = '{ '
@ -962,29 +961,29 @@ function generateJS(ast, options) {
let startRuleFunction = 'peg$parse' + options.allowedStartRules[0];
parts.push([
' peg$startRuleFunctions = ' + startRuleFunctions + ',',
' peg$startRuleFunction = ' + startRuleFunction + ','
' var peg$startRuleFunctions = ' + startRuleFunctions + ';',
' var peg$startRuleFunction = ' + startRuleFunction + ';'
].join('\n'));
}
parts.push('');
parts.push(indent6(generateTables()));
parts.push(indent2(generateTables()));
parts.push([
'',
' peg$currPos = 0,',
' peg$savedPos = 0,',
' peg$posDetailsCache = [{ line: 1, column: 1 }],',
' peg$maxFailPos = 0,',
' peg$maxFailExpected = [],',
' peg$silentFails = 0,', // 0 = report failures, > 0 = silence failures
' var peg$currPos = 0;',
' var peg$savedPos = 0;',
' var peg$posDetailsCache = [{ line: 1, column: 1 }];',
' var peg$maxFailPos = 0;',
' var peg$maxFailExpected = [];',
' var peg$silentFails = 0;', // 0 = report failures, > 0 = silence failures
''
].join('\n'));
if (options.cache) {
parts.push([
' peg$resultsCache = {},',
' var peg$resultsCache = {};',
''
].join('\n'));
}
@ -998,19 +997,19 @@ function generateJS(ast, options) {
+ ']';
parts.push([
' peg$ruleNames = ' + ruleNames + ',',
' var peg$ruleNames = ' + ruleNames + ';',
''
].join('\n'));
}
parts.push([
' peg$tracer = "tracer" in options ? options.tracer : new peg$DefaultTracer(),',
' var peg$tracer = "tracer" in options ? options.tracer : new peg$DefaultTracer();',
''
].join('\n'));
}
parts.push([
' peg$result;',
' var peg$result;',
''
].join('\n'));
@ -1083,7 +1082,8 @@ function generateJS(ast, options) {
' }',
'',
' function peg$computePosDetails(pos) {',
' var details = peg$posDetailsCache[pos], p;',
' var details = peg$posDetailsCache[pos];',
' var p;',
'',
' if (details) {',
' return details;',
@ -1116,8 +1116,8 @@ function generateJS(ast, options) {
' }',
'',
' function peg$computeLocation(startPos, endPos) {',
' var startPosDetails = peg$computePosDetails(startPos),',
' endPosDetails = peg$computePosDetails(endPos);',
' var startPosDetails = peg$computePosDetails(startPos);',
' var endPosDetails = peg$computePosDetails(endPos);',
'',
' return {',
' start: {',
@ -1246,9 +1246,9 @@ function generateJS(ast, options) {
},
commonjs: function() {
let parts = [],
dependencyVars = Object.keys(options.dependencies),
requires = dependencyVars.map(
let parts = [];
let dependencyVars = Object.keys(options.dependencies);
let requires = dependencyVars.map(
variable => variable
+ ' = require("'
+ js.stringEscape(options.dependencies[variable])
@ -1278,14 +1278,14 @@ function generateJS(ast, options) {
},
amd: function() {
let dependencyVars = Object.keys(options.dependencies),
dependencyIds = dependencyIds.map(v => options.dependencies[v]),
dependencies = '['
let dependencyVars = Object.keys(options.dependencies);
let dependencyIds = dependencyIds.map(v => options.dependencies[v]);
let dependencies = '['
+ dependencyIds.map(
id => '"' + js.stringEscape(id) + '"'
).join(', ')
+ ']',
params = dependencyVars.join(', ');
+ ']';
let params = dependencyVars.join(', ');
return [
generateGeneratedByComment(),
@ -1315,18 +1315,18 @@ function generateJS(ast, options) {
},
umd: function() {
let parts = [],
dependencyVars = Object.keys(options.dependencies),
dependencyIds = dependencyIds.map(v => options.dependencies[v]),
dependencies = '['
let parts = [];
let dependencyVars = Object.keys(options.dependencies);
let dependencyIds = dependencyIds.map(v => options.dependencies[v]);
let dependencies = '['
+ dependencyIds.map(
id => '"' + js.stringEscape(id) + '"'
).join(', ')
+ ']',
requires = dependencyIds.map(
+ ']';
let requires = dependencyIds.map(
id => 'require("' + js.stringEscape(id) + '")'
).join(', '),
params = dependencyVars.join(', ');
).join(', ');
let params = dependencyVars.join(', ');
parts.push([
generateGeneratedByComment(),

@ -1,7 +1,7 @@
"use strict";
let GrammarError = require("../../grammar-error"),
visitor = require("../visitor");
let GrammarError = require("../../grammar-error");
let visitor = require("../visitor");
/* Checks that each label is defined only once within each scope. */
function reportDuplicateLabels(ast) {

@ -1,7 +1,7 @@
"use strict";
let GrammarError = require("../../grammar-error"),
visitor = require("../visitor");
let GrammarError = require("../../grammar-error");
let visitor = require("../visitor");
/* Checks that each rule is defined only once. */
function reportDuplicateRules(ast) {

@ -1,8 +1,8 @@
"use strict";
let GrammarError = require("../../grammar-error"),
asts = require("../asts"),
visitor = require("../visitor");
let GrammarError = require("../../grammar-error");
let asts = require("../asts");
let visitor = require("../visitor");
/*
* Reports left recursion in the grammar, which prevents infinite recursion in

@ -1,8 +1,8 @@
"use strict";
let GrammarError = require("../../grammar-error"),
asts = require("../asts"),
visitor = require("../visitor");
let GrammarError = require("../../grammar-error");
let asts = require("../asts");
let visitor = require("../visitor");
/*
* Reports expressions that don't consume any input inside |*| or |+| in the

@ -1,8 +1,8 @@
"use strict";
let GrammarError = require("../../grammar-error"),
asts = require("../asts"),
visitor = require("../visitor");
let GrammarError = require("../../grammar-error");
let asts = require("../asts");
let visitor = require("../visitor");
/* Checks that all referenced rules exist. */
function reportUndefinedRules(ast) {

File diff suppressed because one or more lines are too long

@ -33,8 +33,8 @@ let peg = {
return converted;
}
let plugins = "plugins" in options ? options.plugins : [],
config = {
let plugins = "plugins" in options ? options.plugins : [];
let config = {
parser: peg.parser,
passes: convertPasses(peg.compiler.passes)
};

@ -119,8 +119,8 @@ describe("PEG.js API", function() {
describe("when |trace| is not set", function() {
it("generated parser doesn't trace", function() {
let parser = peg.generate(grammar),
tracer = jasmine.createSpyObj("tracer", ["trace"]);
let parser = peg.generate(grammar);
let tracer = jasmine.createSpyObj("tracer", ["trace"]);
parser.parse("a", { tracer: tracer });
@ -130,8 +130,8 @@ describe("PEG.js API", function() {
describe("when |trace| is set to |false|", function() {
it("generated parser doesn't trace", function() {
let parser = peg.generate(grammar, { trace: false }),
tracer = jasmine.createSpyObj("tracer", ["trace"]);
let parser = peg.generate(grammar, { trace: false });
let tracer = jasmine.createSpyObj("tracer", ["trace"]);
parser.parse("a", { tracer: tracer });
@ -141,8 +141,8 @@ describe("PEG.js API", function() {
describe("when |trace| is set to |true|", function() {
it("generated parser traces", function() {
let parser = peg.generate(grammar, { trace: true }),
tracer = jasmine.createSpyObj("tracer", ["trace"]);
let parser = peg.generate(grammar, { trace: true });
let tracer = jasmine.createSpyObj("tracer", ["trace"]);
parser.parse("a", { tracer: tracer });

@ -38,8 +38,8 @@ describe("plugin API", function() {
let grammar = 'start = "a"';
it("is called for each plugin", function() {
let pluginsUsed = [false, false, false],
plugins = [
let pluginsUsed = [false, false, false];
let plugins = [
{ use: function() { pluginsUsed[0] = true; } },
{ use: function() { pluginsUsed[1] = true; } },
{ use: function() { pluginsUsed[2] = true; } }
@ -85,8 +85,8 @@ describe("plugin API", function() {
use: function(config, options) {
expect(options).toEqual(generateOptions);
}
},
generateOptions = { plugins: [plugin], foo: 42 };
};
let generateOptions = { plugins: [plugin], foo: 42 };
peg.generate(grammar, generateOptions);
});
@ -111,8 +111,8 @@ describe("plugin API", function() {
config.parser = parser;
}
},
parser = peg.generate('a', { plugins: [plugin] });
};
let parser = peg.generate('a', { plugins: [plugin] });
expect(parser.parse("a")).toBe("a");
});
@ -126,8 +126,8 @@ describe("plugin API", function() {
config.passes.generate = [pass];
}
},
parser = peg.generate(grammar, { plugins: [plugin] });
};
let parser = peg.generate(grammar, { plugins: [plugin] });
expect(parser.parse("a")).toBe(42);
});
@ -137,13 +137,13 @@ describe("plugin API", function() {
'a = "x"',
'b = "x"',
'c = "x"'
].join("\n"),
plugin = {
].join("\n");
let plugin = {
use: function(config, options) {
options.allowedStartRules = ["b", "c"];
}
},
parser = peg.generate(grammar, {
};
let parser = peg.generate(grammar, {
allowedStartRules: ["a"],
plugins: [plugin]
});

@ -506,8 +506,8 @@ describe("generated parser behavior", function() {
grammar: 'start = ("a" / b:"b" / "c") &{ return b === "b"; }',
input: "b"
}
],
parser;
];
let parser;
testcases.forEach(testcase => {
parser = peg.generate(testcase.grammar, options);
@ -702,8 +702,8 @@ describe("generated parser behavior", function() {
grammar: 'start = ("a" / b:"b" / "c") !{ return b !== "b"; }',
input: "b"
}
],
parser;
];
let parser;
testcases.forEach(testcase => {
parser = peg.generate(testcase.grammar, options);
@ -1071,8 +1071,8 @@ describe("generated parser behavior", function() {
grammar: 'start = ("a" / b:"b" / "c") { return b; }',
input: "b"
}
],
parser;
];
let parser;
testcases.forEach(testcase => {
parser = peg.generate(testcase.grammar, options);

@ -11,11 +11,11 @@
* browser.
*/
let express = require("express"),
logger = require("morgan"),
glob = require("glob"),
browserify = require("browserify"),
babelify = require("babelify");
let express = require("express");
let logger = require("morgan");
let glob = require("glob");
let browserify = require("browserify");
let babelify = require("babelify");
let app = express();

@ -3,61 +3,61 @@
let peg = require("../../lib/peg");
describe("PEG.js grammar parser", function() {
let literalAbcd = { type: "literal", value: "abcd", ignoreCase: false },
literalEfgh = { type: "literal", value: "efgh", ignoreCase: false },
literalIjkl = { type: "literal", value: "ijkl", ignoreCase: false },
literalMnop = { type: "literal", value: "mnop", ignoreCase: false },
semanticAnd = { type: "semantic_and", code: " code " },
semanticNot = { type: "semantic_not", code: " code " },
optional = { type: "optional", expression: literalAbcd },
zeroOrMore = { type: "zero_or_more", expression: literalAbcd },
oneOrMore = { type: "one_or_more", expression: literalAbcd },
textOptional = { type: "text", expression: optional },
simpleNotAbcd = { type: "simple_not", expression: literalAbcd },
simpleAndOptional = { type: "simple_and", expression: optional },
simpleNotOptional = { type: "simple_not", expression: optional },
labeledAbcd = { type: "labeled", label: "a", expression: literalAbcd },
labeledEfgh = { type: "labeled", label: "b", expression: literalEfgh },
labeledIjkl = { type: "labeled", label: "c", expression: literalIjkl },
labeledMnop = { type: "labeled", label: "d", expression: literalMnop },
labeledSimpleNot = { type: "labeled", label: "a", expression: simpleNotAbcd },
sequence = {
let literalAbcd = { type: "literal", value: "abcd", ignoreCase: false };
let literalEfgh = { type: "literal", value: "efgh", ignoreCase: false };
let literalIjkl = { type: "literal", value: "ijkl", ignoreCase: false };
let literalMnop = { type: "literal", value: "mnop", ignoreCase: false };
let semanticAnd = { type: "semantic_and", code: " code " };
let semanticNot = { type: "semantic_not", code: " code " };
let optional = { type: "optional", expression: literalAbcd };
let zeroOrMore = { type: "zero_or_more", expression: literalAbcd };
let oneOrMore = { type: "one_or_more", expression: literalAbcd };
let textOptional = { type: "text", expression: optional };
let simpleNotAbcd = { type: "simple_not", expression: literalAbcd };
let simpleAndOptional = { type: "simple_and", expression: optional };
let simpleNotOptional = { type: "simple_not", expression: optional };
let labeledAbcd = { type: "labeled", label: "a", expression: literalAbcd };
let labeledEfgh = { type: "labeled", label: "b", expression: literalEfgh };
let labeledIjkl = { type: "labeled", label: "c", expression: literalIjkl };
let labeledMnop = { type: "labeled", label: "d", expression: literalMnop };
let labeledSimpleNot = { type: "labeled", label: "a", expression: simpleNotAbcd };
let sequence = {
type: "sequence",
elements: [literalAbcd, literalEfgh, literalIjkl]
},
sequence2 = {
};
let sequence2 = {
type: "sequence",
elements: [labeledAbcd, labeledEfgh]
},
sequence4 = {
};
let sequence4 = {
type: "sequence",
elements: [labeledAbcd, labeledEfgh, labeledIjkl, labeledMnop]
},
groupLabeled = { type: "group", expression: labeledAbcd },
groupSequence = { type: "group", expression: sequence },
actionAbcd = { type: "action", expression: literalAbcd, code: " code " },
actionEfgh = { type: "action", expression: literalEfgh, code: " code " },
actionIjkl = { type: "action", expression: literalIjkl, code: " code " },
actionMnop = { type: "action", expression: literalMnop, code: " code " },
actionSequence = { type: "action", expression: sequence, code: " code " },
choice = {
};
let groupLabeled = { type: "group", expression: labeledAbcd };
let groupSequence = { type: "group", expression: sequence };
let actionAbcd = { type: "action", expression: literalAbcd, code: " code " };
let actionEfgh = { type: "action", expression: literalEfgh, code: " code " };
let actionIjkl = { type: "action", expression: literalIjkl, code: " code " };
let actionMnop = { type: "action", expression: literalMnop, code: " code " };
let actionSequence = { type: "action", expression: sequence, code: " code " };
let choice = {
type: "choice",
alternatives: [literalAbcd, literalEfgh, literalIjkl]
},
choice2 = {
};
let choice2 = {
type: "choice",
alternatives: [actionAbcd, actionEfgh]
},
choice4 = {
};
let choice4 = {
type: "choice",
alternatives: [actionAbcd, actionEfgh, actionIjkl, actionMnop]
},
named = { type: "named", name: "start rule", expression: literalAbcd },
ruleA = { type: "rule", name: "a", expression: literalAbcd },
ruleB = { type: "rule", name: "b", expression: literalEfgh },
ruleC = { type: "rule", name: "c", expression: literalIjkl },
ruleStart = { type: "rule", name: "start", expression: literalAbcd },
initializer = { type: "initializer", code: " code " };
};
let named = { type: "named", name: "start rule", expression: literalAbcd };
let ruleA = { type: "rule", name: "a", expression: literalAbcd };
let ruleB = { type: "rule", name: "b", expression: literalEfgh };
let ruleC = { type: "rule", name: "c", expression: literalIjkl };
let ruleStart = { type: "rule", name: "start", expression: literalAbcd };
let initializer = { type: "initializer", code: " code " };
function oneRuleGrammar(expression) {
return {
@ -96,8 +96,8 @@ describe("PEG.js grammar parser", function() {
return oneRuleGrammar({ type: "rule_ref", name: name });
}
let trivialGrammar = literalGrammar("abcd", false),
twoRuleGrammar = {
let trivialGrammar = literalGrammar("abcd", false);
let twoRuleGrammar = {
type: "grammar",
initializer: null,
rules: [ruleA, ruleB]

Loading…
Cancel
Save