You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2886 lines
70 KiB
JavaScript

module.exports = (function(){
/*
* Generated by PEG.js 0.7.0.
*
* http://pegjs.majda.cz/
*/
function subclass(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor();
}
function quote(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.
*
* For portability, we also escape escape all control and non-ASCII
* characters. Note that "\0" and "\v" escape sequences are not used
* because JSHint does not like the first and IE the second.
*/
return '"' + s
.replace(/\\/g, '\\\\') // backslash
.replace(/"/g, '\\"') // closing quote character
.replace(/\x08/g, '\\b') // backspace
.replace(/\t/g, '\\t') // horizontal tab
.replace(/\n/g, '\\n') // line feed
.replace(/\f/g, '\\f') // form feed
.replace(/\r/g, '\\r') // carriage return
.replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape)
+ '"';
}
var result = {
/*
* Parses the input with a generated parser. If the parsing is successful,
* 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.parser.SyntaxError| describing the error.
*/
parse: function(input) {
var parseFunctions = {
"grammar": parse_grammar
};
var options = arguments.length > 1 ? arguments[1] : {},
startRule;
if (options.startRule !== undefined) {
startRule = options.startRule;
if (parseFunctions[startRule] === undefined) {
throw new Error("Can't start parsing from rule " + quote(startRule) + ".");
}
} else {
startRule = "grammar";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_grammar() {
var r0, r1, r2, r3, r4, r5, r6;
r1 = pos;
r2 = pos;
r3 = parse___();
if (r3 !== null) {
r4 = parse_initializer();
r4 = r4 !== null ? r4 : "";
if (r4 !== null) {
r6 = parse_rule();
if (r6 !== null) {
r5 = [];
while (r6 !== null) {
r5.push(r6);
r6 = parse_rule();
}
} else {
r5 = null;
}
if (r5 !== null) {
r0 = [r3, r4, r5];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, initializer, rules) {
return {
type: "grammar",
initializer: initializer !== "" ? initializer : null,
rules: rules,
startRule: rules[0].name
};
})(r1, r4, r5);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_initializer() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
r3 = parse_action();
if (r3 !== null) {
r4 = parse_semicolon();
r4 = r4 !== null ? r4 : "";
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, code) {
return {
type: "initializer",
code: code
};
})(r1, r3);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_rule() {
var r0, r1, r2, r3, r4, r5, r6, r7;
r1 = pos;
r2 = pos;
r3 = parse_identifier();
if (r3 !== null) {
r4 = parse_string();
r4 = r4 !== null ? r4 : "";
if (r4 !== null) {
r5 = parse_equals();
if (r5 !== null) {
r6 = parse_choice();
if (r6 !== null) {
r7 = parse_semicolon();
r7 = r7 !== null ? r7 : "";
if (r7 !== null) {
r0 = [r3, r4, r5, r6, r7];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, name, displayName, expression) {
return {
type: "rule",
name: name,
expression: displayName !== ""
? {
type: "named",
name: displayName,
expression: expression
}
: expression
};
})(r1, r3, r4, r6);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_choice() {
var r0, r1, r2, r3, r4, r5, r6, r7, r8;
r1 = pos;
r2 = pos;
r3 = parse_sequence();
if (r3 !== null) {
r4 = [];
r6 = pos;
r7 = parse_slash();
if (r7 !== null) {
r8 = parse_sequence();
if (r8 !== null) {
r5 = [r7, r8];
} else {
r5 = null;
pos = r6;
}
} else {
r5 = null;
pos = r6;
}
while (r5 !== null) {
r4.push(r5);
r6 = pos;
r7 = parse_slash();
if (r7 !== null) {
r8 = parse_sequence();
if (r8 !== null) {
r5 = [r7, r8];
} else {
r5 = null;
pos = r6;
}
} else {
r5 = null;
pos = r6;
}
}
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, head, tail) {
if (tail.length > 0) {
var alternatives = [head].concat(utils.map(
tail,
function(element) { return element[1]; }
));
return {
type: "choice",
alternatives: alternatives
};
} else {
return head;
}
})(r1, r3, r4);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_sequence() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
r3 = [];
r4 = parse_labeled();
while (r4 !== null) {
r3.push(r4);
r4 = parse_labeled();
}
if (r3 !== null) {
r4 = parse_action();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, elements, code) {
var expression = elements.length !== 1
? {
type: "sequence",
elements: elements
}
: elements[0];
return {
type: "action",
expression: expression,
code: code
};
})(r1, r3, r4);
}
if (r0 === null) {
pos = r1;
}
if (r0 === null) {
r1 = pos;
r0 = [];
r2 = parse_labeled();
while (r2 !== null) {
r0.push(r2);
r2 = parse_labeled();
}
if (r0 !== null) {
r0 = (function(offset, elements) {
return elements.length !== 1
? {
type: "sequence",
elements: elements
}
: elements[0];
})(r1, r0);
}
if (r0 === null) {
pos = r1;
}
}
return r0;
}
function parse_labeled() {
var r0, r1, r2, r3, r4, r5;
r1 = pos;
r2 = pos;
r3 = parse_identifier();
if (r3 !== null) {
r4 = parse_colon();
if (r4 !== null) {
r5 = parse_prefixed();
if (r5 !== null) {
r0 = [r3, r4, r5];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, label, expression) {
return {
type: "labeled",
label: label,
expression: expression
};
})(r1, r3, r5);
}
if (r0 === null) {
pos = r1;
}
if (r0 === null) {
r0 = parse_prefixed();
}
return r0;
}
function parse_prefixed() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
r3 = parse_and();
if (r3 !== null) {
r4 = parse_action();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, code) {
return {
type: "semantic_and",
code: code
};
})(r1, r4);
}
if (r0 === null) {
pos = r1;
}
if (r0 === null) {
r1 = pos;
r2 = pos;
r3 = parse_and();
if (r3 !== null) {
r4 = parse_suffixed();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, expression) {
return {
type: "simple_and",
expression: expression
};
})(r1, r4);
}
if (r0 === null) {
pos = r1;
}
if (r0 === null) {
r1 = pos;
r2 = pos;
r3 = parse_not();
if (r3 !== null) {
r4 = parse_action();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, code) {
return {
type: "semantic_not",
code: code
};
})(r1, r4);
}
if (r0 === null) {
pos = r1;
}
if (r0 === null) {
r1 = pos;
r2 = pos;
r3 = parse_not();
if (r3 !== null) {
r4 = parse_suffixed();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, expression) {
return {
type: "simple_not",
expression: expression
};
})(r1, r4);
}
if (r0 === null) {
pos = r1;
}
if (r0 === null) {
r0 = parse_suffixed();
}
}
}
}
return r0;
}
function parse_suffixed() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
r3 = parse_primary();
if (r3 !== null) {
r4 = parse_question();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, expression) {
return {
type: "optional",
expression: expression
};
})(r1, r3);
}
if (r0 === null) {
pos = r1;
}
if (r0 === null) {
r1 = pos;
r2 = pos;
r3 = parse_primary();
if (r3 !== null) {
r4 = parse_star();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, expression) {
return {
type: "zero_or_more",
expression: expression
};
})(r1, r3);
}
if (r0 === null) {
pos = r1;
}
if (r0 === null) {
r1 = pos;
r2 = pos;
r3 = parse_primary();
if (r3 !== null) {
r4 = parse_plus();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, expression) {
return {
type: "one_or_more",
expression: expression
};
})(r1, r3);
}
if (r0 === null) {
pos = r1;
}
if (r0 === null) {
r0 = parse_primary();
}
}
}
return r0;
}
function parse_primary() {
var r0, r1, r2, r3, r4, r5, r6, r7, r8;
r1 = pos;
r2 = pos;
r3 = parse_identifier();
if (r3 !== null) {
r5 = pos;
reportFailures++;
r6 = pos;
r7 = parse_string();
r7 = r7 !== null ? r7 : "";
if (r7 !== null) {
r8 = parse_equals();
if (r8 !== null) {
r4 = [r7, r8];
} else {
r4 = null;
pos = r6;
}
} else {
r4 = null;
pos = r6;
}
reportFailures--;
if (r4 === null) {
r4 = "";
} else {
r4 = null;
pos = r5;
}
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, name) {
return {
type: "rule_ref",
name: name
};
})(r1, r3);
}
if (r0 === null) {
pos = r1;
}
if (r0 === null) {
r0 = parse_literal();
if (r0 === null) {
r0 = parse_class();
if (r0 === null) {
r1 = pos;
r0 = parse_dot();
if (r0 !== null) {
r0 = (function(offset) { return { type: "any" }; })(r1);
}
if (r0 === null) {
pos = r1;
}
if (r0 === null) {
r1 = pos;
r2 = pos;
r3 = parse_lparen();
if (r3 !== null) {
r4 = parse_choice();
if (r4 !== null) {
r5 = parse_rparen();
if (r5 !== null) {
r0 = [r3, r4, r5];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, expression) { return expression; })(r1, r4);
}
if (r0 === null) {
pos = r1;
}
}
}
}
}
return r0;
}
function parse_action() {
var r0, r1, r2, r3, r4;
reportFailures++;
r1 = pos;
r2 = pos;
r3 = parse_braced();
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, braced) { return braced.substr(1, braced.length - 2); })(r1, r3);
}
if (r0 === null) {
pos = r1;
}
reportFailures--;
if (reportFailures === 0 && r0 === null) {
matchFailed("action");
}
return r0;
}
function parse_braced() {
var r0, r1, r2, r3, r4, r5;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 123) {
r3 = "{";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (r3 !== null) {
r4 = [];
r5 = parse_braced();
if (r5 === null) {
r5 = parse_nonBraceCharacters();
}
while (r5 !== null) {
r4.push(r5);
r5 = parse_braced();
if (r5 === null) {
r5 = parse_nonBraceCharacters();
}
}
if (r4 !== null) {
if (input.charCodeAt(pos) === 125) {
r5 = "}";
pos++;
} else {
r5 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (r5 !== null) {
r0 = [r3, r4, r5];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, parts) {
return "{" + parts.join("") + "}";
})(r1, r4);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_nonBraceCharacters() {
var r0, r1, r2;
r1 = pos;
r2 = parse_nonBraceCharacter();
if (r2 !== null) {
r0 = [];
while (r2 !== null) {
r0.push(r2);
r2 = parse_nonBraceCharacter();
}
} else {
r0 = null;
}
if (r0 !== null) {
r0 = (function(offset, chars) { return chars.join(""); })(r1, r0);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_nonBraceCharacter() {
var r0;
if (/^[^{}]/.test(input.charAt(pos))) {
r0 = input.charAt(pos);
pos++;
} else {
r0 = null;
if (reportFailures === 0) {
matchFailed("[^{}]");
}
}
return r0;
}
function parse_equals() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 61) {
r3 = "=";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"=\"");
}
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return "="; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_colon() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 58) {
r3 = ":";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return ":"; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_semicolon() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 59) {
r3 = ";";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\";\"");
}
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return ";"; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_slash() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 47) {
r3 = "/";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return "/"; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_and() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 38) {
r3 = "&";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"&\"");
}
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return "&"; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_not() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 33) {
r3 = "!";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return "!"; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_question() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 63) {
r3 = "?";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return "?"; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_star() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 42) {
r3 = "*";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return "*"; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_plus() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 43) {
r3 = "+";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return "+"; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_lparen() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 40) {
r3 = "(";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return "("; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_rparen() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 41) {
r3 = ")";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return ")"; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_dot() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 46) {
r3 = ".";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return "."; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_identifier() {
var r0, r1, r2, r3, r4, r5;
reportFailures++;
r1 = pos;
r2 = pos;
r3 = parse_letter();
if (r3 === null) {
if (input.charCodeAt(pos) === 95) {
r3 = "_";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"_\"");
}
}
if (r3 === null) {
if (input.charCodeAt(pos) === 36) {
r3 = "$";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
}
}
if (r3 !== null) {
r4 = [];
r5 = parse_letter();
if (r5 === null) {
r5 = parse_digit();
if (r5 === null) {
if (input.charCodeAt(pos) === 95) {
r5 = "_";
pos++;
} else {
r5 = null;
if (reportFailures === 0) {
matchFailed("\"_\"");
}
}
if (r5 === null) {
if (input.charCodeAt(pos) === 36) {
r5 = "$";
pos++;
} else {
r5 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
}
}
}
while (r5 !== null) {
r4.push(r5);
r5 = parse_letter();
if (r5 === null) {
r5 = parse_digit();
if (r5 === null) {
if (input.charCodeAt(pos) === 95) {
r5 = "_";
pos++;
} else {
r5 = null;
if (reportFailures === 0) {
matchFailed("\"_\"");
}
}
if (r5 === null) {
if (input.charCodeAt(pos) === 36) {
r5 = "$";
pos++;
} else {
r5 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
}
}
}
}
if (r4 !== null) {
r5 = parse___();
if (r5 !== null) {
r0 = [r3, r4, r5];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, head, tail) {
return head + tail.join("");
})(r1, r3, r4);
}
if (r0 === null) {
pos = r1;
}
reportFailures--;
if (reportFailures === 0 && r0 === null) {
matchFailed("identifier");
}
return r0;
}
function parse_literal() {
var r0, r1, r2, r3, r4, r5;
reportFailures++;
r1 = pos;
r2 = pos;
r3 = parse_doubleQuotedString();
if (r3 === null) {
r3 = parse_singleQuotedString();
}
if (r3 !== null) {
if (input.charCodeAt(pos) === 105) {
r4 = "i";
pos++;
} else {
r4 = null;
if (reportFailures === 0) {
matchFailed("\"i\"");
}
}
r4 = r4 !== null ? r4 : "";
if (r4 !== null) {
r5 = parse___();
if (r5 !== null) {
r0 = [r3, r4, r5];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, value, flags) {
return {
type: "literal",
value: value,
ignoreCase: flags === "i"
};
})(r1, r3, r4);
}
if (r0 === null) {
pos = r1;
}
reportFailures--;
if (reportFailures === 0 && r0 === null) {
matchFailed("literal");
}
return r0;
}
function parse_string() {
var r0, r1, r2, r3, r4;
reportFailures++;
r1 = pos;
r2 = pos;
r3 = parse_doubleQuotedString();
if (r3 === null) {
r3 = parse_singleQuotedString();
}
if (r3 !== null) {
r4 = parse___();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, string) { return string; })(r1, r3);
}
if (r0 === null) {
pos = r1;
}
reportFailures--;
if (reportFailures === 0 && r0 === null) {
matchFailed("string");
}
return r0;
}
function parse_doubleQuotedString() {
var r0, r1, r2, r3, r4, r5;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 34) {
r3 = "\"";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (r3 !== null) {
r4 = [];
r5 = parse_doubleQuotedCharacter();
while (r5 !== null) {
r4.push(r5);
r5 = parse_doubleQuotedCharacter();
}
if (r4 !== null) {
if (input.charCodeAt(pos) === 34) {
r5 = "\"";
pos++;
} else {
r5 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (r5 !== null) {
r0 = [r3, r4, r5];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, chars) { return chars.join(""); })(r1, r4);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_doubleQuotedCharacter() {
var r0;
r0 = parse_simpleDoubleQuotedCharacter();
if (r0 === null) {
r0 = parse_simpleEscapeSequence();
if (r0 === null) {
r0 = parse_zeroEscapeSequence();
if (r0 === null) {
r0 = parse_hexEscapeSequence();
if (r0 === null) {
r0 = parse_unicodeEscapeSequence();
if (r0 === null) {
r0 = parse_eolEscapeSequence();
}
}
}
}
}
return r0;
}
function parse_simpleDoubleQuotedCharacter() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
r4 = pos;
reportFailures++;
if (input.charCodeAt(pos) === 34) {
r3 = "\"";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (r3 === null) {
if (input.charCodeAt(pos) === 92) {
r3 = "\\";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (r3 === null) {
r3 = parse_eolChar();
}
}
reportFailures--;
if (r3 === null) {
r3 = "";
} else {
r3 = null;
pos = r4;
}
if (r3 !== null) {
if (input.length > pos) {
r4 = input.charAt(pos);
pos++;
} else {
r4 = null;
if (reportFailures === 0) {
matchFailed("any character");
}
}
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, char_) { return char_; })(r1, r4);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_singleQuotedString() {
var r0, r1, r2, r3, r4, r5;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 39) {
r3 = "'";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"'\"");
}
}
if (r3 !== null) {
r4 = [];
r5 = parse_singleQuotedCharacter();
while (r5 !== null) {
r4.push(r5);
r5 = parse_singleQuotedCharacter();
}
if (r4 !== null) {
if (input.charCodeAt(pos) === 39) {
r5 = "'";
pos++;
} else {
r5 = null;
if (reportFailures === 0) {
matchFailed("\"'\"");
}
}
if (r5 !== null) {
r0 = [r3, r4, r5];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, chars) { return chars.join(""); })(r1, r4);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_singleQuotedCharacter() {
var r0;
r0 = parse_simpleSingleQuotedCharacter();
if (r0 === null) {
r0 = parse_simpleEscapeSequence();
if (r0 === null) {
r0 = parse_zeroEscapeSequence();
if (r0 === null) {
r0 = parse_hexEscapeSequence();
if (r0 === null) {
r0 = parse_unicodeEscapeSequence();
if (r0 === null) {
r0 = parse_eolEscapeSequence();
}
}
}
}
}
return r0;
}
function parse_simpleSingleQuotedCharacter() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
r4 = pos;
reportFailures++;
if (input.charCodeAt(pos) === 39) {
r3 = "'";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"'\"");
}
}
if (r3 === null) {
if (input.charCodeAt(pos) === 92) {
r3 = "\\";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (r3 === null) {
r3 = parse_eolChar();
}
}
reportFailures--;
if (r3 === null) {
r3 = "";
} else {
r3 = null;
pos = r4;
}
if (r3 !== null) {
if (input.length > pos) {
r4 = input.charAt(pos);
pos++;
} else {
r4 = null;
if (reportFailures === 0) {
matchFailed("any character");
}
}
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, char_) { return char_; })(r1, r4);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_class() {
var r0, r1, r2, r3, r4, r5, r6, r7, r8;
reportFailures++;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 91) {
r3 = "[";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (r3 !== null) {
if (input.charCodeAt(pos) === 94) {
r4 = "^";
pos++;
} else {
r4 = null;
if (reportFailures === 0) {
matchFailed("\"^\"");
}
}
r4 = r4 !== null ? r4 : "";
if (r4 !== null) {
r5 = [];
r6 = parse_classCharacterRange();
if (r6 === null) {
r6 = parse_classCharacter();
}
while (r6 !== null) {
r5.push(r6);
r6 = parse_classCharacterRange();
if (r6 === null) {
r6 = parse_classCharacter();
}
}
if (r5 !== null) {
if (input.charCodeAt(pos) === 93) {
r6 = "]";
pos++;
} else {
r6 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (r6 !== null) {
if (input.charCodeAt(pos) === 105) {
r7 = "i";
pos++;
} else {
r7 = null;
if (reportFailures === 0) {
matchFailed("\"i\"");
}
}
r7 = r7 !== null ? r7 : "";
if (r7 !== null) {
r8 = parse___();
if (r8 !== null) {
r0 = [r3, r4, r5, r6, r7, r8];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, inverted, parts, flags) {
var partsConverted = utils.map(parts, function(part) { return part.data; });
var rawText = "["
+ inverted
+ utils.map(parts, function(part) { return part.rawText; }).join("")
+ "]"
+ flags;
return {
type: "class",
parts: partsConverted,
// FIXME: Get the raw text from the input directly.
rawText: rawText,
inverted: inverted === "^",
ignoreCase: flags === "i"
};
})(r1, r4, r5, r7);
}
if (r0 === null) {
pos = r1;
}
reportFailures--;
if (reportFailures === 0 && r0 === null) {
matchFailed("character class");
}
return r0;
}
function parse_classCharacterRange() {
var r0, r1, r2, r3, r4, r5;
r1 = pos;
r2 = pos;
r3 = parse_classCharacter();
if (r3 !== null) {
if (input.charCodeAt(pos) === 45) {
r4 = "-";
pos++;
} else {
r4 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
if (r4 !== null) {
r5 = parse_classCharacter();
if (r5 !== null) {
r0 = [r3, r4, r5];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, begin, end) {
if (begin.data.charCodeAt(0) > end.data.charCodeAt(0)) {
throw new this.SyntaxError(
"Invalid character range: " + begin.rawText + "-" + end.rawText + "."
);
}
return {
data: [begin.data, end.data],
// FIXME: Get the raw text from the input directly.
rawText: begin.rawText + "-" + end.rawText
};
})(r1, r3, r5);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_classCharacter() {
var r0, r1;
r1 = pos;
r0 = parse_bracketDelimitedCharacter();
if (r0 !== null) {
r0 = (function(offset, char_) {
return {
data: char_,
// FIXME: Get the raw text from the input directly.
rawText: utils.quoteForRegexpClass(char_)
};
})(r1, r0);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_bracketDelimitedCharacter() {
var r0;
r0 = parse_simpleBracketDelimitedCharacter();
if (r0 === null) {
r0 = parse_simpleEscapeSequence();
if (r0 === null) {
r0 = parse_zeroEscapeSequence();
if (r0 === null) {
r0 = parse_hexEscapeSequence();
if (r0 === null) {
r0 = parse_unicodeEscapeSequence();
if (r0 === null) {
r0 = parse_eolEscapeSequence();
}
}
}
}
}
return r0;
}
function parse_simpleBracketDelimitedCharacter() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
r4 = pos;
reportFailures++;
if (input.charCodeAt(pos) === 93) {
r3 = "]";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (r3 === null) {
if (input.charCodeAt(pos) === 92) {
r3 = "\\";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (r3 === null) {
r3 = parse_eolChar();
}
}
reportFailures--;
if (r3 === null) {
r3 = "";
} else {
r3 = null;
pos = r4;
}
if (r3 !== null) {
if (input.length > pos) {
r4 = input.charAt(pos);
pos++;
} else {
r4 = null;
if (reportFailures === 0) {
matchFailed("any character");
}
}
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, char_) { return char_; })(r1, r4);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_simpleEscapeSequence() {
var r0, r1, r2, r3, r4, r5;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 92) {
r3 = "\\";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (r3 !== null) {
r5 = pos;
reportFailures++;
r4 = parse_digit();
if (r4 === null) {
if (input.charCodeAt(pos) === 120) {
r4 = "x";
pos++;
} else {
r4 = null;
if (reportFailures === 0) {
matchFailed("\"x\"");
}
}
if (r4 === null) {
if (input.charCodeAt(pos) === 117) {
r4 = "u";
pos++;
} else {
r4 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (r4 === null) {
r4 = parse_eolChar();
}
}
}
reportFailures--;
if (r4 === null) {
r4 = "";
} else {
r4 = null;
pos = r5;
}
if (r4 !== null) {
if (input.length > pos) {
r5 = input.charAt(pos);
pos++;
} else {
r5 = null;
if (reportFailures === 0) {
matchFailed("any character");
}
}
if (r5 !== null) {
r0 = [r3, r4, r5];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, char_) {
return char_
.replace("b", "\b")
.replace("f", "\f")
.replace("n", "\n")
.replace("r", "\r")
.replace("t", "\t")
.replace("v", "\x0B"); // IE does not recognize "\v".
})(r1, r5);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_zeroEscapeSequence() {
var r0, r1, r2, r3, r4, r5;
r1 = pos;
r2 = pos;
if (input.substr(pos, 2) === "\\0") {
r3 = "\\0";
pos += 2;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\0\"");
}
}
if (r3 !== null) {
r5 = pos;
reportFailures++;
r4 = parse_digit();
reportFailures--;
if (r4 === null) {
r4 = "";
} else {
r4 = null;
pos = r5;
}
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset) { return "\x00"; })(r1);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_hexEscapeSequence() {
var r0, r1, r2, r3, r4, r5;
r1 = pos;
r2 = pos;
if (input.substr(pos, 2) === "\\x") {
r3 = "\\x";
pos += 2;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\x\"");
}
}
if (r3 !== null) {
r4 = parse_hexDigit();
if (r4 !== null) {
r5 = parse_hexDigit();
if (r5 !== null) {
r0 = [r3, r4, r5];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, h1, h2) {
return String.fromCharCode(parseInt(h1 + h2, 16));
})(r1, r4, r5);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_unicodeEscapeSequence() {
var r0, r1, r2, r3, r4, r5, r6, r7;
r1 = pos;
r2 = pos;
if (input.substr(pos, 2) === "\\u") {
r3 = "\\u";
pos += 2;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\u\"");
}
}
if (r3 !== null) {
r4 = parse_hexDigit();
if (r4 !== null) {
r5 = parse_hexDigit();
if (r5 !== null) {
r6 = parse_hexDigit();
if (r6 !== null) {
r7 = parse_hexDigit();
if (r7 !== null) {
r0 = [r3, r4, r5, r6, r7];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, h1, h2, h3, h4) {
return String.fromCharCode(parseInt(h1 + h2 + h3 + h4, 16));
})(r1, r4, r5, r6, r7);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_eolEscapeSequence() {
var r0, r1, r2, r3, r4;
r1 = pos;
r2 = pos;
if (input.charCodeAt(pos) === 92) {
r3 = "\\";
pos++;
} else {
r3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (r3 !== null) {
r4 = parse_eol();
if (r4 !== null) {
r0 = [r3, r4];
} else {
r0 = null;
pos = r2;
}
} else {
r0 = null;
pos = r2;
}
if (r0 !== null) {
r0 = (function(offset, eol) { return eol; })(r1, r4);
}
if (r0 === null) {
pos = r1;
}
return r0;
}
function parse_digit() {
var r0;
if (/^[0-9]/.test(input.charAt(pos))) {
r0 = input.charAt(pos);
pos++;
} else {
r0 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
return r0;
}
function parse_hexDigit() {
var r0;
if (/^[0-9a-fA-F]/.test(input.charAt(pos))) {
r0 = input.charAt(pos);
pos++;
} else {
r0 = null;
if (reportFailures === 0) {
matchFailed("[0-9a-fA-F]");
}
}
return r0;
}
function parse_letter() {
var r0;
r0 = parse_lowerCaseLetter();
if (r0 === null) {
r0 = parse_upperCaseLetter();
}
return r0;
}
function parse_lowerCaseLetter() {
var r0;
if (/^[a-z]/.test(input.charAt(pos))) {
r0 = input.charAt(pos);
pos++;
} else {
r0 = null;
if (reportFailures === 0) {
matchFailed("[a-z]");
}
}
return r0;
}
function parse_upperCaseLetter() {
var r0;
if (/^[A-Z]/.test(input.charAt(pos))) {
r0 = input.charAt(pos);
pos++;
} else {
r0 = null;
if (reportFailures === 0) {
matchFailed("[A-Z]");
}
}
return r0;
}
function parse___() {
var r0, r1;
r0 = [];
r1 = parse_whitespace();
if (r1 === null) {
r1 = parse_eol();
if (r1 === null) {
r1 = parse_comment();
}
}
while (r1 !== null) {
r0.push(r1);
r1 = parse_whitespace();
if (r1 === null) {
r1 = parse_eol();
if (r1 === null) {
r1 = parse_comment();
}
}
}
return r0;
}
function parse_comment() {
var r0;
reportFailures++;
r0 = parse_singleLineComment();
if (r0 === null) {
r0 = parse_multiLineComment();
}
reportFailures--;
if (reportFailures === 0 && r0 === null) {
matchFailed("comment");
}
return r0;
}
function parse_singleLineComment() {
var r0, r1, r2, r3, r4, r5, r6, r7;
r1 = pos;
if (input.substr(pos, 2) === "//") {
r2 = "//";
pos += 2;
} else {
r2 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (r2 !== null) {
r3 = [];
r5 = pos;
r7 = pos;
reportFailures++;
r6 = parse_eolChar();
reportFailures--;
if (r6 === null) {
r6 = "";
} else {
r6 = null;
pos = r7;
}
if (r6 !== null) {
if (input.length > pos) {
r7 = input.charAt(pos);
pos++;
} else {
r7 = null;
if (reportFailures === 0) {
matchFailed("any character");
}
}
if (r7 !== null) {
r4 = [r6, r7];
} else {
r4 = null;
pos = r5;
}
} else {
r4 = null;
pos = r5;
}
while (r4 !== null) {
r3.push(r4);
r5 = pos;
r7 = pos;
reportFailures++;
r6 = parse_eolChar();
reportFailures--;
if (r6 === null) {
r6 = "";
} else {
r6 = null;
pos = r7;
}
if (r6 !== null) {
if (input.length > pos) {
r7 = input.charAt(pos);
pos++;
} else {
r7 = null;
if (reportFailures === 0) {
matchFailed("any character");
}
}
if (r7 !== null) {
r4 = [r6, r7];
} else {
r4 = null;
pos = r5;
}
} else {
r4 = null;
pos = r5;
}
}
if (r3 !== null) {
r0 = [r2, r3];
} else {
r0 = null;
pos = r1;
}
} else {
r0 = null;
pos = r1;
}
return r0;
}
function parse_multiLineComment() {
var r0, r1, r2, r3, r4, r5, r6, r7;
r1 = pos;
if (input.substr(pos, 2) === "/*") {
r2 = "/*";
pos += 2;
} else {
r2 = null;
if (reportFailures === 0) {
matchFailed("\"/*\"");
}
}
if (r2 !== null) {
r3 = [];
r5 = pos;
r7 = pos;
reportFailures++;
if (input.substr(pos, 2) === "*/") {
r6 = "*/";
pos += 2;
} else {
r6 = null;
if (reportFailures === 0) {
matchFailed("\"*/\"");
}
}
reportFailures--;
if (r6 === null) {
r6 = "";
} else {
r6 = null;
pos = r7;
}
if (r6 !== null) {
if (input.length > pos) {
r7 = input.charAt(pos);
pos++;
} else {
r7 = null;
if (reportFailures === 0) {
matchFailed("any character");
}
}
if (r7 !== null) {
r4 = [r6, r7];
} else {
r4 = null;
pos = r5;
}
} else {
r4 = null;
pos = r5;
}
while (r4 !== null) {
r3.push(r4);
r5 = pos;
r7 = pos;
reportFailures++;
if (input.substr(pos, 2) === "*/") {
r6 = "*/";
pos += 2;
} else {
r6 = null;
if (reportFailures === 0) {
matchFailed("\"*/\"");
}
}
reportFailures--;
if (r6 === null) {
r6 = "";
} else {
r6 = null;
pos = r7;
}
if (r6 !== null) {
if (input.length > pos) {
r7 = input.charAt(pos);
pos++;
} else {
r7 = null;
if (reportFailures === 0) {
matchFailed("any character");
}
}
if (r7 !== null) {
r4 = [r6, r7];
} else {
r4 = null;
pos = r5;
}
} else {
r4 = null;
pos = r5;
}
}
if (r3 !== null) {
if (input.substr(pos, 2) === "*/") {
r4 = "*/";
pos += 2;
} else {
r4 = null;
if (reportFailures === 0) {
matchFailed("\"*/\"");
}
}
if (r4 !== null) {
r0 = [r2, r3, r4];
} else {
r0 = null;
pos = r1;
}
} else {
r0 = null;
pos = r1;
}
} else {
r0 = null;
pos = r1;
}
return r0;
}
function parse_eol() {
var r0;
reportFailures++;
if (input.charCodeAt(pos) === 10) {
r0 = "\n";
pos++;
} else {
r0 = null;
if (reportFailures === 0) {
matchFailed("\"\\n\"");
}
}
if (r0 === null) {
if (input.substr(pos, 2) === "\r\n") {
r0 = "\r\n";
pos += 2;
} else {
r0 = null;
if (reportFailures === 0) {
matchFailed("\"\\r\\n\"");
}
}
if (r0 === null) {
if (input.charCodeAt(pos) === 13) {
r0 = "\r";
pos++;
} else {
r0 = null;
if (reportFailures === 0) {
matchFailed("\"\\r\"");
}
}
if (r0 === null) {
if (input.charCodeAt(pos) === 8232) {
r0 = "\u2028";
pos++;
} else {
r0 = null;
if (reportFailures === 0) {
matchFailed("\"\\u2028\"");
}
}
if (r0 === null) {
if (input.charCodeAt(pos) === 8233) {
r0 = "\u2029";
pos++;
} else {
r0 = null;
if (reportFailures === 0) {
matchFailed("\"\\u2029\"");
}
}
}
}
}
}
reportFailures--;
if (reportFailures === 0 && r0 === null) {
matchFailed("end of line");
}
return r0;
}
function parse_eolChar() {
var r0;
if (/^[\n\r\u2028\u2029]/.test(input.charAt(pos))) {
r0 = input.charAt(pos);
pos++;
} else {
r0 = null;
if (reportFailures === 0) {
matchFailed("[\\n\\r\\u2028\\u2029]");
}
}
return r0;
}
function parse_whitespace() {
var r0;
reportFailures++;
if (/^[ \t\x0B\f\xA0\uFEFF\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]/.test(input.charAt(pos))) {
r0 = input.charAt(pos);
pos++;
} else {
r0 = null;
if (reportFailures === 0) {
matchFailed("[ \\t\\x0B\\f\\xA0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]");
}
}
reportFailures--;
if (reportFailures === 0 && r0 === null) {
matchFailed("whitespace");
}
return r0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
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 < Math.max(pos, rightmostFailuresPos); 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 utils = require("./utils");
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(
cleanupExpected(rightmostFailuresExpected),
found,
offset,
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(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ")
+ " or "
+ expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
};
subclass(result.SyntaxError, Error);
return result;
})();