Use single quotes for code in the emitter

Strings with code should use single quotes so that double quotes (which
I generally prefer) could be used in the code itself without escaping.
redux
David Majda 13 years ago
parent 45c99f8f6b
commit 38c25efde0

@ -98,229 +98,229 @@ PEG.compiler.emitter = function(ast) {
} }
return formatCode( return formatCode(
"(function(){", '(function(){',
" /* Generated by PEG.js @VERSION (http://pegjs.majda.cz/). */", ' /* Generated by PEG.js @VERSION (http://pegjs.majda.cz/). */',
" ", ' ',
" var result = {", ' var result = {',
" /*", ' /*',
" * Parses the input with a generated parser. If the parsing is successfull,", ' * Parses the input with a generated parser. If the parsing is successfull,',
" * returns a value explicitly or implicitly specified by the grammar from", ' * returns a value explicitly or implicitly specified by the grammar from',
" * which the parser was generated (see |PEG.buildParser|). If the parsing is", ' * which the parser was generated (see |PEG.buildParser|). If the parsing is',
" * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.", ' * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.',
" */", ' */',
" parse: function(input, startRule) {", ' parse: function(input, startRule) {',
" var parseFunctions = {", ' var parseFunctions = {',
" ${parseFunctionTableItems}", ' ${parseFunctionTableItems}',
" };", ' };',
" ", ' ',
" if (startRule !== undefined) {", ' if (startRule !== undefined) {',
" if (parseFunctions[startRule] === undefined) {", ' if (parseFunctions[startRule] === undefined) {',
" throw new Error(\"Invalid rule name: \" + quote(startRule) + \".\");", ' throw new Error("Invalid rule name: " + quote(startRule) + ".");',
" }", ' }',
" } else {", ' } else {',
" startRule = ${startRule|string};", ' startRule = ${startRule|string};',
" }", ' }',
" ", ' ',
" var pos = 0;", ' var pos = 0;',
" var reportFailures = 0;", // 0 = report, anything > 0 = do not report ' var reportFailures = 0;', // 0 = report, anything > 0 = do not report
" var rightmostFailuresPos = 0;", ' var rightmostFailuresPos = 0;',
" var rightmostFailuresExpected = [];", ' var rightmostFailuresExpected = [];',
" var cache = {};", ' var cache = {};',
" ", ' ',
/* This needs to be in sync with |padLeft| in utils.js. */ /* This needs to be in sync with |padLeft| in utils.js. */
" function padLeft(input, padding, length) {", ' function padLeft(input, padding, length) {',
" var result = input;", ' var result = input;',
" ", ' ',
" var padLength = length - input.length;", ' var padLength = length - input.length;',
" for (var i = 0; i < padLength; i++) {", ' for (var i = 0; i < padLength; i++) {',
" result = padding + result;", ' result = padding + result;',
" }", ' }',
" ", ' ',
" return result;", ' return result;',
" }", ' }',
" ", ' ',
/* This needs to be in sync with |escape| in utils.js. */ /* This needs to be in sync with |escape| in utils.js. */
" function escape(ch) {", ' function escape(ch) {',
" var charCode = ch.charCodeAt(0);", ' var charCode = ch.charCodeAt(0);',
" var escapeChar;", ' var escapeChar;',
" var length;", ' var length;',
" ", ' ',
" if (charCode <= 0xFF) {", ' if (charCode <= 0xFF) {',
" escapeChar = 'x';", ' escapeChar = \'x\';',
" length = 2;", ' length = 2;',
" } else {", ' } else {',
" escapeChar = 'u';", ' escapeChar = \'u\';',
" length = 4;", ' length = 4;',
" }", ' }',
" ", ' ',
" return '\\\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);", ' return \'\\\\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), \'0\', length);',
" }", ' }',
" ", ' ',
/* This needs to be in sync with |quote| in utils.js. */ /* This needs to be in sync with |quote| in utils.js. */
" function quote(s) {", ' function quote(s) {',
" /*", ' /*',
" * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a", ' * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a',
" * string literal except for the closing quote character, backslash,", ' * string literal except for the closing quote character, backslash,',
" * carriage return, line separator, paragraph separator, and line feed.", ' * carriage return, line separator, paragraph separator, and line feed.',
" * Any character may appear in the form of an escape sequence.", ' * Any character may appear in the form of an escape sequence.',
" *", ' *',
" * For portability, we also escape escape all control and non-ASCII", ' * For portability, we also escape escape all control and non-ASCII',
" * characters. Note that \"\\0\" and \"\\v\" escape sequences are not used", ' * characters. Note that "\\0" and "\\v" escape sequences are not used',
" * because JSHint does not like the first and IE the second.", ' * because JSHint does not like the first and IE the second.',
" */", ' */',
" return '\"' + s", ' return \'"\' + s',
" .replace(/\\\\/g, '\\\\\\\\') // backslash", ' .replace(/\\\\/g, \'\\\\\\\\\') // backslash',
" .replace(/\"/g, '\\\\\"') // closing quote character", ' .replace(/"/g, \'\\\\"\') // closing quote character',
" .replace(/\\x08/g, '\\\\b') // backspace", ' .replace(/\\x08/g, \'\\\\b\') // backspace',
" .replace(/\\t/g, '\\\\t') // horizontal tab", ' .replace(/\\t/g, \'\\\\t\') // horizontal tab',
" .replace(/\\n/g, '\\\\n') // line feed", ' .replace(/\\n/g, \'\\\\n\') // line feed',
" .replace(/\\f/g, '\\\\f') // form feed", ' .replace(/\\f/g, \'\\\\f\') // form feed',
" .replace(/\\r/g, '\\\\r') // carriage return", ' .replace(/\\r/g, \'\\\\r\') // carriage return',
" .replace(/[\\x00-\\x07\\x0B\\x0E-\\x1F\\x80-\\uFFFF]/g, escape)", ' .replace(/[\\x00-\\x07\\x0B\\x0E-\\x1F\\x80-\\uFFFF]/g, escape)',
" + '\"';", ' + \'"\';',
" }", ' }',
" ", ' ',
" function matchFailed(failure) {", ' function matchFailed(failure) {',
" if (pos < rightmostFailuresPos) {", ' if (pos < rightmostFailuresPos) {',
" return;", ' return;',
" }", ' }',
" ", ' ',
" if (pos > rightmostFailuresPos) {", ' if (pos > rightmostFailuresPos) {',
" rightmostFailuresPos = pos;", ' rightmostFailuresPos = pos;',
" rightmostFailuresExpected = [];", ' rightmostFailuresExpected = [];',
" }", ' }',
" ", ' ',
" rightmostFailuresExpected.push(failure);", ' rightmostFailuresExpected.push(failure);',
" }", ' }',
" ", ' ',
" ${parseFunctionDefinitions}", ' ${parseFunctionDefinitions}',
" ", ' ',
" function buildErrorMessage() {", ' function buildErrorMessage() {',
" function buildExpected(failuresExpected) {", ' function buildExpected(failuresExpected) {',
" failuresExpected.sort();", ' failuresExpected.sort();',
" ", ' ',
" var lastFailure = null;", ' var lastFailure = null;',
" var failuresExpectedUnique = [];", ' var failuresExpectedUnique = [];',
" for (var i = 0; i < failuresExpected.length; i++) {", ' for (var i = 0; i < failuresExpected.length; i++) {',
" if (failuresExpected[i] !== lastFailure) {", ' if (failuresExpected[i] !== lastFailure) {',
" failuresExpectedUnique.push(failuresExpected[i]);", ' failuresExpectedUnique.push(failuresExpected[i]);',
" lastFailure = failuresExpected[i];", ' lastFailure = failuresExpected[i];',
" }", ' }',
" }", ' }',
" ", ' ',
" switch (failuresExpectedUnique.length) {", ' switch (failuresExpectedUnique.length) {',
" case 0:", ' case 0:',
" return 'end of input';", ' return "end of input";',
" case 1:", ' case 1:',
" return failuresExpectedUnique[0];", ' return failuresExpectedUnique[0];',
" default:", ' default:',
" return failuresExpectedUnique.slice(0, failuresExpectedUnique.length - 1).join(', ')", ' return failuresExpectedUnique.slice(0, failuresExpectedUnique.length - 1).join(", ")',
" + ' or '", ' + " or "',
" + failuresExpectedUnique[failuresExpectedUnique.length - 1];", ' + failuresExpectedUnique[failuresExpectedUnique.length - 1];',
" }", ' }',
" }", ' }',
" ", ' ',
" var expected = buildExpected(rightmostFailuresExpected);", ' var expected = buildExpected(rightmostFailuresExpected);',
" var actualPos = Math.max(pos, rightmostFailuresPos);", ' var actualPos = Math.max(pos, rightmostFailuresPos);',
" var actual = actualPos < input.length", ' var actual = actualPos < input.length',
" ? quote(input.charAt(actualPos))", ' ? quote(input.charAt(actualPos))',
" : 'end of input';", ' : "end of input";',
" ", ' ',
" return 'Expected ' + expected + ' but ' + actual + ' found.';", ' return "Expected " + expected + " but " + actual + " found.";',
" }", ' }',
" ", ' ',
" function computeErrorPosition() {", ' function computeErrorPosition() {',
" /*", ' /*',
" * The first idea was to use |String.split| to break the input up to the", ' * The first idea was to use |String.split| to break the input up to the',
" * error position along newlines and derive the line and column from", ' * error position along newlines and derive the line and column from',
" * there. However IE's |split| implementation is so broken that it was", ' * there. However IE\'s |split| implementation is so broken that it was',
" * enough to prevent it.", ' * enough to prevent it.',
" */", ' */',
" ", ' ',
" var line = 1;", ' var line = 1;',
" var column = 1;", ' var column = 1;',
" var seenCR = false;", ' var seenCR = false;',
" ", ' ',
" for (var i = 0; i < rightmostFailuresPos; i++) {", ' for (var i = 0; i < rightmostFailuresPos; i++) {',
" var ch = input.charAt(i);", ' var ch = input.charAt(i);',
" if (ch === '\\n') {", ' if (ch === "\\n") {',
" if (!seenCR) { line++; }", ' if (!seenCR) { line++; }',
" column = 1;", ' column = 1;',
" seenCR = false;", ' seenCR = false;',
" } else if (ch === '\\r' || ch === '\\u2028' || ch === '\\u2029') {", ' } else if (ch === "\\r" || ch === "\\u2028" || ch === "\\u2029") {',
" line++;", ' line++;',
" column = 1;", ' column = 1;',
" seenCR = true;", ' seenCR = true;',
" } else {", ' } else {',
" column++;", ' column++;',
" seenCR = false;", ' seenCR = false;',
" }", ' }',
" }", ' }',
" ", ' ',
" return { line: line, column: column };", ' return { line: line, column: column };',
" }", ' }',
" ", ' ',
" ${initializerCode}", ' ${initializerCode}',
" ", ' ',
" var result = parseFunctions[startRule]();", ' var result = parseFunctions[startRule]();',
" ", ' ',
" /*", ' /*',
" * The parser is now in one of the following three states:", ' * The parser is now in one of the following three states:',
" *", ' *',
" * 1. The parser successfully parsed the whole input.", ' * 1. The parser successfully parsed the whole input.',
" *", ' *',
" * - |result !== null|", ' * - |result !== null|',
" * - |pos === input.length|", ' * - |pos === input.length|',
" * - |rightmostFailuresExpected| may or may not contain something", ' * - |rightmostFailuresExpected| may or may not contain something',
" *", ' *',
" * 2. The parser successfully parsed only a part of the input.", ' * 2. The parser successfully parsed only a part of the input.',
" *", ' *',
" * - |result !== null|", ' * - |result !== null|',
" * - |pos < input.length|", ' * - |pos < input.length|',
" * - |rightmostFailuresExpected| may or may not contain something", ' * - |rightmostFailuresExpected| may or may not contain something',
" *", ' *',
" * 3. The parser did not successfully parse any part of the input.", ' * 3. The parser did not successfully parse any part of the input.',
" *", ' *',
" * - |result === null|", ' * - |result === null|',
" * - |pos === 0|", ' * - |pos === 0|',
" * - |rightmostFailuresExpected| contains at least one failure", ' * - |rightmostFailuresExpected| contains at least one failure',
" *", ' *',
" * All code following this comment (including called functions) must", ' * All code following this comment (including called functions) must',
" * handle these states.", ' * handle these states.',
" */", ' */',
" if (result === null || pos !== input.length) {", ' if (result === null || pos !== input.length) {',
" var errorPosition = computeErrorPosition();", ' var errorPosition = computeErrorPosition();',
" throw new this.SyntaxError(", ' throw new this.SyntaxError(',
" buildErrorMessage(),", ' buildErrorMessage(),',
" errorPosition.line,", ' errorPosition.line,',
" errorPosition.column", ' errorPosition.column',
" );", ' );',
" }", ' }',
" ", ' ',
" return result;", ' return result;',
" },", ' },',
" ", ' ',
" /* Returns the parser source code. */", ' /* Returns the parser source code. */',
" toSource: function() { return this._source; }", ' toSource: function() { return this._source; }',
" };", ' };',
" ", ' ',
" /* Thrown when a parser encounters a syntax error. */", ' /* Thrown when a parser encounters a syntax error. */',
" ", ' ',
" result.SyntaxError = function(message, line, column) {", ' result.SyntaxError = function(message, line, column) {',
" this.name = 'SyntaxError';", ' this.name = "SyntaxError";',
" this.message = message;", ' this.message = message;',
" this.line = line;", ' this.line = line;',
" this.column = column;", ' this.column = column;',
" };", ' };',
" ", ' ',
" result.SyntaxError.prototype = Error.prototype;", ' result.SyntaxError.prototype = Error.prototype;',
" ", ' ',
" return result;", ' return result;',
"})()", '})()',
{ {
initializerCode: initializerCode, initializerCode: initializerCode,
parseFunctionTableItems: parseFunctionTableItems.join(",\n"), parseFunctionTableItems: parseFunctionTableItems.join(',\n'),
parseFunctionDefinitions: parseFunctionDefinitions.join("\n\n"), parseFunctionDefinitions: parseFunctionDefinitions.join('\n\n'),
startRule: node.startRule startRule: node.startRule
} }
); );
@ -339,8 +339,8 @@ PEG.compiler.emitter = function(ast) {
var resultVars = map(range(node.resultStackDepth), resultVar); var resultVars = map(range(node.resultStackDepth), resultVar);
var posVars = map(range(node.posStackDepth), posVar); var posVars = map(range(node.posStackDepth), posVar);
var resultVarsCode = resultVars.length > 0 ? "var " + resultVars.join(", ") + ";" : ""; var resultVarsCode = resultVars.length > 0 ? 'var ' + resultVars.join(', ') + ';' : '';
var posVarsCode = posVars.length > 0 ? "var " + posVars.join(", ") + ";" : ""; var posVarsCode = posVars.length > 0 ? 'var ' + posVars.join(', ') + ';' : '';
var setReportFailuresCode; var setReportFailuresCode;
var restoreReportFailuresCode; var restoreReportFailuresCode;
@ -348,15 +348,15 @@ PEG.compiler.emitter = function(ast) {
if (node.displayName !== null) { if (node.displayName !== null) {
setReportFailuresCode = formatCode( setReportFailuresCode = formatCode(
"reportFailures++;" 'reportFailures++;'
); );
restoreReportFailuresCode = formatCode( restoreReportFailuresCode = formatCode(
"reportFailures--;" 'reportFailures--;'
); );
reportFailureCode = formatCode( reportFailureCode = formatCode(
"if (reportFailures === 0 && ${resultVar} === null) {", 'if (reportFailures === 0 && ${resultVar} === null) {',
" matchFailed(${displayName|string});", ' matchFailed(${displayName|string});',
"}", '}',
{ {
displayName: node.displayName, displayName: node.displayName,
resultVar: resultVar(context.resultIndex) resultVar: resultVar(context.resultIndex)
@ -369,28 +369,28 @@ PEG.compiler.emitter = function(ast) {
} }
return formatCode( return formatCode(
"function parse_${name}() {", 'function parse_${name}() {',
" var cacheKey = '${name}@' + pos;", ' var cacheKey = "${name}@" + pos;',
" var cachedResult = cache[cacheKey];", ' var cachedResult = cache[cacheKey];',
" if (cachedResult) {", ' if (cachedResult) {',
" pos = cachedResult.nextPos;", ' pos = cachedResult.nextPos;',
" return cachedResult.result;", ' return cachedResult.result;',
" }", ' }',
" ", ' ',
" ${resultVarsCode}", ' ${resultVarsCode}',
" ${posVarsCode}", ' ${posVarsCode}',
" ", ' ',
" ${setReportFailuresCode}", ' ${setReportFailuresCode}',
" ${code}", ' ${code}',
" ${restoreReportFailuresCode}", ' ${restoreReportFailuresCode}',
" ${reportFailureCode}", ' ${reportFailureCode}',
" ", ' ',
" cache[cacheKey] = {", ' cache[cacheKey] = {',
" nextPos: pos,", ' nextPos: pos,',
" result: ${resultVar}", ' result: ${resultVar}',
" };", ' };',
" return ${resultVar};", ' return ${resultVar};',
"}", '}',
{ {
name: node.name, name: node.name,
resultVarsCode: resultVarsCode, resultVarsCode: resultVarsCode,
@ -440,18 +440,18 @@ PEG.compiler.emitter = function(ast) {
for (var i = node.alternatives.length - 1; i >= 0; i--) { for (var i = node.alternatives.length - 1; i >= 0; i--) {
nextAlternativesCode = i !== node.alternatives.length - 1 nextAlternativesCode = i !== node.alternatives.length - 1
? formatCode( ? formatCode(
"if (${resultVar} === null) {", 'if (${resultVar} === null) {',
" ${code}", ' ${code}',
"}", '}',
{ {
code: code, code: code,
resultVar: resultVar(context.resultIndex) resultVar: resultVar(context.resultIndex)
} }
) )
: ""; : '';
code = formatCode( code = formatCode(
"${currentAlternativeCode}", '${currentAlternativeCode}',
"${nextAlternativesCode}", '${nextAlternativesCode}',
{ {
currentAlternativeCode: emit(node.alternatives[i], context), currentAlternativeCode: emit(node.alternatives[i], context),
nextAlternativesCode: nextAlternativesCode nextAlternativesCode: nextAlternativesCode
@ -468,10 +468,10 @@ PEG.compiler.emitter = function(ast) {
}); });
var code = formatCode( var code = formatCode(
"${resultVar} = ${elementResultVarArray};", '${resultVar} = ${elementResultVarArray};',
{ {
resultVar: resultVar(context.resultIndex), resultVar: resultVar(context.resultIndex),
elementResultVarArray: "[" + elementResultVars.join(", ") + "]" elementResultVarArray: '[' + elementResultVars.join(', ') + ']'
} }
); );
var elementContext; var elementContext;
@ -482,13 +482,13 @@ PEG.compiler.emitter = function(ast) {
posIndex: context.posIndex + 1 posIndex: context.posIndex + 1
}; };
code = formatCode( code = formatCode(
"${elementCode}", '${elementCode}',
"if (${elementResultVar} !== null) {", 'if (${elementResultVar} !== null) {',
" ${code}", ' ${code}',
"} else {", '} else {',
" ${resultVar} = null;", ' ${resultVar} = null;',
" pos = ${posVar};", ' pos = ${posVar};',
"}", '}',
{ {
elementCode: emit(node.elements[i], elementContext), elementCode: emit(node.elements[i], elementContext),
elementResultVar: elementResultVars[i], elementResultVar: elementResultVars[i],
@ -500,8 +500,8 @@ PEG.compiler.emitter = function(ast) {
} }
return formatCode( return formatCode(
"${posVar} = pos;", '${posVar} = pos;',
"${code}", '${code}',
{ {
code: code, code: code,
posVar: posVar(context.posIndex) posVar: posVar(context.posIndex)
@ -520,16 +520,16 @@ PEG.compiler.emitter = function(ast) {
}; };
return formatCode( return formatCode(
"${posVar} = pos;", '${posVar} = pos;',
"reportFailures++;", 'reportFailures++;',
"${expressionCode}", '${expressionCode}',
"reportFailures--;", 'reportFailures--;',
"if (${resultVar} !== null) {", 'if (${resultVar} !== null) {',
" ${resultVar} = '';", ' ${resultVar} = "";',
" pos = ${posVar};", ' pos = ${posVar};',
"} else {", '} else {',
" ${resultVar} = null;", ' ${resultVar} = null;',
"}", '}',
{ {
expressionCode: emit(node.expression, expressionContext), expressionCode: emit(node.expression, expressionContext),
posVar: posVar(context.posIndex), posVar: posVar(context.posIndex),
@ -545,16 +545,16 @@ PEG.compiler.emitter = function(ast) {
}; };
return formatCode( return formatCode(
"${posVar} = pos;", '${posVar} = pos;',
"reportFailures++;", 'reportFailures++;',
"${expressionCode}", '${expressionCode}',
"reportFailures--;", 'reportFailures--;',
"if (${resultVar} === null) {", 'if (${resultVar} === null) {',
" ${resultVar} = '';", ' ${resultVar} = "";',
"} else {", '} else {',
" ${resultVar} = null;", ' ${resultVar} = null;',
" pos = ${posVar};", ' pos = ${posVar};',
"}", '}',
{ {
expressionCode: emit(node.expression, expressionContext), expressionCode: emit(node.expression, expressionContext),
posVar: posVar(context.posIndex), posVar: posVar(context.posIndex),
@ -565,7 +565,7 @@ PEG.compiler.emitter = function(ast) {
semantic_and: function(node, context) { semantic_and: function(node, context) {
return formatCode( return formatCode(
"${resultVar} = (function() {${actionCode}})() ? '' : null;", '${resultVar} = (function() {${actionCode}})() ? "" : null;',
{ {
actionCode: node.code, actionCode: node.code,
resultVar: resultVar(context.resultIndex) resultVar: resultVar(context.resultIndex)
@ -575,7 +575,7 @@ PEG.compiler.emitter = function(ast) {
semantic_not: function(node, context) { semantic_not: function(node, context) {
return formatCode( return formatCode(
"${resultVar} = (function() {${actionCode}})() ? null : '';", '${resultVar} = (function() {${actionCode}})() ? null : "";',
{ {
actionCode: node.code, actionCode: node.code,
resultVar: resultVar(context.resultIndex) resultVar: resultVar(context.resultIndex)
@ -585,8 +585,8 @@ PEG.compiler.emitter = function(ast) {
optional: function(node, context) { optional: function(node, context) {
return formatCode( return formatCode(
"${expressionCode}", '${expressionCode}',
"${resultVar} = ${resultVar} !== null ? ${resultVar} : '';", '${resultVar} = ${resultVar} !== null ? ${resultVar} : "";',
{ {
expressionCode: emit(node.expression, context), expressionCode: emit(node.expression, context),
resultVar: resultVar(context.resultIndex) resultVar: resultVar(context.resultIndex)
@ -601,12 +601,12 @@ PEG.compiler.emitter = function(ast) {
}; };
return formatCode( return formatCode(
"${resultVar} = [];", '${resultVar} = [];',
"${expressionCode}", '${expressionCode}',
"while (${expressionResultVar} !== null) {", 'while (${expressionResultVar} !== null) {',
" ${resultVar}.push(${expressionResultVar});", ' ${resultVar}.push(${expressionResultVar});',
" ${expressionCode}", ' ${expressionCode}',
"}", '}',
{ {
expressionCode: emit(node.expression, expressionContext), expressionCode: emit(node.expression, expressionContext),
expressionResultVar: resultVar(context.resultIndex + 1), expressionResultVar: resultVar(context.resultIndex + 1),
@ -622,16 +622,16 @@ PEG.compiler.emitter = function(ast) {
}; };
return formatCode( return formatCode(
"${expressionCode}", '${expressionCode}',
"if (${expressionResultVar} !== null) {", 'if (${expressionResultVar} !== null) {',
" ${resultVar} = [];", ' ${resultVar} = [];',
" while (${expressionResultVar} !== null) {", ' while (${expressionResultVar} !== null) {',
" ${resultVar}.push(${expressionResultVar});", ' ${resultVar}.push(${expressionResultVar});',
" ${expressionCode}", ' ${expressionCode}',
" }", ' }',
"} else {", '} else {',
" ${resultVar} = null;", ' ${resultVar} = null;',
"}", '}',
{ {
expressionCode: emit(node.expression, expressionContext), expressionCode: emit(node.expression, expressionContext),
expressionResultVar: resultVar(context.resultIndex + 1), expressionResultVar: resultVar(context.resultIndex + 1),
@ -667,7 +667,7 @@ PEG.compiler.emitter = function(ast) {
for (var i = 0; i < elementsLength; i++) { for (var i = 0; i < elementsLength; i++) {
if (elements[i].type === "labeled") { if (elements[i].type === "labeled") {
formalParams.push(elements[i].label); formalParams.push(elements[i].label);
actualParams.push(resultVar(context.resultIndex) + "[" + i + "]"); actualParams.push(resultVar(context.resultIndex) + '[' + i + ']');
} }
} }
} else if (node.expression.type === "labeled") { } else if (node.expression.type === "labeled") {
@ -679,19 +679,19 @@ PEG.compiler.emitter = function(ast) {
} }
return formatCode( return formatCode(
"${posVar} = pos;", '${posVar} = pos;',
"${expressionCode}", '${expressionCode}',
"if (${resultVar} !== null) {", 'if (${resultVar} !== null) {',
" ${resultVar} = (function(${formalParams}) {${actionCode}})(${actualParams});", ' ${resultVar} = (function(${formalParams}) {${actionCode}})(${actualParams});',
"}", '}',
"if (${resultVar} === null) {", 'if (${resultVar} === null) {',
" pos = ${posVar};", ' pos = ${posVar};',
"}", '}',
{ {
expressionCode: emit(node.expression, expressionContext), expressionCode: emit(node.expression, expressionContext),
actionCode: node.code, actionCode: node.code,
formalParams: formalParams.join(", "), formalParams: formalParams.join(', '),
actualParams: actualParams.join(", "), actualParams: actualParams.join(', '),
posVar: posVar(context.posIndex), posVar: posVar(context.posIndex),
resultVar: resultVar(context.resultIndex) resultVar: resultVar(context.resultIndex)
} }
@ -700,9 +700,9 @@ PEG.compiler.emitter = function(ast) {
rule_ref: function(node, context) { rule_ref: function(node, context) {
return formatCode( return formatCode(
"${resultVar} = ${ruleMethod}();", '${resultVar} = ${ruleMethod}();',
{ {
ruleMethod: "parse_" + node.name, ruleMethod: 'parse_' + node.name,
resultVar: resultVar(context.resultIndex) resultVar: resultVar(context.resultIndex)
} }
); );
@ -713,18 +713,18 @@ PEG.compiler.emitter = function(ast) {
if (length === 0) { if (length === 0) {
return formatCode( return formatCode(
"${resultVar} = '';", '${resultVar} = "";',
{ resultVar: resultVar(context.resultIndex) } { resultVar: resultVar(context.resultIndex) }
); );
} }
var testCode = length === 1 var testCode = length === 1
? formatCode( ? formatCode(
"input.charCodeAt(pos) === ${valueCharCode}", 'input.charCodeAt(pos) === ${valueCharCode}',
{ valueCharCode: node.value.charCodeAt(0) } { valueCharCode: node.value.charCodeAt(0) }
) )
: formatCode( : formatCode(
"input.substr(pos, ${length}) === ${value|string}", 'input.substr(pos, ${length}) === ${value|string}',
{ {
value: node.value, value: node.value,
length: length length: length
@ -732,15 +732,15 @@ PEG.compiler.emitter = function(ast) {
); );
return formatCode( return formatCode(
"if (${testCode}) {", 'if (${testCode}) {',
" ${resultVar} = ${value|string};", ' ${resultVar} = ${value|string};',
" pos += ${length};", ' pos += ${length};',
"} else {", '} else {',
" ${resultVar} = null;", ' ${resultVar} = null;',
" if (reportFailures === 0) {", ' if (reportFailures === 0) {',
" matchFailed(${valueQuoted|string});", ' matchFailed(${valueQuoted|string});',
" }", ' }',
"}", '}',
{ {
testCode: testCode, testCode: testCode,
value: node.value, value: node.value,
@ -753,15 +753,15 @@ PEG.compiler.emitter = function(ast) {
any: function(node, context) { any: function(node, context) {
return formatCode( return formatCode(
"if (input.length > pos) {", 'if (input.length > pos) {',
" ${resultVar} = input.charAt(pos);", ' ${resultVar} = input.charAt(pos);',
" pos++;", ' pos++;',
"} else {", '} else {',
" ${resultVar} = null;", ' ${resultVar} = null;',
" if (reportFailures === 0) {", ' if (reportFailures === 0) {',
" matchFailed('any character');", ' matchFailed("any character");',
" }", ' }',
"}", '}',
{ resultVar: resultVar(context.resultIndex) } { resultVar: resultVar(context.resultIndex) }
); );
}, },
@ -770,34 +770,34 @@ PEG.compiler.emitter = function(ast) {
var regexp; var regexp;
if (node.parts.length > 0) { if (node.parts.length > 0) {
regexp = "/^[" regexp = '/^['
+ (node.inverted ? "^" : "") + (node.inverted ? '^' : '')
+ map(node.parts, function(part) { + map(node.parts, function(part) {
return part instanceof Array return part instanceof Array
? quoteForRegexpClass(part[0]) ? quoteForRegexpClass(part[0])
+ "-" + '-'
+ quoteForRegexpClass(part[1]) + quoteForRegexpClass(part[1])
: quoteForRegexpClass(part); : quoteForRegexpClass(part);
}).join("") }).join('')
+ "]/"; + ']/';
} else { } else {
/* /*
* Stupid IE considers regexps /[]/ and /[^]/ syntactically invalid, so * Stupid IE considers regexps /[]/ and /[^]/ syntactically invalid, so
* we translate them into euqivalents it can handle. * we translate them into euqivalents it can handle.
*/ */
regexp = node.inverted ? "/^[\\S\\s]/" : "/^(?!)/"; regexp = node.inverted ? '/^[\\S\\s]/' : '/^(?!)/';
} }
return formatCode( return formatCode(
"if (${regexp}.test(input.charAt(pos))) {", 'if (${regexp}.test(input.charAt(pos))) {',
" ${resultVar} = input.charAt(pos);", ' ${resultVar} = input.charAt(pos);',
" pos++;", ' pos++;',
"} else {", '} else {',
" ${resultVar} = null;", ' ${resultVar} = null;',
" if (reportFailures === 0) {", ' if (reportFailures === 0) {',
" matchFailed(${rawText|string});", ' matchFailed(${rawText|string});',
" }", ' }',
"}", '}',
{ {
regexp: regexp, regexp: regexp,
rawText: node.rawText, rawText: node.rawText,

@ -145,7 +145,7 @@ PEG.parser = (function(){
} }
function parse_grammar() { function parse_grammar() {
var cacheKey = 'grammar@' + pos; var cacheKey = "grammar@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -161,7 +161,7 @@ PEG.parser = (function(){
result0 = parse___(); result0 = parse___();
if (result0 !== null) { if (result0 !== null) {
result1 = parse_initializer(); result1 = parse_initializer();
result1 = result1 !== null ? result1 : ''; result1 = result1 !== null ? result1 : "";
if (result1 !== null) { if (result1 !== null) {
result3 = parse_rule(); result3 = parse_rule();
if (result3 !== null) { if (result3 !== null) {
@ -214,7 +214,7 @@ PEG.parser = (function(){
} }
function parse_initializer() { function parse_initializer() {
var cacheKey = 'initializer@' + pos; var cacheKey = "initializer@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -230,7 +230,7 @@ PEG.parser = (function(){
result0 = parse_action(); result0 = parse_action();
if (result0 !== null) { if (result0 !== null) {
result1 = parse_semicolon(); result1 = parse_semicolon();
result1 = result1 !== null ? result1 : ''; result1 = result1 !== null ? result1 : "";
if (result1 !== null) { if (result1 !== null) {
result0 = [result0, result1]; result0 = [result0, result1];
} else { } else {
@ -263,7 +263,7 @@ PEG.parser = (function(){
} }
function parse_rule() { function parse_rule() {
var cacheKey = 'rule@' + pos; var cacheKey = "rule@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -280,7 +280,7 @@ PEG.parser = (function(){
if (result0 !== null) { if (result0 !== null) {
result1 = parse_literal(); result1 = parse_literal();
if (result1 === null) { if (result1 === null) {
result1 = ''; result1 = "";
} }
if (result1 !== null) { if (result1 !== null) {
@ -289,7 +289,7 @@ PEG.parser = (function(){
result3 = parse_choice(); result3 = parse_choice();
if (result3 !== null) { if (result3 !== null) {
result4 = parse_semicolon(); result4 = parse_semicolon();
result4 = result4 !== null ? result4 : ''; result4 = result4 !== null ? result4 : "";
if (result4 !== null) { if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4]; result0 = [result0, result1, result2, result3, result4];
} else { } else {
@ -336,7 +336,7 @@ PEG.parser = (function(){
} }
function parse_choice() { function parse_choice() {
var cacheKey = 'choice@' + pos; var cacheKey = "choice@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -423,7 +423,7 @@ PEG.parser = (function(){
} }
function parse_sequence() { function parse_sequence() {
var cacheKey = 'sequence@' + pos; var cacheKey = "sequence@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -506,7 +506,7 @@ PEG.parser = (function(){
} }
function parse_labeled() { function parse_labeled() {
var cacheKey = 'labeled@' + pos; var cacheKey = "labeled@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -565,7 +565,7 @@ PEG.parser = (function(){
} }
function parse_prefixed() { function parse_prefixed() {
var cacheKey = 'prefixed@' + pos; var cacheKey = "prefixed@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -701,7 +701,7 @@ PEG.parser = (function(){
} }
function parse_suffixed() { function parse_suffixed() {
var cacheKey = 'suffixed@' + pos; var cacheKey = "suffixed@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -809,7 +809,7 @@ PEG.parser = (function(){
} }
function parse_primary() { function parse_primary() {
var cacheKey = 'primary@' + pos; var cacheKey = "primary@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -829,7 +829,7 @@ PEG.parser = (function(){
pos3 = pos; pos3 = pos;
result1 = parse_literal(); result1 = parse_literal();
if (result1 === null) { if (result1 === null) {
result1 = ''; result1 = "";
} }
if (result1 !== null) { if (result1 !== null) {
@ -846,7 +846,7 @@ PEG.parser = (function(){
} }
reportFailures--; reportFailures--;
if (result1 === null) { if (result1 === null) {
result1 = ''; result1 = "";
} else { } else {
result1 = null; result1 = null;
pos = pos2; pos = pos2;
@ -941,7 +941,7 @@ PEG.parser = (function(){
} }
function parse_action() { function parse_action() {
var cacheKey = 'action@' + pos; var cacheKey = "action@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -986,7 +986,7 @@ PEG.parser = (function(){
} }
function parse_braced() { function parse_braced() {
var cacheKey = 'braced@' + pos; var cacheKey = "braced@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1066,7 +1066,7 @@ PEG.parser = (function(){
} }
function parse_nonBraceCharacters() { function parse_nonBraceCharacters() {
var cacheKey = 'nonBraceCharacters@' + pos; var cacheKey = "nonBraceCharacters@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1105,7 +1105,7 @@ PEG.parser = (function(){
} }
function parse_nonBraceCharacter() { function parse_nonBraceCharacter() {
var cacheKey = 'nonBraceCharacter@' + pos; var cacheKey = "nonBraceCharacter@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1136,7 +1136,7 @@ PEG.parser = (function(){
} }
function parse_equals() { function parse_equals() {
var cacheKey = 'equals@' + pos; var cacheKey = "equals@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1187,7 +1187,7 @@ PEG.parser = (function(){
} }
function parse_colon() { function parse_colon() {
var cacheKey = 'colon@' + pos; var cacheKey = "colon@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1238,7 +1238,7 @@ PEG.parser = (function(){
} }
function parse_semicolon() { function parse_semicolon() {
var cacheKey = 'semicolon@' + pos; var cacheKey = "semicolon@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1289,7 +1289,7 @@ PEG.parser = (function(){
} }
function parse_slash() { function parse_slash() {
var cacheKey = 'slash@' + pos; var cacheKey = "slash@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1340,7 +1340,7 @@ PEG.parser = (function(){
} }
function parse_and() { function parse_and() {
var cacheKey = 'and@' + pos; var cacheKey = "and@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1391,7 +1391,7 @@ PEG.parser = (function(){
} }
function parse_not() { function parse_not() {
var cacheKey = 'not@' + pos; var cacheKey = "not@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1442,7 +1442,7 @@ PEG.parser = (function(){
} }
function parse_question() { function parse_question() {
var cacheKey = 'question@' + pos; var cacheKey = "question@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1493,7 +1493,7 @@ PEG.parser = (function(){
} }
function parse_star() { function parse_star() {
var cacheKey = 'star@' + pos; var cacheKey = "star@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1544,7 +1544,7 @@ PEG.parser = (function(){
} }
function parse_plus() { function parse_plus() {
var cacheKey = 'plus@' + pos; var cacheKey = "plus@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1595,7 +1595,7 @@ PEG.parser = (function(){
} }
function parse_lparen() { function parse_lparen() {
var cacheKey = 'lparen@' + pos; var cacheKey = "lparen@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1646,7 +1646,7 @@ PEG.parser = (function(){
} }
function parse_rparen() { function parse_rparen() {
var cacheKey = 'rparen@' + pos; var cacheKey = "rparen@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1697,7 +1697,7 @@ PEG.parser = (function(){
} }
function parse_dot() { function parse_dot() {
var cacheKey = 'dot@' + pos; var cacheKey = "dot@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1748,7 +1748,7 @@ PEG.parser = (function(){
} }
function parse_identifier() { function parse_identifier() {
var cacheKey = 'identifier@' + pos; var cacheKey = "identifier@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1881,7 +1881,7 @@ PEG.parser = (function(){
} }
function parse_literal() { function parse_literal() {
var cacheKey = 'literal@' + pos; var cacheKey = "literal@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -1930,7 +1930,7 @@ PEG.parser = (function(){
} }
function parse_doubleQuotedLiteral() { function parse_doubleQuotedLiteral() {
var cacheKey = 'doubleQuotedLiteral@' + pos; var cacheKey = "doubleQuotedLiteral@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2000,7 +2000,7 @@ PEG.parser = (function(){
} }
function parse_doubleQuotedCharacter() { function parse_doubleQuotedCharacter() {
var cacheKey = 'doubleQuotedCharacter@' + pos; var cacheKey = "doubleQuotedCharacter@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2039,7 +2039,7 @@ PEG.parser = (function(){
} }
function parse_simpleDoubleQuotedCharacter() { function parse_simpleDoubleQuotedCharacter() {
var cacheKey = 'simpleDoubleQuotedCharacter@' + pos; var cacheKey = "simpleDoubleQuotedCharacter@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2080,7 +2080,7 @@ PEG.parser = (function(){
} }
reportFailures--; reportFailures--;
if (result0 === null) { if (result0 === null) {
result0 = ''; result0 = "";
} else { } else {
result0 = null; result0 = null;
pos = pos2; pos = pos2;
@ -2092,7 +2092,7 @@ PEG.parser = (function(){
} else { } else {
result1 = null; result1 = null;
if (reportFailures === 0) { if (reportFailures === 0) {
matchFailed('any character'); matchFailed("any character");
} }
} }
if (result1 !== null) { if (result1 !== null) {
@ -2122,7 +2122,7 @@ PEG.parser = (function(){
} }
function parse_singleQuotedLiteral() { function parse_singleQuotedLiteral() {
var cacheKey = 'singleQuotedLiteral@' + pos; var cacheKey = "singleQuotedLiteral@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2192,7 +2192,7 @@ PEG.parser = (function(){
} }
function parse_singleQuotedCharacter() { function parse_singleQuotedCharacter() {
var cacheKey = 'singleQuotedCharacter@' + pos; var cacheKey = "singleQuotedCharacter@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2231,7 +2231,7 @@ PEG.parser = (function(){
} }
function parse_simpleSingleQuotedCharacter() { function parse_simpleSingleQuotedCharacter() {
var cacheKey = 'simpleSingleQuotedCharacter@' + pos; var cacheKey = "simpleSingleQuotedCharacter@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2272,7 +2272,7 @@ PEG.parser = (function(){
} }
reportFailures--; reportFailures--;
if (result0 === null) { if (result0 === null) {
result0 = ''; result0 = "";
} else { } else {
result0 = null; result0 = null;
pos = pos2; pos = pos2;
@ -2284,7 +2284,7 @@ PEG.parser = (function(){
} else { } else {
result1 = null; result1 = null;
if (reportFailures === 0) { if (reportFailures === 0) {
matchFailed('any character'); matchFailed("any character");
} }
} }
if (result1 !== null) { if (result1 !== null) {
@ -2314,7 +2314,7 @@ PEG.parser = (function(){
} }
function parse_class() { function parse_class() {
var cacheKey = 'class@' + pos; var cacheKey = "class@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2346,7 +2346,7 @@ PEG.parser = (function(){
matchFailed("\"^\""); matchFailed("\"^\"");
} }
} }
result1 = result1 !== null ? result1 : ''; result1 = result1 !== null ? result1 : "";
if (result1 !== null) { if (result1 !== null) {
result2 = []; result2 = [];
result3 = parse_classCharacterRange(); result3 = parse_classCharacterRange();
@ -2429,7 +2429,7 @@ PEG.parser = (function(){
} }
function parse_classCharacterRange() { function parse_classCharacterRange() {
var cacheKey = 'classCharacterRange@' + pos; var cacheKey = "classCharacterRange@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2498,7 +2498,7 @@ PEG.parser = (function(){
} }
function parse_classCharacter() { function parse_classCharacter() {
var cacheKey = 'classCharacter@' + pos; var cacheKey = "classCharacter@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2534,7 +2534,7 @@ PEG.parser = (function(){
} }
function parse_bracketDelimitedCharacter() { function parse_bracketDelimitedCharacter() {
var cacheKey = 'bracketDelimitedCharacter@' + pos; var cacheKey = "bracketDelimitedCharacter@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2573,7 +2573,7 @@ PEG.parser = (function(){
} }
function parse_simpleBracketDelimitedCharacter() { function parse_simpleBracketDelimitedCharacter() {
var cacheKey = 'simpleBracketDelimitedCharacter@' + pos; var cacheKey = "simpleBracketDelimitedCharacter@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2614,7 +2614,7 @@ PEG.parser = (function(){
} }
reportFailures--; reportFailures--;
if (result0 === null) { if (result0 === null) {
result0 = ''; result0 = "";
} else { } else {
result0 = null; result0 = null;
pos = pos2; pos = pos2;
@ -2626,7 +2626,7 @@ PEG.parser = (function(){
} else { } else {
result1 = null; result1 = null;
if (reportFailures === 0) { if (reportFailures === 0) {
matchFailed('any character'); matchFailed("any character");
} }
} }
if (result1 !== null) { if (result1 !== null) {
@ -2656,7 +2656,7 @@ PEG.parser = (function(){
} }
function parse_simpleEscapeSequence() { function parse_simpleEscapeSequence() {
var cacheKey = 'simpleEscapeSequence@' + pos; var cacheKey = "simpleEscapeSequence@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2710,7 +2710,7 @@ PEG.parser = (function(){
} }
reportFailures--; reportFailures--;
if (result1 === null) { if (result1 === null) {
result1 = ''; result1 = "";
} else { } else {
result1 = null; result1 = null;
pos = pos2; pos = pos2;
@ -2722,7 +2722,7 @@ PEG.parser = (function(){
} else { } else {
result2 = null; result2 = null;
if (reportFailures === 0) { if (reportFailures === 0) {
matchFailed('any character'); matchFailed("any character");
} }
} }
if (result2 !== null) { if (result2 !== null) {
@ -2764,7 +2764,7 @@ PEG.parser = (function(){
} }
function parse_zeroEscapeSequence() { function parse_zeroEscapeSequence() {
var cacheKey = 'zeroEscapeSequence@' + pos; var cacheKey = "zeroEscapeSequence@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2792,7 +2792,7 @@ PEG.parser = (function(){
result1 = parse_digit(); result1 = parse_digit();
reportFailures--; reportFailures--;
if (result1 === null) { if (result1 === null) {
result1 = ''; result1 = "";
} else { } else {
result1 = null; result1 = null;
pos = pos2; pos = pos2;
@ -2824,7 +2824,7 @@ PEG.parser = (function(){
} }
function parse_hexEscapeSequence() { function parse_hexEscapeSequence() {
var cacheKey = 'hexEscapeSequence@' + pos; var cacheKey = "hexEscapeSequence@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2883,7 +2883,7 @@ PEG.parser = (function(){
} }
function parse_unicodeEscapeSequence() { function parse_unicodeEscapeSequence() {
var cacheKey = 'unicodeEscapeSequence@' + pos; var cacheKey = "unicodeEscapeSequence@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -2954,7 +2954,7 @@ PEG.parser = (function(){
} }
function parse_eolEscapeSequence() { function parse_eolEscapeSequence() {
var cacheKey = 'eolEscapeSequence@' + pos; var cacheKey = "eolEscapeSequence@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3005,7 +3005,7 @@ PEG.parser = (function(){
} }
function parse_digit() { function parse_digit() {
var cacheKey = 'digit@' + pos; var cacheKey = "digit@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3036,7 +3036,7 @@ PEG.parser = (function(){
} }
function parse_hexDigit() { function parse_hexDigit() {
var cacheKey = 'hexDigit@' + pos; var cacheKey = "hexDigit@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3067,7 +3067,7 @@ PEG.parser = (function(){
} }
function parse_letter() { function parse_letter() {
var cacheKey = 'letter@' + pos; var cacheKey = "letter@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3094,7 +3094,7 @@ PEG.parser = (function(){
} }
function parse_lowerCaseLetter() { function parse_lowerCaseLetter() {
var cacheKey = 'lowerCaseLetter@' + pos; var cacheKey = "lowerCaseLetter@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3125,7 +3125,7 @@ PEG.parser = (function(){
} }
function parse_upperCaseLetter() { function parse_upperCaseLetter() {
var cacheKey = 'upperCaseLetter@' + pos; var cacheKey = "upperCaseLetter@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3156,7 +3156,7 @@ PEG.parser = (function(){
} }
function parse___() { function parse___() {
var cacheKey = '__@' + pos; var cacheKey = "__@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3198,7 +3198,7 @@ PEG.parser = (function(){
} }
function parse_comment() { function parse_comment() {
var cacheKey = 'comment@' + pos; var cacheKey = "comment@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3227,7 +3227,7 @@ PEG.parser = (function(){
} }
function parse_singleLineComment() { function parse_singleLineComment() {
var cacheKey = 'singleLineComment@' + pos; var cacheKey = "singleLineComment@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3256,7 +3256,7 @@ PEG.parser = (function(){
result2 = parse_eolChar(); result2 = parse_eolChar();
reportFailures--; reportFailures--;
if (result2 === null) { if (result2 === null) {
result2 = ''; result2 = "";
} else { } else {
result2 = null; result2 = null;
pos = pos2; pos = pos2;
@ -3268,7 +3268,7 @@ PEG.parser = (function(){
} else { } else {
result3 = null; result3 = null;
if (reportFailures === 0) { if (reportFailures === 0) {
matchFailed('any character'); matchFailed("any character");
} }
} }
if (result3 !== null) { if (result3 !== null) {
@ -3289,7 +3289,7 @@ PEG.parser = (function(){
result2 = parse_eolChar(); result2 = parse_eolChar();
reportFailures--; reportFailures--;
if (result2 === null) { if (result2 === null) {
result2 = ''; result2 = "";
} else { } else {
result2 = null; result2 = null;
pos = pos2; pos = pos2;
@ -3301,7 +3301,7 @@ PEG.parser = (function(){
} else { } else {
result3 = null; result3 = null;
if (reportFailures === 0) { if (reportFailures === 0) {
matchFailed('any character'); matchFailed("any character");
} }
} }
if (result3 !== null) { if (result3 !== null) {
@ -3336,7 +3336,7 @@ PEG.parser = (function(){
} }
function parse_multiLineComment() { function parse_multiLineComment() {
var cacheKey = 'multiLineComment@' + pos; var cacheKey = "multiLineComment@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3373,7 +3373,7 @@ PEG.parser = (function(){
} }
reportFailures--; reportFailures--;
if (result2 === null) { if (result2 === null) {
result2 = ''; result2 = "";
} else { } else {
result2 = null; result2 = null;
pos = pos2; pos = pos2;
@ -3385,7 +3385,7 @@ PEG.parser = (function(){
} else { } else {
result3 = null; result3 = null;
if (reportFailures === 0) { if (reportFailures === 0) {
matchFailed('any character'); matchFailed("any character");
} }
} }
if (result3 !== null) { if (result3 !== null) {
@ -3414,7 +3414,7 @@ PEG.parser = (function(){
} }
reportFailures--; reportFailures--;
if (result2 === null) { if (result2 === null) {
result2 = ''; result2 = "";
} else { } else {
result2 = null; result2 = null;
pos = pos2; pos = pos2;
@ -3426,7 +3426,7 @@ PEG.parser = (function(){
} else { } else {
result3 = null; result3 = null;
if (reportFailures === 0) { if (reportFailures === 0) {
matchFailed('any character'); matchFailed("any character");
} }
} }
if (result3 !== null) { if (result3 !== null) {
@ -3475,7 +3475,7 @@ PEG.parser = (function(){
} }
function parse_eol() { function parse_eol() {
var cacheKey = 'eol@' + pos; var cacheKey = "eol@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3553,7 +3553,7 @@ PEG.parser = (function(){
} }
function parse_eolChar() { function parse_eolChar() {
var cacheKey = 'eolChar@' + pos; var cacheKey = "eolChar@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3584,7 +3584,7 @@ PEG.parser = (function(){
} }
function parse_whitespace() { function parse_whitespace() {
var cacheKey = 'whitespace@' + pos; var cacheKey = "whitespace@" + pos;
var cachedResult = cache[cacheKey]; var cachedResult = cache[cacheKey];
if (cachedResult) { if (cachedResult) {
pos = cachedResult.nextPos; pos = cachedResult.nextPos;
@ -3631,12 +3631,12 @@ PEG.parser = (function(){
switch (failuresExpectedUnique.length) { switch (failuresExpectedUnique.length) {
case 0: case 0:
return 'end of input'; return "end of input";
case 1: case 1:
return failuresExpectedUnique[0]; return failuresExpectedUnique[0];
default: default:
return failuresExpectedUnique.slice(0, failuresExpectedUnique.length - 1).join(', ') return failuresExpectedUnique.slice(0, failuresExpectedUnique.length - 1).join(", ")
+ ' or ' + " or "
+ failuresExpectedUnique[failuresExpectedUnique.length - 1]; + failuresExpectedUnique[failuresExpectedUnique.length - 1];
} }
} }
@ -3645,9 +3645,9 @@ PEG.parser = (function(){
var actualPos = Math.max(pos, rightmostFailuresPos); var actualPos = Math.max(pos, rightmostFailuresPos);
var actual = actualPos < input.length var actual = actualPos < input.length
? quote(input.charAt(actualPos)) ? quote(input.charAt(actualPos))
: 'end of input'; : "end of input";
return 'Expected ' + expected + ' but ' + actual + ' found.'; return "Expected " + expected + " but " + actual + " found.";
} }
function computeErrorPosition() { function computeErrorPosition() {
@ -3664,11 +3664,11 @@ PEG.parser = (function(){
for (var i = 0; i < rightmostFailuresPos; i++) { for (var i = 0; i < rightmostFailuresPos; i++) {
var ch = input.charAt(i); var ch = input.charAt(i);
if (ch === '\n') { if (ch === "\n") {
if (!seenCR) { line++; } if (!seenCR) { line++; }
column = 1; column = 1;
seenCR = false; seenCR = false;
} else if (ch === '\r' || ch === '\u2028' || ch === '\u2029') { } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
line++; line++;
column = 1; column = 1;
seenCR = true; seenCR = true;
@ -3728,7 +3728,7 @@ PEG.parser = (function(){
/* Thrown when a parser encounters a syntax error. */ /* Thrown when a parser encounters a syntax error. */
result.SyntaxError = function(message, line, column) { result.SyntaxError = function(message, line, column) {
this.name = 'SyntaxError'; this.name = "SyntaxError";
this.message = message; this.message = message;
this.line = line; this.line = line;
this.column = column; this.column = column;

Loading…
Cancel
Save