1747 lines
52 KiB
JavaScript
1747 lines
52 KiB
JavaScript
exports.parser = (function(){
|
||
/* Generated by PEG.js (http://pegjs.majda.cz/). */
|
||
|
||
var result = {
|
||
/*
|
||
* Parses the input with a generated parser. If the parsing is successfull,
|
||
* returns a value explicitly or implicitly specified by the grammar from
|
||
* which the parser was generated (see |PEG.buildParser|). If the parsing is
|
||
* unsuccessful, throws |PEG.grammarParser.SyntaxError| describing the error.
|
||
*/
|
||
parse: function(input) {
|
||
var pos = 0;
|
||
var rightmostMatchFailuresPos = 0;
|
||
var rightmostMatchFailuresExpected = [];
|
||
var cache = {};
|
||
|
||
function quoteString(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 may appear in the form of an escape sequence.
|
||
*/
|
||
return '"' + s
|
||
.replace(/\\/g, '\\\\') // backslash
|
||
.replace(/"/g, '\\"') // closing quote character
|
||
.replace(/\r/g, '\\r') // carriage return
|
||
.replace(/\u2028/g, '\\u2028') // line separator
|
||
.replace(/\u2029/g, '\\u2029') // paragraph separator
|
||
.replace(/\n/g, '\\n') // line feed
|
||
+ '"';
|
||
}
|
||
|
||
function arrayContains(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;
|
||
}
|
||
|
||
if (pos > rightmostMatchFailuresPos) {
|
||
rightmostMatchFailuresPos = pos;
|
||
rightmostMatchFailuresExpected = [];
|
||
}
|
||
|
||
if (!arrayContains(rightmostMatchFailuresExpected, failure)) {
|
||
rightmostMatchFailuresExpected.push(failure);
|
||
}
|
||
}
|
||
|
||
function parse_start(context) {
|
||
var cacheKey = "start" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var savedPos0 = pos;
|
||
var result2 = parse__(context);
|
||
if (result2 !== null) {
|
||
var result3 = parse_object(context);
|
||
if (result3 !== null) {
|
||
var result1 = [result2, result3];
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result0 = result1 !== null
|
||
? (function(object) { return object; })(result1[1])
|
||
: null;
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_object(context) {
|
||
var cacheKey = "object" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var savedPos1 = pos;
|
||
if (input.substr(pos, 1) === "{") {
|
||
var result10 = "{";
|
||
pos += 1;
|
||
} else {
|
||
var result10 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("{"));
|
||
}
|
||
}
|
||
if (result10 !== null) {
|
||
var result11 = parse__(context);
|
||
if (result11 !== null) {
|
||
if (input.substr(pos, 1) === "}") {
|
||
var result12 = "}";
|
||
pos += 1;
|
||
} else {
|
||
var result12 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("}"));
|
||
}
|
||
}
|
||
if (result12 !== null) {
|
||
var result13 = parse__(context);
|
||
if (result13 !== null) {
|
||
var result9 = [result10, result11, result12, result13];
|
||
} else {
|
||
var result9 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result9 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result9 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result9 = null;
|
||
pos = savedPos1;
|
||
}
|
||
var result8 = result9 !== null
|
||
? (function() { return {}; })()
|
||
: null;
|
||
if (result8 !== null) {
|
||
var result0 = result8;
|
||
} else {
|
||
var savedPos0 = pos;
|
||
if (input.substr(pos, 1) === "{") {
|
||
var result3 = "{";
|
||
pos += 1;
|
||
} else {
|
||
var result3 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("{"));
|
||
}
|
||
}
|
||
if (result3 !== null) {
|
||
var result4 = parse__(context);
|
||
if (result4 !== null) {
|
||
var result5 = parse_members(context);
|
||
if (result5 !== null) {
|
||
if (input.substr(pos, 1) === "}") {
|
||
var result6 = "}";
|
||
pos += 1;
|
||
} else {
|
||
var result6 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("}"));
|
||
}
|
||
}
|
||
if (result6 !== null) {
|
||
var result7 = parse__(context);
|
||
if (result7 !== null) {
|
||
var result2 = [result3, result4, result5, result6, result7];
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result1 = result2 !== null
|
||
? (function(members) { return members; })(result2[2])
|
||
: null;
|
||
if (result1 !== null) {
|
||
var result0 = result1;
|
||
} else {
|
||
var result0 = null;;
|
||
};
|
||
}
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_members(context) {
|
||
var cacheKey = "members" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var savedPos0 = pos;
|
||
var result2 = parse_pair(context);
|
||
if (result2 !== null) {
|
||
var result3 = [];
|
||
var savedPos1 = pos;
|
||
if (input.substr(pos, 1) === ",") {
|
||
var result5 = ",";
|
||
pos += 1;
|
||
} else {
|
||
var result5 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString(","));
|
||
}
|
||
}
|
||
if (result5 !== null) {
|
||
var result6 = parse__(context);
|
||
if (result6 !== null) {
|
||
var result7 = parse_pair(context);
|
||
if (result7 !== null) {
|
||
var result4 = [result5, result6, result7];
|
||
} else {
|
||
var result4 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result4 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result4 = null;
|
||
pos = savedPos1;
|
||
}
|
||
while (result4 !== null) {
|
||
result3.push(result4);
|
||
var savedPos1 = pos;
|
||
if (input.substr(pos, 1) === ",") {
|
||
var result5 = ",";
|
||
pos += 1;
|
||
} else {
|
||
var result5 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString(","));
|
||
}
|
||
}
|
||
if (result5 !== null) {
|
||
var result6 = parse__(context);
|
||
if (result6 !== null) {
|
||
var result7 = parse_pair(context);
|
||
if (result7 !== null) {
|
||
var result4 = [result5, result6, result7];
|
||
} else {
|
||
var result4 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result4 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result4 = null;
|
||
pos = savedPos1;
|
||
}
|
||
}
|
||
if (result3 !== null) {
|
||
var result1 = [result2, result3];
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result0 = result1 !== null
|
||
? (function(head, tail) {
|
||
var result = {};
|
||
result[head[0]] = head[1];
|
||
for (var i = 0; i < tail.length; i++) {
|
||
result[tail[i][2][0]] = tail[i][2][1];
|
||
}
|
||
return result;
|
||
})(result1[0], result1[1])
|
||
: null;
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_pair(context) {
|
||
var cacheKey = "pair" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var savedPos0 = pos;
|
||
var result2 = parse_string(context);
|
||
if (result2 !== null) {
|
||
if (input.substr(pos, 1) === ":") {
|
||
var result3 = ":";
|
||
pos += 1;
|
||
} else {
|
||
var result3 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString(":"));
|
||
}
|
||
}
|
||
if (result3 !== null) {
|
||
var result4 = parse__(context);
|
||
if (result4 !== null) {
|
||
var result5 = parse_value(context);
|
||
if (result5 !== null) {
|
||
var result1 = [result2, result3, result4, result5];
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result0 = result1 !== null
|
||
? (function(name, value) { return [name, value]; })(result1[0], result1[3])
|
||
: null;
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_array(context) {
|
||
var cacheKey = "array" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var savedPos1 = pos;
|
||
if (input.substr(pos, 1) === "[") {
|
||
var result10 = "[";
|
||
pos += 1;
|
||
} else {
|
||
var result10 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("["));
|
||
}
|
||
}
|
||
if (result10 !== null) {
|
||
var result11 = parse__(context);
|
||
if (result11 !== null) {
|
||
if (input.substr(pos, 1) === "]") {
|
||
var result12 = "]";
|
||
pos += 1;
|
||
} else {
|
||
var result12 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("]"));
|
||
}
|
||
}
|
||
if (result12 !== null) {
|
||
var result13 = parse__(context);
|
||
if (result13 !== null) {
|
||
var result9 = [result10, result11, result12, result13];
|
||
} else {
|
||
var result9 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result9 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result9 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result9 = null;
|
||
pos = savedPos1;
|
||
}
|
||
var result8 = result9 !== null
|
||
? (function() { return []; })()
|
||
: null;
|
||
if (result8 !== null) {
|
||
var result0 = result8;
|
||
} else {
|
||
var savedPos0 = pos;
|
||
if (input.substr(pos, 1) === "[") {
|
||
var result3 = "[";
|
||
pos += 1;
|
||
} else {
|
||
var result3 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("["));
|
||
}
|
||
}
|
||
if (result3 !== null) {
|
||
var result4 = parse__(context);
|
||
if (result4 !== null) {
|
||
var result5 = parse_elements(context);
|
||
if (result5 !== null) {
|
||
if (input.substr(pos, 1) === "]") {
|
||
var result6 = "]";
|
||
pos += 1;
|
||
} else {
|
||
var result6 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("]"));
|
||
}
|
||
}
|
||
if (result6 !== null) {
|
||
var result7 = parse__(context);
|
||
if (result7 !== null) {
|
||
var result2 = [result3, result4, result5, result6, result7];
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result1 = result2 !== null
|
||
? (function(elements) { return elements; })(result2[2])
|
||
: null;
|
||
if (result1 !== null) {
|
||
var result0 = result1;
|
||
} else {
|
||
var result0 = null;;
|
||
};
|
||
}
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_elements(context) {
|
||
var cacheKey = "elements" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var savedPos0 = pos;
|
||
var result2 = parse_value(context);
|
||
if (result2 !== null) {
|
||
var result3 = [];
|
||
var savedPos1 = pos;
|
||
if (input.substr(pos, 1) === ",") {
|
||
var result5 = ",";
|
||
pos += 1;
|
||
} else {
|
||
var result5 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString(","));
|
||
}
|
||
}
|
||
if (result5 !== null) {
|
||
var result6 = parse__(context);
|
||
if (result6 !== null) {
|
||
var result7 = parse_value(context);
|
||
if (result7 !== null) {
|
||
var result4 = [result5, result6, result7];
|
||
} else {
|
||
var result4 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result4 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result4 = null;
|
||
pos = savedPos1;
|
||
}
|
||
while (result4 !== null) {
|
||
result3.push(result4);
|
||
var savedPos1 = pos;
|
||
if (input.substr(pos, 1) === ",") {
|
||
var result5 = ",";
|
||
pos += 1;
|
||
} else {
|
||
var result5 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString(","));
|
||
}
|
||
}
|
||
if (result5 !== null) {
|
||
var result6 = parse__(context);
|
||
if (result6 !== null) {
|
||
var result7 = parse_value(context);
|
||
if (result7 !== null) {
|
||
var result4 = [result5, result6, result7];
|
||
} else {
|
||
var result4 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result4 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result4 = null;
|
||
pos = savedPos1;
|
||
}
|
||
}
|
||
if (result3 !== null) {
|
||
var result1 = [result2, result3];
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result0 = result1 !== null
|
||
? (function(head, tail) {
|
||
var result = [head];
|
||
for (var i = 0; i < tail.length; i++) {
|
||
result.push(tail[i][2]);
|
||
}
|
||
return result;
|
||
})(result1[0], result1[1])
|
||
: null;
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_value(context) {
|
||
var cacheKey = "value" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var result16 = parse_string(context);
|
||
if (result16 !== null) {
|
||
var result0 = result16;
|
||
} else {
|
||
var result15 = parse_number(context);
|
||
if (result15 !== null) {
|
||
var result0 = result15;
|
||
} else {
|
||
var result14 = parse_object(context);
|
||
if (result14 !== null) {
|
||
var result0 = result14;
|
||
} else {
|
||
var result13 = parse_array(context);
|
||
if (result13 !== null) {
|
||
var result0 = result13;
|
||
} else {
|
||
var savedPos2 = pos;
|
||
if (input.substr(pos, 4) === "true") {
|
||
var result11 = "true";
|
||
pos += 4;
|
||
} else {
|
||
var result11 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("true"));
|
||
}
|
||
}
|
||
if (result11 !== null) {
|
||
var result12 = parse__(context);
|
||
if (result12 !== null) {
|
||
var result10 = [result11, result12];
|
||
} else {
|
||
var result10 = null;
|
||
pos = savedPos2;
|
||
}
|
||
} else {
|
||
var result10 = null;
|
||
pos = savedPos2;
|
||
}
|
||
var result9 = result10 !== null
|
||
? (function() { return true; })()
|
||
: null;
|
||
if (result9 !== null) {
|
||
var result0 = result9;
|
||
} else {
|
||
var savedPos1 = pos;
|
||
if (input.substr(pos, 5) === "false") {
|
||
var result7 = "false";
|
||
pos += 5;
|
||
} else {
|
||
var result7 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("false"));
|
||
}
|
||
}
|
||
if (result7 !== null) {
|
||
var result8 = parse__(context);
|
||
if (result8 !== null) {
|
||
var result6 = [result7, result8];
|
||
} else {
|
||
var result6 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result6 = null;
|
||
pos = savedPos1;
|
||
}
|
||
var result5 = result6 !== null
|
||
? (function() { return false; })()
|
||
: null;
|
||
if (result5 !== null) {
|
||
var result0 = result5;
|
||
} else {
|
||
var savedPos0 = pos;
|
||
if (input.substr(pos, 4) === "null") {
|
||
var result3 = "null";
|
||
pos += 4;
|
||
} else {
|
||
var result3 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("null"));
|
||
}
|
||
}
|
||
if (result3 !== null) {
|
||
var result4 = parse__(context);
|
||
if (result4 !== null) {
|
||
var result2 = [result3, result4];
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result1 = result2 !== null
|
||
? (function() { return "null"; })()
|
||
: null;
|
||
if (result1 !== null) {
|
||
var result0 = result1;
|
||
} else {
|
||
var result0 = null;;
|
||
};
|
||
};
|
||
};
|
||
};
|
||
};
|
||
};
|
||
}
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_string(context) {
|
||
var cacheKey = "string" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
var savedReportMatchFailures = context.reportMatchFailures;
|
||
context.reportMatchFailures = false;
|
||
var savedPos1 = pos;
|
||
if (input.substr(pos, 1) === "\"") {
|
||
var result9 = "\"";
|
||
pos += 1;
|
||
} else {
|
||
var result9 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\""));
|
||
}
|
||
}
|
||
if (result9 !== null) {
|
||
if (input.substr(pos, 1) === "\"") {
|
||
var result10 = "\"";
|
||
pos += 1;
|
||
} else {
|
||
var result10 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\""));
|
||
}
|
||
}
|
||
if (result10 !== null) {
|
||
var result11 = parse__(context);
|
||
if (result11 !== null) {
|
||
var result8 = [result9, result10, result11];
|
||
} else {
|
||
var result8 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result8 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result8 = null;
|
||
pos = savedPos1;
|
||
}
|
||
var result7 = result8 !== null
|
||
? (function() { return ""; })()
|
||
: null;
|
||
if (result7 !== null) {
|
||
var result0 = result7;
|
||
} else {
|
||
var savedPos0 = pos;
|
||
if (input.substr(pos, 1) === "\"") {
|
||
var result3 = "\"";
|
||
pos += 1;
|
||
} else {
|
||
var result3 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\""));
|
||
}
|
||
}
|
||
if (result3 !== null) {
|
||
var result4 = parse_chars(context);
|
||
if (result4 !== null) {
|
||
if (input.substr(pos, 1) === "\"") {
|
||
var result5 = "\"";
|
||
pos += 1;
|
||
} else {
|
||
var result5 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\""));
|
||
}
|
||
}
|
||
if (result5 !== null) {
|
||
var result6 = parse__(context);
|
||
if (result6 !== null) {
|
||
var result2 = [result3, result4, result5, result6];
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result1 = result2 !== null
|
||
? (function(chars) { return chars; })(result2[1])
|
||
: null;
|
||
if (result1 !== null) {
|
||
var result0 = result1;
|
||
} else {
|
||
var result0 = null;;
|
||
};
|
||
}
|
||
context.reportMatchFailures = savedReportMatchFailures;
|
||
if (context.reportMatchFailures && result0 === null) {
|
||
matchFailed("string");
|
||
}
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_chars(context) {
|
||
var cacheKey = "chars" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var result2 = parse_char(context);
|
||
if (result2 !== null) {
|
||
var result1 = [];
|
||
while (result2 !== null) {
|
||
result1.push(result2);
|
||
var result2 = parse_char(context);
|
||
}
|
||
} else {
|
||
var result1 = null;
|
||
}
|
||
var result0 = result1 !== null
|
||
? (function(chars) { return chars.join(""); })(result1)
|
||
: null;
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_char(context) {
|
||
var cacheKey = "char" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
if (input.substr(pos).match(/^[^"\\\0-]/) !== null) {
|
||
var result24 = input.charAt(pos);
|
||
pos++;
|
||
} else {
|
||
var result24 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed("[^\"\\\\\\0-]");
|
||
}
|
||
}
|
||
if (result24 !== null) {
|
||
var result0 = result24;
|
||
} else {
|
||
if (input.substr(pos, 2) === "\\\"") {
|
||
var result23 = "\\\"";
|
||
pos += 2;
|
||
} else {
|
||
var result23 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\\\""));
|
||
}
|
||
}
|
||
var result22 = result23 !== null
|
||
? (function() { return '"'; })()
|
||
: null;
|
||
if (result22 !== null) {
|
||
var result0 = result22;
|
||
} else {
|
||
if (input.substr(pos, 2) === "\\\\") {
|
||
var result21 = "\\\\";
|
||
pos += 2;
|
||
} else {
|
||
var result21 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\\\\"));
|
||
}
|
||
}
|
||
var result20 = result21 !== null
|
||
? (function() { return "\\"; })()
|
||
: null;
|
||
if (result20 !== null) {
|
||
var result0 = result20;
|
||
} else {
|
||
if (input.substr(pos, 2) === "\\/") {
|
||
var result19 = "\\/";
|
||
pos += 2;
|
||
} else {
|
||
var result19 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\\/"));
|
||
}
|
||
}
|
||
var result18 = result19 !== null
|
||
? (function() { return "/"; })()
|
||
: null;
|
||
if (result18 !== null) {
|
||
var result0 = result18;
|
||
} else {
|
||
if (input.substr(pos, 2) === "\\b") {
|
||
var result17 = "\\b";
|
||
pos += 2;
|
||
} else {
|
||
var result17 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\\b"));
|
||
}
|
||
}
|
||
var result16 = result17 !== null
|
||
? (function() { return "\b"; })()
|
||
: null;
|
||
if (result16 !== null) {
|
||
var result0 = result16;
|
||
} else {
|
||
if (input.substr(pos, 2) === "\\f") {
|
||
var result15 = "\\f";
|
||
pos += 2;
|
||
} else {
|
||
var result15 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\\f"));
|
||
}
|
||
}
|
||
var result14 = result15 !== null
|
||
? (function() { return "\f"; })()
|
||
: null;
|
||
if (result14 !== null) {
|
||
var result0 = result14;
|
||
} else {
|
||
if (input.substr(pos, 2) === "\\n") {
|
||
var result13 = "\\n";
|
||
pos += 2;
|
||
} else {
|
||
var result13 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\\n"));
|
||
}
|
||
}
|
||
var result12 = result13 !== null
|
||
? (function() { return "\n"; })()
|
||
: null;
|
||
if (result12 !== null) {
|
||
var result0 = result12;
|
||
} else {
|
||
if (input.substr(pos, 2) === "\\r") {
|
||
var result11 = "\\r";
|
||
pos += 2;
|
||
} else {
|
||
var result11 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\\r"));
|
||
}
|
||
}
|
||
var result10 = result11 !== null
|
||
? (function() { return "\r"; })()
|
||
: null;
|
||
if (result10 !== null) {
|
||
var result0 = result10;
|
||
} else {
|
||
if (input.substr(pos, 2) === "\\t") {
|
||
var result9 = "\\t";
|
||
pos += 2;
|
||
} else {
|
||
var result9 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\\t"));
|
||
}
|
||
}
|
||
var result8 = result9 !== null
|
||
? (function() { return "\t"; })()
|
||
: null;
|
||
if (result8 !== null) {
|
||
var result0 = result8;
|
||
} else {
|
||
var savedPos0 = pos;
|
||
if (input.substr(pos, 2) === "\\u") {
|
||
var result3 = "\\u";
|
||
pos += 2;
|
||
} else {
|
||
var result3 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("\\u"));
|
||
}
|
||
}
|
||
if (result3 !== null) {
|
||
var result4 = parse_hexDigit(context);
|
||
if (result4 !== null) {
|
||
var result5 = parse_hexDigit(context);
|
||
if (result5 !== null) {
|
||
var result6 = parse_hexDigit(context);
|
||
if (result6 !== null) {
|
||
var result7 = parse_hexDigit(context);
|
||
if (result7 !== null) {
|
||
var result2 = [result3, result4, result5, result6, result7];
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result1 = result2 !== null
|
||
? (function(h1, h2, h3, h4) {
|
||
return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
|
||
})(result2[1], result2[2], result2[3], result2[4])
|
||
: null;
|
||
if (result1 !== null) {
|
||
var result0 = result1;
|
||
} else {
|
||
var result0 = null;;
|
||
};
|
||
};
|
||
};
|
||
};
|
||
};
|
||
};
|
||
};
|
||
};
|
||
};
|
||
}
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_number(context) {
|
||
var cacheKey = "number" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
var savedReportMatchFailures = context.reportMatchFailures;
|
||
context.reportMatchFailures = false;
|
||
var savedPos3 = pos;
|
||
var result17 = parse_int(context);
|
||
if (result17 !== null) {
|
||
var result18 = parse_frac(context);
|
||
if (result18 !== null) {
|
||
var result19 = parse_exp(context);
|
||
if (result19 !== null) {
|
||
var result20 = parse__(context);
|
||
if (result20 !== null) {
|
||
var result16 = [result17, result18, result19, result20];
|
||
} else {
|
||
var result16 = null;
|
||
pos = savedPos3;
|
||
}
|
||
} else {
|
||
var result16 = null;
|
||
pos = savedPos3;
|
||
}
|
||
} else {
|
||
var result16 = null;
|
||
pos = savedPos3;
|
||
}
|
||
} else {
|
||
var result16 = null;
|
||
pos = savedPos3;
|
||
}
|
||
var result15 = result16 !== null
|
||
? (function(int_, frac, exp) { return parseFloat(int_ + frac + exp); })(result16[0], result16[1], result16[2])
|
||
: null;
|
||
if (result15 !== null) {
|
||
var result0 = result15;
|
||
} else {
|
||
var savedPos2 = pos;
|
||
var result12 = parse_int(context);
|
||
if (result12 !== null) {
|
||
var result13 = parse_frac(context);
|
||
if (result13 !== null) {
|
||
var result14 = parse__(context);
|
||
if (result14 !== null) {
|
||
var result11 = [result12, result13, result14];
|
||
} else {
|
||
var result11 = null;
|
||
pos = savedPos2;
|
||
}
|
||
} else {
|
||
var result11 = null;
|
||
pos = savedPos2;
|
||
}
|
||
} else {
|
||
var result11 = null;
|
||
pos = savedPos2;
|
||
}
|
||
var result10 = result11 !== null
|
||
? (function(int_, frac) { return parseFloat(int_ + frac); })(result11[0], result11[1])
|
||
: null;
|
||
if (result10 !== null) {
|
||
var result0 = result10;
|
||
} else {
|
||
var savedPos1 = pos;
|
||
var result7 = parse_int(context);
|
||
if (result7 !== null) {
|
||
var result8 = parse_exp(context);
|
||
if (result8 !== null) {
|
||
var result9 = parse__(context);
|
||
if (result9 !== null) {
|
||
var result6 = [result7, result8, result9];
|
||
} else {
|
||
var result6 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result6 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result6 = null;
|
||
pos = savedPos1;
|
||
}
|
||
var result5 = result6 !== null
|
||
? (function(int_, exp) { return parseFloat(int_ + exp); })(result6[0], result6[1])
|
||
: null;
|
||
if (result5 !== null) {
|
||
var result0 = result5;
|
||
} else {
|
||
var savedPos0 = pos;
|
||
var result3 = parse_int(context);
|
||
if (result3 !== null) {
|
||
var result4 = parse__(context);
|
||
if (result4 !== null) {
|
||
var result2 = [result3, result4];
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result1 = result2 !== null
|
||
? (function(int_) { return parseFloat(int_); })(result2[0])
|
||
: null;
|
||
if (result1 !== null) {
|
||
var result0 = result1;
|
||
} else {
|
||
var result0 = null;;
|
||
};
|
||
};
|
||
};
|
||
}
|
||
context.reportMatchFailures = savedReportMatchFailures;
|
||
if (context.reportMatchFailures && result0 === null) {
|
||
matchFailed("number");
|
||
}
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_int(context) {
|
||
var cacheKey = "int" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var savedPos2 = pos;
|
||
var result13 = parse_digit19(context);
|
||
if (result13 !== null) {
|
||
var result14 = parse_digits(context);
|
||
if (result14 !== null) {
|
||
var result12 = [result13, result14];
|
||
} else {
|
||
var result12 = null;
|
||
pos = savedPos2;
|
||
}
|
||
} else {
|
||
var result12 = null;
|
||
pos = savedPos2;
|
||
}
|
||
var result11 = result12 !== null
|
||
? (function(digit19, digits) { return digit19 + digits; })(result12[0], result12[1])
|
||
: null;
|
||
if (result11 !== null) {
|
||
var result0 = result11;
|
||
} else {
|
||
var result10 = parse_digit(context);
|
||
if (result10 !== null) {
|
||
var result0 = result10;
|
||
} else {
|
||
var savedPos1 = pos;
|
||
if (input.substr(pos, 1) === "-") {
|
||
var result7 = "-";
|
||
pos += 1;
|
||
} else {
|
||
var result7 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("-"));
|
||
}
|
||
}
|
||
if (result7 !== null) {
|
||
var result8 = parse_digit19(context);
|
||
if (result8 !== null) {
|
||
var result9 = parse_digits(context);
|
||
if (result9 !== null) {
|
||
var result6 = [result7, result8, result9];
|
||
} else {
|
||
var result6 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result6 = null;
|
||
pos = savedPos1;
|
||
}
|
||
} else {
|
||
var result6 = null;
|
||
pos = savedPos1;
|
||
}
|
||
var result5 = result6 !== null
|
||
? (function(digit19, digits) { return "-" + digit19 + digits; })(result6[1], result6[2])
|
||
: null;
|
||
if (result5 !== null) {
|
||
var result0 = result5;
|
||
} else {
|
||
var savedPos0 = pos;
|
||
if (input.substr(pos, 1) === "-") {
|
||
var result3 = "-";
|
||
pos += 1;
|
||
} else {
|
||
var result3 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("-"));
|
||
}
|
||
}
|
||
if (result3 !== null) {
|
||
var result4 = parse_digit(context);
|
||
if (result4 !== null) {
|
||
var result2 = [result3, result4];
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result2 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result1 = result2 !== null
|
||
? (function(digit) { return "-" + digit; })(result2[1])
|
||
: null;
|
||
if (result1 !== null) {
|
||
var result0 = result1;
|
||
} else {
|
||
var result0 = null;;
|
||
};
|
||
};
|
||
};
|
||
}
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_frac(context) {
|
||
var cacheKey = "frac" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var savedPos0 = pos;
|
||
if (input.substr(pos, 1) === ".") {
|
||
var result2 = ".";
|
||
pos += 1;
|
||
} else {
|
||
var result2 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed(quoteString("."));
|
||
}
|
||
}
|
||
if (result2 !== null) {
|
||
var result3 = parse_digits(context);
|
||
if (result3 !== null) {
|
||
var result1 = [result2, result3];
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result0 = result1 !== null
|
||
? (function(digits) { return "." + digits; })(result1[1])
|
||
: null;
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_exp(context) {
|
||
var cacheKey = "exp" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var savedPos0 = pos;
|
||
var result2 = parse_e(context);
|
||
if (result2 !== null) {
|
||
var result3 = parse_digits(context);
|
||
if (result3 !== null) {
|
||
var result1 = [result2, result3];
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result0 = result1 !== null
|
||
? (function(e, digits) { return e + digits; })(result1[0], result1[1])
|
||
: null;
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_digits(context) {
|
||
var cacheKey = "digits" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var result2 = parse_digit(context);
|
||
if (result2 !== null) {
|
||
var result1 = [];
|
||
while (result2 !== null) {
|
||
result1.push(result2);
|
||
var result2 = parse_digit(context);
|
||
}
|
||
} else {
|
||
var result1 = null;
|
||
}
|
||
var result0 = result1 !== null
|
||
? (function(digits) { return digits.join(""); })(result1)
|
||
: null;
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_e(context) {
|
||
var cacheKey = "e" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
var savedPos0 = pos;
|
||
if (input.substr(pos).match(/^[eE]/) !== null) {
|
||
var result2 = input.charAt(pos);
|
||
pos++;
|
||
} else {
|
||
var result2 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed("[eE]");
|
||
}
|
||
}
|
||
if (result2 !== null) {
|
||
if (input.substr(pos).match(/^[+\-]/) !== null) {
|
||
var result4 = input.charAt(pos);
|
||
pos++;
|
||
} else {
|
||
var result4 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed("[+\\-]");
|
||
}
|
||
}
|
||
var result3 = result4 !== null ? result4 : '';
|
||
if (result3 !== null) {
|
||
var result1 = [result2, result3];
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
} else {
|
||
var result1 = null;
|
||
pos = savedPos0;
|
||
}
|
||
var result0 = result1 !== null
|
||
? (function(e, sign) { return e + sign; })(result1[0], result1[1])
|
||
: null;
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_digit(context) {
|
||
var cacheKey = "digit" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
if (input.substr(pos).match(/^[0-9]/) !== null) {
|
||
var result0 = input.charAt(pos);
|
||
pos++;
|
||
} else {
|
||
var result0 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed("[0-9]");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_digit19(context) {
|
||
var cacheKey = "digit19" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
if (input.substr(pos).match(/^[1-9]/) !== null) {
|
||
var result0 = input.charAt(pos);
|
||
pos++;
|
||
} else {
|
||
var result0 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed("[1-9]");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_hexDigit(context) {
|
||
var cacheKey = "hexDigit" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
if (input.substr(pos).match(/^[0-9a-fA-F]/) !== null) {
|
||
var result0 = input.charAt(pos);
|
||
pos++;
|
||
} else {
|
||
var result0 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed("[0-9a-fA-F]");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse__(context) {
|
||
var cacheKey = "_" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
var savedReportMatchFailures = context.reportMatchFailures;
|
||
context.reportMatchFailures = false;
|
||
var result0 = [];
|
||
var result1 = parse_whitespace(context);
|
||
while (result1 !== null) {
|
||
result0.push(result1);
|
||
var result1 = parse_whitespace(context);
|
||
}
|
||
context.reportMatchFailures = savedReportMatchFailures;
|
||
if (context.reportMatchFailures && result0 === null) {
|
||
matchFailed("whitespace");
|
||
}
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function parse_whitespace(context) {
|
||
var cacheKey = "whitespace" + '@' + pos;
|
||
var cachedResult = cache[cacheKey];
|
||
if (cachedResult) {
|
||
pos = cachedResult.nextPos;
|
||
return cachedResult.result;
|
||
}
|
||
|
||
|
||
if (input.substr(pos).match(/^[ \n\r]/) !== null) {
|
||
var result0 = input.charAt(pos);
|
||
pos++;
|
||
} else {
|
||
var result0 = null;
|
||
if (context.reportMatchFailures) {
|
||
matchFailed("[ \\n\\r]");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
cache[cacheKey] = {
|
||
nextPos: pos,
|
||
result: result0
|
||
};
|
||
return result0;
|
||
}
|
||
|
||
function buildErrorMessage() {
|
||
function buildExpected(failuresExpected) {
|
||
switch (failuresExpected.length) {
|
||
case 0:
|
||
return 'end of input';
|
||
case 1:
|
||
return failuresExpected[0];
|
||
default:
|
||
failuresExpected.sort();
|
||
return failuresExpected.slice(0, failuresExpected.length - 1).join(', ')
|
||
+ ' or '
|
||
+ failuresExpected[failuresExpected.length - 1];
|
||
}
|
||
}
|
||
|
||
var expected = buildExpected(rightmostMatchFailuresExpected);
|
||
var actualPos = Math.max(pos, rightmostMatchFailuresPos);
|
||
var actual = actualPos < input.length
|
||
? quoteString(input.charAt(actualPos))
|
||
: 'end of input';
|
||
|
||
return 'Expected ' + expected + ' but ' + actual + ' found.';
|
||
}
|
||
|
||
function computeErrorPosition() {
|
||
/*
|
||
* 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
|
||
* there. However IE's |split| implementation is so broken that it was
|
||
* enough to prevent it.
|
||
*/
|
||
|
||
var line = 1;
|
||
var column = 1;
|
||
var seenCR = false;
|
||
|
||
for (var i = 0; i < rightmostMatchFailuresPos; i++) {
|
||
var ch = input.charAt(i);
|
||
if (ch === '\n') {
|
||
if (!seenCR) { line++; }
|
||
column = 1;
|
||
seenCR = false;
|
||
} else if (ch === '\r' | ch === '\u2028' || ch === '\u2029') {
|
||
line++;
|
||
column = 1;
|
||
seenCR = true;
|
||
} else {
|
||
column++;
|
||
seenCR = false;
|
||
}
|
||
}
|
||
|
||
return { line: line, column: column };
|
||
}
|
||
|
||
|
||
|
||
var result = parse_start({ reportMatchFailures: true });
|
||
|
||
/*
|
||
* The parser is now in one of the following three states:
|
||
*
|
||
* 1. The parser successfully parsed the whole input.
|
||
*
|
||
* - |result !== null|
|
||
* - |pos === input.length|
|
||
* - |rightmostMatchFailuresExpected| may or may not contain something
|
||
*
|
||
* 2. The parser successfully parsed only a part of the input.
|
||
*
|
||
* - |result !== null|
|
||
* - |pos < input.length|
|
||
* - |rightmostMatchFailuresExpected| may or may not contain something
|
||
*
|
||
* 3. The parser did not successfully parse any part of the input.
|
||
*
|
||
* - |result === null|
|
||
* - |pos === 0|
|
||
* - |rightmostMatchFailuresExpected| contains at least one failure
|
||
*
|
||
* All code following this comment (including called functions) must
|
||
* handle these states.
|
||
*/
|
||
if (result === null || pos !== input.length) {
|
||
var errorPosition = computeErrorPosition();
|
||
throw new this.SyntaxError(
|
||
buildErrorMessage(),
|
||
errorPosition.line,
|
||
errorPosition.column
|
||
);
|
||
}
|
||
|
||
return result;
|
||
},
|
||
|
||
/* Returns the parser source code. */
|
||
toSource: function() { return this._source; }
|
||
};
|
||
|
||
/* Thrown when a parser encounters a syntax error. */
|
||
|
||
result.SyntaxError = function(message, line, column) {
|
||
this.name = 'SyntaxError';
|
||
this.message = message;
|
||
this.line = line;
|
||
this.column = column;
|
||
};
|
||
|
||
result.SyntaxError.prototype = Error.prototype;
|
||
|
||
return result;
|
||
})(); |