@ -137,21 +137,6 @@ PEG.compiler.emitter = function(ast) {
" + '\"';" ,
" }" ,
" " ,
/* This needs to be in sync with |contains| in utils.js. */
" function contains(array, value) {" ,
" /*" ,
" * Stupid IE does not have Array.prototype.indexOf, otherwise this" ,
" * function would be a one-liner." ,
" */" ,
" var length = array.length;" ,
" for (var i = 0; i < length; i++) {" ,
" if (array[i] === value) {" ,
" return true;" ,
" }" ,
" }" ,
" return false;" ,
" }" ,
" " ,
" function matchFailed(failure) {" ,
" if (pos < rightmostMatchFailuresPos) {" ,
" return;" ,
@ -162,25 +147,33 @@ PEG.compiler.emitter = function(ast) {
" rightmostMatchFailuresExpected = [];" ,
" }" ,
" " ,
" if (!contains(rightmostMatchFailuresExpected, failure)) {" ,
" rightmostMatchFailuresExpected.push(failure);" ,
" }" ,
" rightmostMatchFailuresExpected.push(failure);" ,
" }" ,
" " ,
" ${parseFunctionDefinitions}" ,
" " ,
" function buildErrorMessage() {" ,
" function buildExpected(failuresExpected) {" ,
" switch (failuresExpected.length) {" ,
" failuresExpected.sort();" ,
" " ,
" var lastFailure = null;" ,
" var failuresExpectedUnique = [];" ,
" for (var i = 0; i < failuresExpected.length; i++) {" ,
" if (failuresExpected[i] !== lastFailure) {" ,
" failuresExpectedUnique.push(failuresExpected[i]);" ,
" lastFailure = failuresExpected[i];" ,
" }" ,
" }" ,
" " ,
" switch (failuresExpectedUnique.length) {" ,
" case 0:" ,
" return 'end of input';" ,
" case 1:" ,
" return failuresExpected[0];" ,
" return failuresExpected Unique [0];",
" default:" ,
" failuresExpected.sort();" ,
" return failuresExpected.slice(0, failuresExpected.length - 1).join(', ')" ,
" return failuresExpectedUnique.slice(0, failuresExpectedUnique.length - 1).join(', ')" ,
" + ' or '" ,
" + failuresExpected[failuresExpected.length - 1];" ,
" + failuresExpected Unique [failuresExpectedUnique .length - 1];",
" }" ,
" }" ,
" " ,