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.
2996 lines
73 KiB
JavaScript
2996 lines
73 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 reportedPos = 0;
|
|
var cachedReportedPos = 0;
|
|
var cachedReportedPosDetails = { line: 1, column: 1, seenCR: false };
|
|
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 computeReportedPosDetails() {
|
|
function advanceCachedReportedPos() {
|
|
var ch;
|
|
|
|
for (; cachedReportedPos < reportedPos; cachedReportedPos++) {
|
|
ch = input.charAt(cachedReportedPos);
|
|
if (ch === "\n") {
|
|
if (!cachedReportedPosDetails.seenCR) { cachedReportedPosDetails.line++; }
|
|
cachedReportedPosDetails.column = 1;
|
|
cachedReportedPosDetails.seenCR = false;
|
|
} else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
|
|
cachedReportedPosDetails.line++;
|
|
cachedReportedPosDetails.column = 1;
|
|
cachedReportedPosDetails.seenCR = true;
|
|
} else {
|
|
cachedReportedPosDetails.column++;
|
|
cachedReportedPosDetails.seenCR = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (cachedReportedPos !== reportedPos) {
|
|
if (cachedReportedPos > reportedPos) {
|
|
cachedReportedPos = 0;
|
|
cachedReportedPosDetails = { line: 1, column: 1, seenCR: false };
|
|
}
|
|
advanceCachedReportedPos();
|
|
}
|
|
|
|
return cachedReportedPosDetails;
|
|
}
|
|
|
|
function offset() {
|
|
return reportedPos;
|
|
}
|
|
|
|
function line() {
|
|
return computeReportedPosDetails().line;
|
|
}
|
|
|
|
function column() {
|
|
return computeReportedPosDetails().column;
|
|
}
|
|
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function(initializer, rules) {
|
|
return {
|
|
type: "grammar",
|
|
initializer: initializer !== "" ? initializer : null,
|
|
rules: rules,
|
|
startRule: rules[0].name
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(code) {
|
|
return {
|
|
type: "initializer",
|
|
code: code
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(name, displayName, expression) {
|
|
return {
|
|
type: "rule",
|
|
name: name,
|
|
expression: displayName !== ""
|
|
? {
|
|
type: "named",
|
|
name: displayName,
|
|
expression: expression
|
|
}
|
|
: expression
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(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;
|
|
}
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(elements, code) {
|
|
var expression = elements.length !== 1
|
|
? {
|
|
type: "sequence",
|
|
elements: elements
|
|
}
|
|
: elements[0];
|
|
return {
|
|
type: "action",
|
|
expression: expression,
|
|
code: code
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(elements) {
|
|
return elements.length !== 1
|
|
? {
|
|
type: "sequence",
|
|
elements: elements
|
|
}
|
|
: elements[0];
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(label, expression) {
|
|
return {
|
|
type: "labeled",
|
|
label: label,
|
|
expression: expression
|
|
};
|
|
})(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_dollar();
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function(expression) {
|
|
return {
|
|
type: "text",
|
|
expression: expression
|
|
};
|
|
})(r4);
|
|
}
|
|
if (r0 === null) {
|
|
pos = r1;
|
|
}
|
|
if (r0 === null) {
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function(code) {
|
|
return {
|
|
type: "semantic_and",
|
|
code: code
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(expression) {
|
|
return {
|
|
type: "simple_and",
|
|
expression: expression
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(code) {
|
|
return {
|
|
type: "semantic_not",
|
|
code: code
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(expression) {
|
|
return {
|
|
type: "simple_not",
|
|
expression: expression
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(expression) {
|
|
return {
|
|
type: "optional",
|
|
expression: expression
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(expression) {
|
|
return {
|
|
type: "zero_or_more",
|
|
expression: expression
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(expression) {
|
|
return {
|
|
type: "one_or_more",
|
|
expression: expression
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(name) {
|
|
return {
|
|
type: "rule_ref",
|
|
name: name
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return { type: "any" }; })();
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function(expression) { return expression; })(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(braced) { return braced.substr(1, braced.length - 2); })(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 = input.substring(pos, r1);
|
|
}
|
|
return r0;
|
|
}
|
|
|
|
function parse_nonBraceCharacters() {
|
|
var r0, r1;
|
|
|
|
r1 = parse_nonBraceCharacter();
|
|
if (r1 !== null) {
|
|
r0 = [];
|
|
while (r1 !== null) {
|
|
r0.push(r1);
|
|
r1 = parse_nonBraceCharacter();
|
|
}
|
|
} else {
|
|
r0 = null;
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return "="; })();
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return ":"; })();
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return ";"; })();
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return "/"; })();
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return "&"; })();
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return "!"; })();
|
|
}
|
|
if (r0 === null) {
|
|
pos = r1;
|
|
}
|
|
return r0;
|
|
}
|
|
|
|
function parse_dollar() {
|
|
var r0, r1, r2, r3, r4;
|
|
|
|
r1 = pos;
|
|
r2 = pos;
|
|
if (input.charCodeAt(pos) === 36) {
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return "$"; })();
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return "?"; })();
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return "*"; })();
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return "+"; })();
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return "("; })();
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return ")"; })();
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return "."; })();
|
|
}
|
|
if (r0 === null) {
|
|
pos = r1;
|
|
}
|
|
return r0;
|
|
}
|
|
|
|
function parse_identifier() {
|
|
var r0, r1, r2, r3, r4, r5, r6, r7, r8;
|
|
|
|
reportFailures++;
|
|
r1 = pos;
|
|
r2 = pos;
|
|
r4 = pos;
|
|
r5 = pos;
|
|
r6 = parse_letter();
|
|
if (r6 === null) {
|
|
if (input.charCodeAt(pos) === 95) {
|
|
r6 = "_";
|
|
pos++;
|
|
} else {
|
|
r6 = null;
|
|
if (reportFailures === 0) {
|
|
matchFailed("\"_\"");
|
|
}
|
|
}
|
|
}
|
|
if (r6 !== null) {
|
|
r7 = [];
|
|
r8 = parse_letter();
|
|
if (r8 === null) {
|
|
r8 = parse_digit();
|
|
if (r8 === null) {
|
|
if (input.charCodeAt(pos) === 95) {
|
|
r8 = "_";
|
|
pos++;
|
|
} else {
|
|
r8 = null;
|
|
if (reportFailures === 0) {
|
|
matchFailed("\"_\"");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
while (r8 !== null) {
|
|
r7.push(r8);
|
|
r8 = parse_letter();
|
|
if (r8 === null) {
|
|
r8 = parse_digit();
|
|
if (r8 === null) {
|
|
if (input.charCodeAt(pos) === 95) {
|
|
r8 = "_";
|
|
pos++;
|
|
} else {
|
|
r8 = null;
|
|
if (reportFailures === 0) {
|
|
matchFailed("\"_\"");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (r7 !== null) {
|
|
r3 = [r6, r7];
|
|
} else {
|
|
r3 = null;
|
|
pos = r5;
|
|
}
|
|
} else {
|
|
r3 = null;
|
|
pos = r5;
|
|
}
|
|
if (r3 !== null) {
|
|
r3 = input.substring(pos, r4);
|
|
}
|
|
if (r3 !== null) {
|
|
r4 = parse___();
|
|
if (r4 !== null) {
|
|
r0 = [r3, r4];
|
|
} else {
|
|
r0 = null;
|
|
pos = r2;
|
|
}
|
|
} else {
|
|
r0 = null;
|
|
pos = r2;
|
|
}
|
|
if (r0 !== null) {
|
|
reportedPos = r1;
|
|
r0 = (function(chars) { return chars; })(r3);
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function(value, flags) {
|
|
return {
|
|
type: "literal",
|
|
value: value,
|
|
ignoreCase: flags === "i"
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(string) { return string; })(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(chars) { return chars.join(""); })(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(char_) { return char_; })(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(chars) { return chars.join(""); })(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(char_) { return char_; })(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(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"
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(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
|
|
};
|
|
})(r3, r5);
|
|
}
|
|
if (r0 === null) {
|
|
pos = r1;
|
|
}
|
|
return r0;
|
|
}
|
|
|
|
function parse_classCharacter() {
|
|
var r0, r1;
|
|
|
|
r1 = pos;
|
|
r0 = parse_bracketDelimitedCharacter();
|
|
if (r0 !== null) {
|
|
reportedPos = r1;
|
|
r0 = (function(char_) {
|
|
return {
|
|
data: char_,
|
|
// FIXME: Get the raw text from the input directly.
|
|
rawText: utils.quoteForRegexpClass(char_)
|
|
};
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(char_) { return char_; })(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) {
|
|
reportedPos = r1;
|
|
r0 = (function(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".
|
|
})(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) {
|
|
reportedPos = r1;
|
|
r0 = (function() { return "\x00"; })();
|
|
}
|
|
if (r0 === null) {
|
|
pos = r1;
|
|
}
|
|
return r0;
|
|
}
|
|
|
|
function parse_hexEscapeSequence() {
|
|
var r0, r1, r2, r3, r4, r5, r6, r7, r8;
|
|
|
|
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) {
|
|
r5 = pos;
|
|
r6 = pos;
|
|
r7 = parse_hexDigit();
|
|
if (r7 !== null) {
|
|
r8 = parse_hexDigit();
|
|
if (r8 !== null) {
|
|
r4 = [r7, r8];
|
|
} else {
|
|
r4 = null;
|
|
pos = r6;
|
|
}
|
|
} else {
|
|
r4 = null;
|
|
pos = r6;
|
|
}
|
|
if (r4 !== null) {
|
|
r4 = input.substring(pos, r5);
|
|
}
|
|
if (r4 !== null) {
|
|
r0 = [r3, r4];
|
|
} else {
|
|
r0 = null;
|
|
pos = r2;
|
|
}
|
|
} else {
|
|
r0 = null;
|
|
pos = r2;
|
|
}
|
|
if (r0 !== null) {
|
|
reportedPos = r1;
|
|
r0 = (function(digits) {
|
|
return String.fromCharCode(parseInt(digits, 16));
|
|
})(r4);
|
|
}
|
|
if (r0 === null) {
|
|
pos = r1;
|
|
}
|
|
return r0;
|
|
}
|
|
|
|
function parse_unicodeEscapeSequence() {
|
|
var r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10;
|
|
|
|
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) {
|
|
r5 = pos;
|
|
r6 = pos;
|
|
r7 = parse_hexDigit();
|
|
if (r7 !== null) {
|
|
r8 = parse_hexDigit();
|
|
if (r8 !== null) {
|
|
r9 = parse_hexDigit();
|
|
if (r9 !== null) {
|
|
r10 = parse_hexDigit();
|
|
if (r10 !== null) {
|
|
r4 = [r7, r8, r9, r10];
|
|
} else {
|
|
r4 = null;
|
|
pos = r6;
|
|
}
|
|
} else {
|
|
r4 = null;
|
|
pos = r6;
|
|
}
|
|
} else {
|
|
r4 = null;
|
|
pos = r6;
|
|
}
|
|
} else {
|
|
r4 = null;
|
|
pos = r6;
|
|
}
|
|
if (r4 !== null) {
|
|
r4 = input.substring(pos, r5);
|
|
}
|
|
if (r4 !== null) {
|
|
r0 = [r3, r4];
|
|
} else {
|
|
r0 = null;
|
|
pos = r2;
|
|
}
|
|
} else {
|
|
r0 = null;
|
|
pos = r2;
|
|
}
|
|
if (r0 !== null) {
|
|
reportedPos = r1;
|
|
r0 = (function(digits) {
|
|
return String.fromCharCode(parseInt(digits, 16));
|
|
})(r4);
|
|
}
|
|
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) {
|
|
reportedPos = r1;
|
|
r0 = (function(eol) { return eol; })(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;
|
|
}
|
|
|
|
|
|
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) {
|
|
reportedPos = Math.max(pos, rightmostFailuresPos);
|
|
var found = reportedPos < input.length ? input.charAt(reportedPos) : null;
|
|
var reportedPosDetails = computeReportedPosDetails();
|
|
|
|
throw new this.SyntaxError(
|
|
cleanupExpected(rightmostFailuresExpected),
|
|
found,
|
|
reportedPos,
|
|
reportedPosDetails.line,
|
|
reportedPosDetails.column
|
|
);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
};
|
|
|
|
/* 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;
|
|
})();
|