ng-tql
Version:
A domain specific language that extends SQL and allows visual metaprogramming
1,801 lines (1,668 loc) • 52.7 kB
JavaScript
module.exports = (function() {
"use strict";
/*
* Generated by PEG.js 0.9.0.
*
* http://pegjs.org/
*/
function peg$subclass(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor();
}
function peg$SyntaxError(message, expected, found, location) {
this.message = message;
this.expected = expected;
this.found = found;
this.location = location;
this.name = "SyntaxError";
if (typeof Error.captureStackTrace === "function") {
Error.captureStackTrace(this, peg$SyntaxError);
}
}
peg$subclass(peg$SyntaxError, Error);
function peg$parse(input) {
var options = arguments.length > 1 ? arguments[1] : {},
parser = this,
peg$FAILED = {},
peg$startRuleFunctions = { Start: peg$parseStart },
peg$startRuleFunction = peg$parseStart,
peg$c0 = { type: "other", description: "template" },
peg$c1 = function(f, t) { return t; },
peg$c2 = function(f, t, d, ds, b, p) {
var expect, currentType;
var needsCheck = true;
var is = function(x) { return x !== null; };
// Type inference implementation
if (!is(t) && is(d)) {
/**
* When no expectations, but value defined, expectations become of the
* type of the defined value.
* Infer EXPECTED on VALUE.
*/
currentType = typeof d;
expect = typeof d;
} else if (is(t) && is(d)) {
/**
* When there are expectations and a value, type check them.
*/
currentType = typeof d;
expect = t;
} else if (!is(t) && !is(d)) {
/**
* When no value and no typecheck, auto-infer string.
*/
expect = "string";
needsCheck = false;
// Auto-infer
} else if (is(t) && !is(d)) {
/**
* When expectations, but no value, set the expectations and skip the
* type check.
*/
expect = t;
needsCheck = false;
}
needsCheck && TypeChecker.assert(expect, currentType);
return {
field: f,
type: expect,
default: d,
base: b || "_",
describe: ds || "",
picture: p || ""
};
},
peg$c3 = { type: "other", description: "field declaration" },
peg$c4 = "@",
peg$c5 = { type: "literal", value: "@", description: "\"@\"" },
peg$c6 = function(name) {
return name.value;
},
peg$c7 = { type: "other", description: "type declaration" },
peg$c8 = function(t) {
return t;
},
peg$c9 = { type: "other", description: "type" },
peg$c10 = function() { return "number"; },
peg$c11 = function() { return "string"; },
peg$c12 = function() { return "object"; },
peg$c13 = { type: "other", description: "default value" },
peg$c14 = function(e) {
return e;
},
peg$c15 = { type: "other", description: "describe value" },
peg$c16 = { type: "other", description: "base value" },
peg$c17 = { type: "other", description: "picture" },
peg$c18 = function(s) {
return s;
},
peg$c19 = { type: "other", description: "expression" },
peg$c20 = { type: "other", description: "number" },
peg$c21 = "+",
peg$c22 = { type: "literal", value: "+", description: "\"+\"" },
peg$c23 = "-",
peg$c24 = { type: "literal", value: "-", description: "\"-\"" },
peg$c25 = /^[0-9]/,
peg$c26 = { type: "class", value: "[0-9]", description: "[0-9]" },
peg$c27 = ".",
peg$c28 = { type: "literal", value: ".", description: "\".\"" },
peg$c29 = function(m, x, xs) { return xs; },
peg$c30 = function(m, x, xs) {
var op = m || "";
return xs
? parseFloat(op + x.join("") + "." + xs.join(""))
: parseInt(op + x.join(""));
},
peg$c31 = { type: "other", description: "string" },
peg$c32 = "\"\"",
peg$c33 = { type: "literal", value: "\"\"", description: "\"\\\"\\\"\"" },
peg$c34 = function() {
return "";
},
peg$c35 = "\"",
peg$c36 = { type: "literal", value: "\"", description: "\"\\\"\"" },
peg$c37 = function(str, last) {
var r = "";
for (var c in str) {
r += str[c][1];
}
return r + last;
},
peg$c38 = { type: "other", description: "date" },
peg$c39 = "#",
peg$c40 = { type: "literal", value: "#", description: "\"#\"" },
peg$c41 = "/",
peg$c42 = { type: "literal", value: "/", description: "\"/\"" },
peg$c43 = function(year, month, day, time) {
var record = function(n) {
return parseInt(n.join(""));
};
return time
? new Date(record(year), record(month) - 1, record(day), time.hour, time.minute, time.second)
: new Date(record(year), record(month) - 1, record(day));
},
peg$c44 = { type: "other", description: "time" },
peg$c45 = ":",
peg$c46 = { type: "literal", value: ":", description: "\":\"" },
peg$c47 = function(hour, minute, second) {
var record = function(n) {
return parseInt(n.join(""));
};
return {
hour: record(hour),
minute: record(minute),
second: record(second)
};
},
peg$c48 = /^[^\\]/,
peg$c49 = { type: "class", value: "[^\\\\]", description: "[^\\\\]" },
peg$c50 = function(last) { return last; },
peg$c51 = { type: "any", description: "any character" },
peg$c52 = { type: "other", description: "keyword" },
peg$c53 = { type: "other", description: "as" },
peg$c54 = "as",
peg$c55 = { type: "literal", value: "as", description: "\"as\"" },
peg$c56 = { type: "other", description: "base" },
peg$c57 = "base",
peg$c58 = { type: "literal", value: "base", description: "\"base\"" },
peg$c59 = { type: "other", description: "default" },
peg$c60 = "default",
peg$c61 = { type: "literal", value: "default", description: "\"default\"" },
peg$c62 = { type: "other", description: "describe" },
peg$c63 = "describe",
peg$c64 = { type: "literal", value: "describe", description: "\"describe\"" },
peg$c65 = "picture",
peg$c66 = { type: "literal", value: "picture", description: "\"picture\"" },
peg$c67 = { type: "other", description: "number type" },
peg$c68 = "number",
peg$c69 = { type: "literal", value: "number", description: "\"number\"" },
peg$c70 = { type: "other", description: "string type" },
peg$c71 = "string",
peg$c72 = { type: "literal", value: "string", description: "\"string\"" },
peg$c73 = { type: "other", description: "date type" },
peg$c74 = "date",
peg$c75 = { type: "literal", value: "date", description: "\"date\"" },
peg$c76 = { type: "other", description: "identifier" },
peg$c77 = function(name) {
return name;
},
peg$c78 = function(x, xs) {
return {
type: "Identifier",
value: [x].concat(xs).join("")
};
},
peg$c79 = /^[a-zA-Z-\xFF]/,
peg$c80 = { type: "class", value: "[a-zA-Z_\\x7f-\\xff]", description: "[a-zA-Z_\\x7f-\\xff]" },
peg$c81 = /^[a-zA-Z0-9-\xFF]/,
peg$c82 = { type: "class", value: "[a-zA-Z0-9_\\x7f-\\xff]", description: "[a-zA-Z0-9_\\x7f-\\xff]" },
peg$c83 = { type: "other", description: "optional whitespace" },
peg$c84 = /^[ \t]/,
peg$c85 = { type: "class", value: "[ \\t]", description: "[ \\t]" },
peg$c86 = { type: "other", description: "mandatory whitespace" },
peg$currPos = 0,
peg$savedPos = 0,
peg$posDetailsCache = [{ line: 1, column: 1, seenCR: false }],
peg$maxFailPos = 0,
peg$maxFailExpected = [],
peg$silentFails = 0,
peg$result;
if ("startRule" in options) {
if (!(options.startRule in peg$startRuleFunctions)) {
throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
}
peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
}
function text() {
return input.substring(peg$savedPos, peg$currPos);
}
function location() {
return peg$computeLocation(peg$savedPos, peg$currPos);
}
function expected(description) {
throw peg$buildException(
null,
[{ type: "other", description: description }],
input.substring(peg$savedPos, peg$currPos),
peg$computeLocation(peg$savedPos, peg$currPos)
);
}
function error(message) {
throw peg$buildException(
message,
null,
input.substring(peg$savedPos, peg$currPos),
peg$computeLocation(peg$savedPos, peg$currPos)
);
}
function peg$computePosDetails(pos) {
var details = peg$posDetailsCache[pos],
p, ch;
if (details) {
return details;
} else {
p = pos - 1;
while (!peg$posDetailsCache[p]) {
p--;
}
details = peg$posDetailsCache[p];
details = {
line: details.line,
column: details.column,
seenCR: details.seenCR
};
while (p < pos) {
ch = input.charAt(p);
if (ch === "\n") {
if (!details.seenCR) { details.line++; }
details.column = 1;
details.seenCR = false;
} else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
details.line++;
details.column = 1;
details.seenCR = true;
} else {
details.column++;
details.seenCR = false;
}
p++;
}
peg$posDetailsCache[pos] = details;
return details;
}
}
function peg$computeLocation(startPos, endPos) {
var startPosDetails = peg$computePosDetails(startPos),
endPosDetails = peg$computePosDetails(endPos);
return {
start: {
offset: startPos,
line: startPosDetails.line,
column: startPosDetails.column
},
end: {
offset: endPos,
line: endPosDetails.line,
column: endPosDetails.column
}
};
}
function peg$fail(expected) {
if (peg$currPos < peg$maxFailPos) { return; }
if (peg$currPos > peg$maxFailPos) {
peg$maxFailPos = peg$currPos;
peg$maxFailExpected = [];
}
peg$maxFailExpected.push(expected);
}
function peg$buildException(message, expected, found, location) {
function cleanupExpected(expected) {
var i = 1;
expected.sort(function(a, b) {
if (a.description < b.description) {
return -1;
} else if (a.description > b.description) {
return 1;
} else {
return 0;
}
});
while (i < expected.length) {
if (expected[i - 1] === expected[i]) {
expected.splice(i, 1);
} else {
i++;
}
}
}
function buildMessage(expected, found) {
function stringEscape(s) {
function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
return s
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\x08/g, '\\b')
.replace(/\t/g, '\\t')
.replace(/\n/g, '\\n')
.replace(/\f/g, '\\f')
.replace(/\r/g, '\\r')
.replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
.replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); })
.replace(/[\u0100-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); })
.replace(/[\u1000-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); });
}
var expectedDescs = new Array(expected.length),
expectedDesc, foundDesc, i;
for (i = 0; i < expected.length; i++) {
expectedDescs[i] = expected[i].description;
}
expectedDesc = expected.length > 1
? expectedDescs.slice(0, -1).join(", ")
+ " or "
+ expectedDescs[expected.length - 1]
: expectedDescs[0];
foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";
return "Expected " + expectedDesc + " but " + foundDesc + " found.";
}
if (expected !== null) {
cleanupExpected(expected);
}
return new peg$SyntaxError(
message !== null ? message : buildMessage(expected, found),
expected,
found,
location
);
}
function peg$parseStart() {
var s0;
s0 = peg$parseTemplate();
return s0;
}
function peg$parseTemplate() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$parseFieldDecl();
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
s3 = peg$parse__();
if (s3 !== peg$FAILED) {
s4 = peg$parseType();
if (s4 !== peg$FAILED) {
peg$savedPos = s2;
s3 = peg$c1(s1, s4);
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 === peg$FAILED) {
s2 = null;
}
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
s4 = peg$parseDefaultValue();
if (s4 === peg$FAILED) {
s4 = null;
}
if (s4 !== peg$FAILED) {
s5 = peg$parse_();
if (s5 !== peg$FAILED) {
s6 = peg$parseDescribe();
if (s6 === peg$FAILED) {
s6 = null;
}
if (s6 !== peg$FAILED) {
s7 = peg$parse_();
if (s7 !== peg$FAILED) {
s8 = peg$parseBaseValue();
if (s8 === peg$FAILED) {
s8 = null;
}
if (s8 !== peg$FAILED) {
s9 = peg$parse_();
if (s9 !== peg$FAILED) {
s10 = peg$parsePicture();
if (s10 === peg$FAILED) {
s10 = null;
}
if (s10 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c2(s1, s2, s4, s6, s8, s10);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c0); }
}
return s0;
}
function peg$parseFieldDecl() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 64) {
s1 = peg$c4;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c5); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parseIdentifier();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c3); }
}
return s0;
}
function peg$parseType() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$parseAsToken();
if (s1 !== peg$FAILED) {
s2 = peg$parse__();
if (s2 !== peg$FAILED) {
s3 = peg$parseSupportedType();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c8(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c7); }
}
return s0;
}
function peg$parseSupportedType() {
var s0, s1;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$parseNumberType();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c10();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseStringType();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c11();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseDateType();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c12();
}
s0 = s1;
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c9); }
}
return s0;
}
function peg$parseDefaultValue() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$parseDefaultToken();
if (s1 !== peg$FAILED) {
s2 = peg$parse__();
if (s2 !== peg$FAILED) {
s3 = peg$parseExpr();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c14(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c13); }
}
return s0;
}
function peg$parseDescribe() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$parseDescribeToken();
if (s1 !== peg$FAILED) {
s2 = peg$parse__();
if (s2 !== peg$FAILED) {
s3 = peg$parseString();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c14(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c15); }
}
return s0;
}
function peg$parseBaseValue() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$parseBaseToken();
if (s1 !== peg$FAILED) {
s2 = peg$parse__();
if (s2 !== peg$FAILED) {
s3 = peg$parseExpr();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c14(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c16); }
}
return s0;
}
function peg$parsePicture() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$parsePictureToken();
if (s1 !== peg$FAILED) {
s2 = peg$parse__();
if (s2 !== peg$FAILED) {
s3 = peg$parseString();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c18(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c17); }
}
return s0;
}
function peg$parseExpr() {
var s0, s1;
peg$silentFails++;
s0 = peg$parseNumber();
if (s0 === peg$FAILED) {
s0 = peg$parseString();
if (s0 === peg$FAILED) {
s0 = peg$parseDate();
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c19); }
}
return s0;
}
function peg$parseNumber() {
var s0, s1, s2, s3, s4, s5, s6;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 43) {
s1 = peg$c21;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c22); }
}
if (s1 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 45) {
s1 = peg$c23;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c24); }
}
}
if (s1 === peg$FAILED) {
s1 = null;
}
if (s1 !== peg$FAILED) {
s2 = [];
if (peg$c25.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
if (peg$c25.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
}
} else {
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 46) {
s4 = peg$c27;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c28); }
}
if (s4 !== peg$FAILED) {
s5 = [];
if (peg$c25.test(input.charAt(peg$currPos))) {
s6 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
if (s6 !== peg$FAILED) {
while (s6 !== peg$FAILED) {
s5.push(s6);
if (peg$c25.test(input.charAt(peg$currPos))) {
s6 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
}
} else {
s5 = peg$FAILED;
}
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c29(s1, s2, s5);
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 === peg$FAILED) {
s3 = null;
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c30(s1, s2, s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c20); }
}
return s0;
}
function peg$parseString() {
var s0, s1, s2, s3, s4, s5;
peg$silentFails++;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c32) {
s1 = peg$c32;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c33); }
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c34();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 34) {
s1 = peg$c35;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c36); }
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
s5 = peg$parseUnescapedQuote();
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = void 0;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
s5 = peg$parseAnyChar();
if (s5 !== peg$FAILED) {
s4 = [s4, s5];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
s5 = peg$parseUnescapedQuote();
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = void 0;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
s5 = peg$parseAnyChar();
if (s5 !== peg$FAILED) {
s4 = [s4, s5];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
}
if (s2 !== peg$FAILED) {
s3 = peg$parseUnescapedQuote();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c37(s2, s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c31); }
}
return s0;
}
function peg$parseDate() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 35) {
s1 = peg$c39;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c40); }
}
if (s1 !== peg$FAILED) {
s2 = [];
if (peg$c25.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
if (peg$c25.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
}
} else {
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 47) {
s3 = peg$c41;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c42); }
}
if (s3 !== peg$FAILED) {
s4 = [];
if (peg$c25.test(input.charAt(peg$currPos))) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
if (s5 !== peg$FAILED) {
while (s5 !== peg$FAILED) {
s4.push(s5);
if (peg$c25.test(input.charAt(peg$currPos))) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
}
} else {
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 47) {
s5 = peg$c41;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c42); }
}
if (s5 !== peg$FAILED) {
s6 = [];
if (peg$c25.test(input.charAt(peg$currPos))) {
s7 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
if (s7 !== peg$FAILED) {
while (s7 !== peg$FAILED) {
s6.push(s7);
if (peg$c25.test(input.charAt(peg$currPos))) {
s7 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
}
} else {
s6 = peg$FAILED;
}
if (s6 !== peg$FAILED) {
s7 = peg$parse_();
if (s7 !== peg$FAILED) {
s8 = peg$parseTime();
if (s8 === peg$FAILED) {
s8 = null;
}
if (s8 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c43(s2, s4, s6, s8);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c38); }
}
return s0;
}
function peg$parseTime() {
var s0, s1, s2, s3, s4, s5, s6, s7;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 35) {
s1 = peg$c39;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c40); }
}
if (s1 !== peg$FAILED) {
s2 = [];
if (peg$c25.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
if (peg$c25.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
}
} else {
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 58) {
s3 = peg$c45;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c46); }
}
if (s3 !== peg$FAILED) {
s4 = [];
if (peg$c25.test(input.charAt(peg$currPos))) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
if (s5 !== peg$FAILED) {
while (s5 !== peg$FAILED) {
s4.push(s5);
if (peg$c25.test(input.charAt(peg$currPos))) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
}
} else {
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 58) {
s5 = peg$c45;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c46); }
}
if (s5 !== peg$FAILED) {
s6 = [];
if (peg$c25.test(input.charAt(peg$currPos))) {
s7 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
if (s7 !== peg$FAILED) {
while (s7 !== peg$FAILED) {
s6.push(s7);
if (peg$c25.test(input.charAt(peg$currPos))) {
s7 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
}
} else {
s6 = peg$FAILED;
}
if (s6 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c47(s2, s4, s6);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c44); }
}
return s0;
}
function peg$parseUnescapedQuote() {
var s0, s1, s2;
s0 = peg$currPos;
if (peg$c48.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c49); }
}
if (s1 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 34) {
s2 = peg$c35;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c36); }
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c50(s1);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseAnyChar() {
var s0;
if (input.length > peg$currPos) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c51); }
}
return s0;
}
function peg$parseKeyword() {
var s0, s1;
peg$silentFails++;
s0 = peg$parseAsToken();
if (s0 === peg$FAILED) {
s0 = peg$parseBaseToken();
if (s0 === peg$FAILED) {
s0 = peg$parseDefaultToken();
if (s0 === peg$FAILED) {
s0 = peg$parseDescribeToken();
}
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c52); }
}
return s0;
}
function peg$parseAsToken() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2).toLowerCase() === peg$c54) {
s1 = input.substr(peg$currPos, 2);
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c55); }
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$parseIdentRest();
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = void 0;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c53); }
}
return s0;
}
function peg$parseBaseToken() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
if (input.substr(peg$currPos, 4).toLowerCase() === peg$c57) {
s1 = input.substr(peg$currPos, 4);
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c58); }
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$parseIdentRest();
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = void 0;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c56); }
}
return s0;
}
function peg$parseDefaultToken() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
if (input.substr(peg$currPos, 7).toLowerCase() === peg$c60) {
s1 = input.substr(peg$currPos, 7);
peg$currPos += 7;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c61); }
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$parseIdentRest();
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = void 0;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c59); }
}
return s0;
}
function peg$parseDescribeToken() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
if (input.substr(peg$currPos, 8).toLowerCase() === peg$c63) {
s1 = input.substr(peg$currPos, 8);
peg$currPos += 8;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c64); }
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$parseIdentRest();
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = void 0;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c62); }
}
return s0;
}
function peg$parsePictureToken() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
if (input.substr(peg$currPos, 7).toLowerCase() === peg$c65) {
s1 = input.substr(peg$currPos, 7);
peg$currPos += 7;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c66); }
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$parseIdentRest();
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = void 0;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c17); }
}
return s0;
}
function peg$parseNumberType() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
if (input.substr(peg$currPos, 6).toLowerCase() === peg$c68) {
s1 = input.substr(peg$currPos, 6);
peg$currPos += 6;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c69); }
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$parseIdentRest();
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = void 0;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c67); }
}
return s0;
}
function peg$parseStringType() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
if (input.substr(peg$currPos, 6).toLowerCase() === peg$c71) {
s1 = input.substr(peg$currPos, 6);
peg$currPos += 6;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c72); }
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$parseIdentRest();
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = void 0;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c70); }
}
return s0;
}
function peg$parseDateType() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$currPos;
if (input.substr(peg$currPos, 4).toLowerCase() === peg$c74) {
s1 = input.substr(peg$currPos, 4);
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c75); }
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$parseIdentRest();
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = void 0;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c73); }
}
return s0;
}
function peg$parseIdentifier() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
s2 = peg$parseKeyword();
peg$silentFails--;
if (s2 === peg$FAILED) {
s1 = void 0;
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parseIdentName();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c77(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c76); }
}
return s0;
}
function peg$parseIdentName() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$parseIdentStart();
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parseIdentRest();
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parseIdentRest();
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c78(s1, s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseIdentStart() {
var s0;
if (peg$c79.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c80); }
}
return s0;
}
function peg$parseIdentRest() {
var s0;
if (peg$c81.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s0 = peg$FAI