src/emitter.js: Fix variable redefinitions

Fixes the following JSHint errors:

  ./src/emitter.js: line 95, col 21, 'name' is already defined.
  ./src/emitter.js: line 361, col 35, 'setReportFailuresCode' is already defined.
  ./src/emitter.js: line 362, col 39, 'restoreReportFailuresCode' is already defined.
  ./src/emitter.js: line 363, col 31, 'reportFailureCode' is already defined.
  ./src/emitter.js: line 393, col 38, 'setReportFailuresCode' used out of scope.Fixes the following JSHint errors:
  ./src/emitter.js: line 394, col 38, 'restoreReportFailuresCode' used out of scope.
  ./src/emitter.js: line 395, col 38, 'reportFailureCode' used out of scope.
  ./src/emitter.js: line 666, col 26, 'formalParams' is already defined.
  ./src/emitter.js: line 667, col 26, 'actualParams' is already defined.
  ./src/emitter.js: line 669, col 26, 'formalParams' is already defined.
  ./src/emitter.js: line 670, col 26, 'actualParams' is already defined.
  ./src/emitter.js: line 685, col 27, 'formalParams' used out of scope.
  ./src/emitter.js: line 686, col 27, 'actualParams' used out of scope.
  ./src/emitter.js: line 770, col 20, 'regexp' is already defined.
  ./src/emitter.js: line 784, col 22, 'regexp' used out of scope.
redux
David Majda 13 years ago
parent a52522c7c6
commit bc4821581c

@ -84,15 +84,16 @@ PEG.compiler.emitter = function(ast) {
var initializerCode = node.initializer !== null
? emit(node.initializer)
: "";
var name;
var parseFunctionTableItems = [];
for (var name in node.rules) {
for (name in node.rules) {
parseFunctionTableItems.push(quote(name) + ": parse_" + name);
}
parseFunctionTableItems.sort();
var parseFunctionDefinitions = [];
for (var name in node.rules) {
for (name in node.rules) {
parseFunctionDefinitions.push(emit(node.rules[name]));
}
@ -341,14 +342,18 @@ PEG.compiler.emitter = function(ast) {
var resultVarsCode = resultVars.length > 0 ? "var " + resultVars.join(", ") + ";" : "";
var posVarsCode = posVars.length > 0 ? "var " + posVars.join(", ") + ";" : "";
var setReportFailuresCode;
var restoreReportFailuresCode;
var reportFailureCode;
if (node.displayName !== null) {
var setReportFailuresCode = formatCode(
setReportFailuresCode = formatCode(
"reportFailures++;"
);
var restoreReportFailuresCode = formatCode(
restoreReportFailuresCode = formatCode(
"reportFailures--;"
);
var reportFailureCode = formatCode(
reportFailureCode = formatCode(
"if (reportFailures === 0 && ${resultVar} === null) {",
" matchFailed(${displayName|string});",
"}",
@ -358,9 +363,9 @@ PEG.compiler.emitter = function(ast) {
}
);
} else {
var setReportFailuresCode = "";
var restoreReportFailuresCode = "";
var reportFailureCode = "";
setReportFailuresCode = "";
restoreReportFailuresCode = "";
reportFailureCode = "";
}
return formatCode(
@ -650,9 +655,12 @@ PEG.compiler.emitter = function(ast) {
posIndex: context.posIndex + 1
};
var formalParams;
var actualParams;
if (node.expression.type === "sequence") {
var formalParams = [];
var actualParams = [];
formalParams = [];
actualParams = [];
var elements = node.expression.elements;
var elementsLength = elements.length;
@ -663,11 +671,11 @@ PEG.compiler.emitter = function(ast) {
}
}
} else if (node.expression.type === "labeled") {
var formalParams = [node.expression.label];
var actualParams = [resultVar(context.resultIndex)];
formalParams = [node.expression.label];
actualParams = [resultVar(context.resultIndex)];
} else {
var formalParams = [];
var actualParams = [];
formalParams = [];
actualParams = [];
}
return formatCode(
@ -751,8 +759,10 @@ PEG.compiler.emitter = function(ast) {
},
"class": function(node, context) {
var regexp;
if (node.parts.length > 0) {
var regexp = "/^["
regexp = "/^["
+ (node.inverted ? "^" : "")
+ map(node.parts, function(part) {
return part instanceof Array
@ -767,7 +777,7 @@ PEG.compiler.emitter = function(ast) {
* Stupid IE considers regexps /[]/ and /[^]/ syntactically invalid, so
* we translate them into euqivalents it can handle.
*/
var regexp = node.inverted ? "/^[\\S\\s]/" : "/^(?!)/";
regexp = node.inverted ? "/^[\\S\\s]/" : "/^(?!)/";
}
return formatCode(

Loading…
Cancel
Save