@dbml/core
Version:
> TODO: description
1,675 lines (1,671 loc) • 181 kB
JavaScript
/*
* Generated by PEG.js 0.10.0.
*
* http://pegjs.org/
*/
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var _ = require("lodash"),
pluralize = require("pluralize");
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);
peg$SyntaxError.buildMessage = function (expected, found) {
var DESCRIBE_EXPECTATION_FNS = {
literal: function literal(expectation) {
return "\"" + literalEscape(expectation.text) + "\"";
},
"class": function _class(expectation) {
var escapedParts = "",
i;
for (i = 0; i < expectation.parts.length; i++) {
escapedParts += expectation.parts[i] instanceof Array ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) : classEscape(expectation.parts[i]);
}
return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
},
any: function any(expectation) {
return "any character";
},
end: function end(expectation) {
return "end of input";
},
other: function other(expectation) {
return expectation.description;
}
};
function hex(ch) {
return ch.charCodeAt(0).toString(16).toUpperCase();
}
function literalEscape(s) {
return s.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\0/g, '\\0').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/[\x00-\x0F]/g, function (ch) {
return '\\x0' + hex(ch);
}).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
return '\\x' + hex(ch);
});
}
function classEscape(s) {
return s.replace(/\\/g, '\\\\').replace(/\]/g, '\\]').replace(/\^/g, '\\^').replace(/-/g, '\\-').replace(/\0/g, '\\0').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/[\x00-\x0F]/g, function (ch) {
return '\\x0' + hex(ch);
}).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
return '\\x' + hex(ch);
});
}
function describeExpectation(expectation) {
return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
}
function describeExpected(expected) {
var descriptions = new Array(expected.length),
i,
j;
for (i = 0; i < expected.length; i++) {
descriptions[i] = describeExpectation(expected[i]);
}
descriptions.sort();
if (descriptions.length > 0) {
for (i = 1, j = 1; i < descriptions.length; i++) {
if (descriptions[i - 1] !== descriptions[i]) {
descriptions[j] = descriptions[i];
j++;
}
}
descriptions.length = j;
}
switch (descriptions.length) {
case 1:
return descriptions[0];
case 2:
return descriptions[0] + " or " + descriptions[1];
default:
return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
}
}
function describeFound(found) {
return found ? "\"" + literalEscape(found) + "\"" : "end of input";
}
return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
};
function peg$parse(input, options) {
options = options !== void 0 ? options : {};
var peg$FAILED = {},
peg$startRuleFunctions = {
rules: peg$parserules
},
peg$startRuleFunction = peg$parserules,
peg$c0 = function peg$c0() {
return data;
},
peg$c1 = function peg$c1(t) {
data.tables.push(t);
},
peg$c2 = function peg$c2(r) {
data.refs.push(r);
},
peg$c3 = function peg$c3(e) {
data.enums.push(e);
},
peg$c4 = function peg$c4(tg) {
data.tableGroups.push(tg);
},
peg$c5 = function peg$c5(p) {
projectCnt += 1;
if (projectCnt > 1) {
error('Project is already defined');
}
data.project = p;
data.tables = data.tables.concat(p.tables);
data.refs = data.refs.concat(p.refs);
data.enums = data.enums.concat(p.enums);
data.tableGroups = data.tableGroups.concat(p.tableGroups);
},
peg$c6 = "{",
peg$c7 = peg$literalExpectation("{", false),
peg$c8 = "}",
peg$c9 = peg$literalExpectation("}", false),
peg$c10 = function peg$c10(name, body) {
return _objectSpread({
name: name ? name[1] : null
}, body);
},
peg$c11 = function peg$c11(elements) {
var tables = [];
var refs = [];
var enums = [];
var tableGroups = [];
var note = null;
var projectFields = {};
elements.forEach(function (ele) {
if (ele.type === 'table') {
tables.push(ele.value);
} else if (ele.type === 'ref') {
refs.push(ele.value);
} else if (ele.type === 'enum') {
enums.push(ele.value);
} else if (ele.type === 'table_group') {
tableGroups.push(ele.value);
} else if (ele.type === 'note') {
note = ele.value;
} else {
projectFields[ele.value.name] = ele.value.value;
}
});
return _objectSpread({
tables: tables,
refs: refs,
enums: enums,
tableGroups: tableGroups,
note: note
}, projectFields);
},
peg$c12 = function peg$c12(note) {
return {
type: 'note',
value: note
};
},
peg$c13 = function peg$c13(t) {
return {
type: 'table',
value: t
};
},
peg$c14 = function peg$c14(r) {
return {
type: 'ref',
value: r
};
},
peg$c15 = function peg$c15(e) {
return {
type: 'enum',
value: e
};
},
peg$c16 = function peg$c16(tg) {
return {
type: 'table_group',
value: tg
};
},
peg$c17 = function peg$c17(element) {
return {
type: 'element',
value: element
};
},
peg$c18 = ":",
peg$c19 = peg$literalExpectation(":", false),
peg$c20 = function peg$c20(name, value) {
return {
name: name,
value: value.value
};
},
peg$c21 = function peg$c21(schemaName, name, body) {
return {
name: name,
schemaName: schemaName,
tables: body,
token: location()
};
},
peg$c22 = function peg$c22(tables) {
return tables.map(function (t) {
return {
name: t[1],
schemaName: t[0]
};
});
},
peg$c23 = function peg$c23(r) {
var schemaName = r.endpoints[0].schemaName;
return _objectSpread(_objectSpread({}, r), {}, {
schemaName: schemaName
});
},
peg$c24 = function peg$c24(name, body) {
var ref = {
name: name ? name[1] : null,
endpoints: body.endpoints,
token: location()
};
Object.assign(ref, body.settings);
return ref;
},
peg$c25 = function peg$c25(field1, relation, field2, ref_settings) {
var rel = getRelations(relation);
var endpoints = [{
schemaName: field1.schemaName,
tableName: field1.tableName,
fieldNames: field1.fieldNames,
relation: rel[0],
token: location()
}, {
schemaName: field2.schemaName,
tableName: field2.tableName,
fieldNames: field2.fieldNames,
relation: rel[1],
token: location()
}];
return {
endpoints: endpoints,
settings: ref_settings
};
},
peg$c26 = function peg$c26(field) {
if (typeof field === "string") field = [field];
return field;
},
peg$c27 = function peg$c27(field) {
return field;
},
peg$c28 = "(",
peg$c29 = peg$literalExpectation("(", false),
peg$c30 = ")",
peg$c31 = peg$literalExpectation(")", false),
peg$c32 = function peg$c32(first, rest) {
var arrField = [first].concat(rest.map(function (el) {
return el[3];
}));
return arrField;
},
peg$c33 = "[",
peg$c34 = peg$literalExpectation("[", false),
peg$c35 = "]",
peg$c36 = peg$literalExpectation("]", false),
peg$c37 = function peg$c37(first, rest) {
var arrSettings = [first].concat(rest.map(function (el) {
return el[1];
}));
var res = {};
arrSettings.forEach(function (ele) {
if (ele.type === "update") {
res.onUpdate = ele.value;
}
if (ele.type === "delete") {
res.onDelete = ele.value;
}
});
return res;
},
peg$c38 = function peg$c38(v) {
return {
type: 'update',
value: v
};
},
peg$c39 = function peg$c39(v) {
return {
type: 'delete',
value: v
};
},
peg$c40 = "update:",
peg$c41 = peg$literalExpectation("update:", true),
peg$c42 = function peg$c42(val) {
return val;
},
peg$c43 = "delete:",
peg$c44 = peg$literalExpectation("delete:", true),
peg$c45 = function peg$c45(schemaName, name, alias, table_settings, body) {
var fields = body.fields || [];
var indexes = body.indexes || [];
// Handle list of partial inline_refs
var refs = [];
fields.forEach(function (field) {
(field.inline_refs || []).forEach(function (iref) {
var rel = getRelations(iref.relation);
var endpoints = [{
schemaName: iref.schemaName,
tableName: iref.tableName,
fieldNames: iref.fieldNames,
relation: rel[1],
token: iref.token
}, {
schemaName: schemaName,
tableName: name,
fieldNames: [field.name],
relation: rel[0],
token: iref.token
}];
var ref = {
schemaName: schemaName,
name: null,
// no name
endpoints: endpoints,
token: iref.token
};
data.refs.push(ref);
});
});
if (alias) {
if (data.aliases.find(function (a) {
return a.name === alias;
})) error("Alias \"".concat(alias, "\" is already defined"));
data.aliases.push({
name: alias,
kind: 'table',
value: {
tableName: name,
schemaName: schemaName
}
});
}
var res = _objectSpread({
name: name,
schemaName: schemaName,
alias: alias,
fields: fields,
token: location(),
indexes: indexes
}, table_settings);
if (body.note) {
res = _objectSpread(_objectSpread({}, res), {}, {
note: body.note
});
}
return res;
},
peg$c46 = function peg$c46(fields, elements) {
// concat all indexes
var indexes = _.flatMap(elements.filter(function (ele) {
return ele.type === 'indexes';
}), function (ele) {
return ele.value;
});
// pick the last note
var note = elements.slice().reverse().find(function (ele) {
return ele.type === 'note';
});
// process field for composite primary key:
var primaryKeyList = [];
fields.forEach(function (field) {
if (field.pk) {
primaryKeyList.push(field);
}
});
if (primaryKeyList.length > 1) {
var columns = primaryKeyList.map(function (field) {
return {
value: field.name,
type: 'column'
};
});
// remove property `pk` for each field in this list
primaryKeyList.forEach(function (field) {
return delete field.pk;
});
indexes.push({
columns: columns,
token: _.head(primaryKeyList).token,
pk: true
});
}
return {
fields: fields,
indexes: indexes,
note: note ? note.value : null
};
},
peg$c47 = function peg$c47(indexes) {
return {
type: 'indexes',
value: indexes
};
},
peg$c48 = function peg$c48(name, typeSchemaName, type, constrains, field_settings) {
var field = {
name: name,
type: _objectSpread({
schemaName: typeSchemaName
}, type),
token: location(),
inline_refs: []
};
Object.assign.apply(Object, [field].concat(_toConsumableArray(constrains.map(function (c) {
return c[1];
}))));
if (field_settings) {
Object.assign(field, field_settings[1]);
}
return field;
},
peg$c49 = function peg$c49(schemaName, name, body) {
return {
name: name,
schemaName: schemaName,
token: location(),
values: body.enum_values
};
},
peg$c50 = function peg$c50(enum_values) {
return {
enum_values: enum_values
};
},
peg$c51 = function peg$c51(name, enum_setting) {
var enum_value = {
name: name,
token: location()
};
Object.assign(enum_value, enum_setting);
return enum_value;
},
peg$c52 = function peg$c52(v) {
return {
note: v
};
},
peg$c53 = function peg$c53(first, rest) {
var arrSettings = [first].concat(rest.map(function (el) {
return el[1];
}));
var res = {
inline_refs: []
};
arrSettings.forEach(function (ele) {
if (typeof ele === 'string') {
if (ele.toLowerCase() == "not null") {
res.not_null = true;
}
if (ele.toLowerCase() == "null") {
res.not_null = false;
}
if (ele.toLowerCase() == "primary key" || ele.toLowerCase() == 'pk') {
res.pk = true;
}
if (ele.toLowerCase() == "unique") {
res.unique = true;
}
if (ele.toLowerCase() == "increment") {
res.increment = true;
}
} else {
if (ele.type === "note") {
res.note = ele.value;
}
if (ele.type === "ref_inline") {
res.inline_refs.push(ele.value);
}
if (ele.type === "default") {
res.dbdefault = ele.value;
}
}
});
return res;
},
peg$c54 = function peg$c54(first, rest) {
var settings = [first].concat(_toConsumableArray(rest.map(function (el) {
return el[1];
})));
var result = {};
settings.forEach(function (el) {
if (typeof el === 'string') {
if (el.startsWith('#')) {
result.headerColor = el.toUpperCase();
}
} else {
if (el.type === "note") {
result.note = el.value;
}
}
});
return result;
},
peg$c55 = function peg$c55(v) {
return {
type: 'note',
value: v
};
},
peg$c56 = function peg$c56(c) {
return c;
},
peg$c57 = "not null",
peg$c58 = peg$literalExpectation("not null", true),
peg$c59 = function peg$c59(a) {
return a;
},
peg$c60 = "null",
peg$c61 = peg$literalExpectation("null", true),
peg$c62 = "primary key",
peg$c63 = peg$literalExpectation("primary key", true),
peg$c64 = "pk",
peg$c65 = peg$literalExpectation("pk", true),
peg$c66 = "unique",
peg$c67 = peg$literalExpectation("unique", true),
peg$c68 = "increment",
peg$c69 = peg$literalExpectation("increment", false),
peg$c70 = function peg$c70(v) {
return {
type: 'ref_inline',
value: v
};
},
peg$c71 = function peg$c71(v) {
return {
type: 'default',
value: v
};
},
peg$c72 = function peg$c72(body) {
return body;
},
peg$c73 = function peg$c73(index) {
return index;
},
peg$c74 = function peg$c74(index) {
return index;
},
peg$c75 = function peg$c75(syntax, index_settings) {
var index = {
columns: [syntax],
token: location()
};
Object.assign(index, index_settings);
return index;
},
peg$c76 = function peg$c76(syntax, index_settings) {
var index = {
columns: syntax,
token: location()
};
Object.assign(index, index_settings);
return index;
},
peg$c77 = function peg$c77(column) {
var singleIndex = {
value: column,
type: 'column'
};
return singleIndex;
},
peg$c78 = "`",
peg$c79 = peg$literalExpectation("`", false),
peg$c80 = /^[^`]/,
peg$c81 = peg$classExpectation(["`"], true, false),
peg$c82 = function peg$c82(text) {
return {
value: text.join(""),
type: 'expression'
};
},
peg$c83 = function peg$c83(first, rest) {
var arrIndex = [first].concat(rest.map(function (el) {
return el[2];
}));
return arrIndex;
},
peg$c84 = function peg$c84(first, rest) {
var arrSettings = [first].concat(rest.map(function (el) {
return el[1];
}));
var res = {};
arrSettings.forEach(function (ele) {
if (typeof ele === 'string') {
res[ele.toLowerCase()] = true;
} else {
res[ele.type] = ele.value;
}
});
return res;
},
peg$c85 = function peg$c85(v) {
return {
type: 'name',
value: v
};
},
peg$c86 = function peg$c86(v) {
return {
type: 'type',
value: v
};
},
peg$c87 = function peg$c87() {
return {
type: 'pk',
value: true
};
},
peg$c88 = "name:",
peg$c89 = peg$literalExpectation("name:", true),
peg$c90 = function peg$c90(val) {
return val.value;
},
peg$c91 = function peg$c91(note) {
return note;
},
peg$c92 = "note",
peg$c93 = peg$literalExpectation("note", true),
peg$c94 = function peg$c94(val) {
return {
value: val.value,
token: location()
};
},
peg$c95 = "note:",
peg$c96 = peg$literalExpectation("note:", true),
peg$c97 = "type:",
peg$c98 = peg$literalExpectation("type:", true),
peg$c99 = "ref:",
peg$c100 = peg$literalExpectation("ref:", false),
peg$c101 = function peg$c101(relation, field) {
return {
schemaName: field.schemaName,
tableName: field.tableName,
fieldNames: [field.fieldName],
relation: relation,
token: location()
};
},
peg$c102 = "default:",
peg$c103 = peg$literalExpectation("default:", true),
peg$c104 = function peg$c104(val) {
return val;
},
peg$c105 = "as",
peg$c106 = peg$literalExpectation("as", false),
peg$c107 = function peg$c107(alias) {
return alias;
},
peg$c108 = function peg$c108(s, color) {
return s + color.join('');
},
peg$c109 = peg$otherExpectation("project"),
peg$c110 = "project",
peg$c111 = peg$literalExpectation("project", true),
peg$c112 = peg$otherExpectation("table"),
peg$c113 = "table",
peg$c114 = peg$literalExpectation("table", true),
peg$c115 = peg$literalExpectation("as", true),
peg$c116 = peg$otherExpectation("references"),
peg$c117 = "ref",
peg$c118 = peg$literalExpectation("ref", true),
peg$c119 = peg$otherExpectation("unique"),
peg$c120 = function peg$c120() {
return {
unique: true
};
},
peg$c121 = peg$otherExpectation("PK"),
peg$c122 = function peg$c122() {
return {
pk: true
};
},
peg$c123 = peg$otherExpectation("indexes"),
peg$c124 = "indexes",
peg$c125 = peg$literalExpectation("indexes", true),
peg$c126 = peg$otherExpectation("btree"),
peg$c127 = "btree",
peg$c128 = peg$literalExpectation("btree", true),
peg$c129 = peg$otherExpectation("hash"),
peg$c130 = "hash",
peg$c131 = peg$literalExpectation("hash", true),
peg$c132 = peg$otherExpectation("enum"),
peg$c133 = "enum",
peg$c134 = peg$literalExpectation("enum", true),
peg$c135 = "headercolor",
peg$c136 = peg$literalExpectation("headercolor", true),
peg$c137 = peg$otherExpectation("Table Group"),
peg$c138 = "tablegroup",
peg$c139 = peg$literalExpectation("TableGroup", true),
peg$c140 = peg$otherExpectation("no action"),
peg$c141 = "no action",
peg$c142 = peg$literalExpectation("no action", true),
peg$c143 = peg$otherExpectation("restrict"),
peg$c144 = "restrict",
peg$c145 = peg$literalExpectation("restrict", true),
peg$c146 = peg$otherExpectation("cascade"),
peg$c147 = "cascade",
peg$c148 = peg$literalExpectation("cascade", true),
peg$c149 = peg$otherExpectation("set null"),
peg$c150 = "set null",
peg$c151 = peg$literalExpectation("set null", true),
peg$c152 = peg$otherExpectation("set default"),
peg$c153 = "set default",
peg$c154 = peg$literalExpectation("set default", true),
peg$c155 = peg$otherExpectation("<>, >, - or <"),
peg$c156 = "<>",
peg$c157 = peg$literalExpectation("<>", false),
peg$c158 = ">",
peg$c159 = peg$literalExpectation(">", false),
peg$c160 = "<",
peg$c161 = peg$literalExpectation("<", false),
peg$c162 = "-",
peg$c163 = peg$literalExpectation("-", false),
peg$c164 = peg$otherExpectation("valid name"),
peg$c165 = function peg$c165(c) {
return c.join("");
},
peg$c166 = /^[^"\n]/,
peg$c167 = peg$classExpectation(["\"", "\n"], true, false),
peg$c168 = peg$otherExpectation("schema name"),
peg$c169 = ".",
peg$c170 = peg$literalExpectation(".", false),
peg$c171 = function peg$c171(name) {
return name;
},
peg$c172 = function peg$c172(schemaName, tableName, fieldNames) {
return {
schemaName: schemaName,
tableName: tableName,
fieldNames: fieldNames
};
},
peg$c173 = function peg$c173(tableName, fieldNames) {
return {
schemaName: null,
tableName: tableName,
fieldNames: fieldNames
};
},
peg$c174 = function peg$c174(schemaName, tableName, fieldName) {
return {
schemaName: schemaName,
tableName: tableName,
fieldName: fieldName
};
},
peg$c175 = function peg$c175(tableName, fieldName) {
return {
schemaName: null,
tableName: tableName,
fieldName: fieldName
};
},
peg$c176 = peg$otherExpectation("type"),
peg$c177 = function peg$c177(type_name, args) {
args = args ? args[3] : null;
if (type_name.toLowerCase() !== 'enum') {
type_name = args ? type_name + '(' + args + ')' : type_name;
}
return {
type_name: type_name,
args: args
};
},
peg$c178 = peg$otherExpectation("expression"),
peg$c179 = function peg$c179(factors) {
return _.flattenDeep(factors).join("");
},
peg$c180 = ",",
peg$c181 = peg$literalExpectation(",", false),
peg$c182 = ");",
peg$c183 = peg$literalExpectation(");", false),
peg$c184 = peg$anyExpectation(),
peg$c185 = function peg$c185(factors) {
return _.flattenDeep(factors).join("");
},
peg$c186 = /^[',.a-z0-9_+-`]/i,
peg$c187 = peg$classExpectation(["'", ",", ".", ["a", "z"], ["0", "9"], "_", ["+", "`"]], false, true),
peg$c188 = /^['.a-z0-9_+\-]/i,
peg$c189 = peg$classExpectation(["'", ".", ["a", "z"], ["0", "9"], "_", "+", "-"], false, true),
peg$c190 = function peg$c190() {
return text();
},
peg$c191 = /^[[\]]/,
peg$c192 = peg$classExpectation(["[", "]"], false, false),
peg$c193 = peg$otherExpectation("letter, number or underscore"),
peg$c194 = /^[a-z0-9_]/i,
peg$c195 = peg$classExpectation([["a", "z"], ["0", "9"], "_"], false, true),
peg$c196 = /^[0-9a-fA-F]/,
peg$c197 = peg$classExpectation([["0", "9"], ["a", "f"], ["A", "F"]], false, false),
peg$c198 = function peg$c198(c) {
return c.toLowerCase();
},
peg$c199 = "\"",
peg$c200 = peg$literalExpectation("\"", false),
peg$c201 = peg$otherExpectation("endline"),
peg$c202 = "\t",
peg$c203 = peg$literalExpectation("\t", false),
peg$c204 = "//",
peg$c205 = peg$literalExpectation("//", false),
peg$c206 = /^[^\n]/,
peg$c207 = peg$classExpectation(["\n"], true, false),
peg$c208 = "/*",
peg$c209 = peg$literalExpectation("/*", false),
peg$c210 = "*/",
peg$c211 = peg$literalExpectation("*/", false),
peg$c212 = peg$otherExpectation("comment"),
peg$c213 = peg$otherExpectation("newline"),
peg$c214 = "\r\n",
peg$c215 = peg$literalExpectation("\r\n", false),
peg$c216 = "\n",
peg$c217 = peg$literalExpectation("\n", false),
peg$c218 = peg$otherExpectation("whitespace"),
peg$c219 = /^[ \t\r\n\r]/,
peg$c220 = peg$classExpectation([" ", "\t", "\r", "\n", "\r"], false, false),
peg$c221 = /^[ \t\r\n\r"]/,
peg$c222 = peg$classExpectation([" ", "\t", "\r", "\n", "\r", "\""], false, false),
peg$c223 = " ",
peg$c224 = peg$literalExpectation(" ", false),
peg$c225 = "#",
peg$c226 = peg$literalExpectation("#", false),
peg$c227 = function peg$c227() {
return "#";
},
peg$c228 = peg$otherExpectation("string"),
peg$c229 = function peg$c229(chars) {
return {
value: chars.join(''),
type: 'string'
};
},
peg$c230 = "'''",
peg$c231 = peg$literalExpectation("'''", false),
peg$c232 = function peg$c232(chars) {
var str = chars.join('');
// // replace line continuation using look around, but this is not compatible with firefox, safari.
// str = str.replace(/(?<!\\)\\(?!\\)(?:\n|\r\n)?/g, '');
// str = str.replace(/\\\\/, '\\');
var lines = str.split(/\n|\r\n?/);
var leadingSpaces = function leadingSpaces(str) {
var i = 0;
while (i < str.length && str[i] === ' ') {
i += 1;
}
return i;
};
var minLeadingSpaces = lines.filter(function (line) {
return line.replace(/\s+/g, '');
}).reduce(function (acc, cur) {
return Math.min(acc, leadingSpaces(cur));
}, Number.MAX_SAFE_INTEGER);
lines = lines.map(function (line) {
return line ? line.slice(minLeadingSpaces) : line;
});
var countLeadingEmptyLine = function countLeadingEmptyLine(lines) {
var i = 0;
while (i < lines.length && !lines[i].replace(/\s+/g, '')) {
i += 1;
}
return i;
};
lines.splice(0, countLeadingEmptyLine(lines));
lines.splice(lines.length - countLeadingEmptyLine(lines.slice().reverse()));
var finalStr = lines.join('\n');
return {
value: finalStr,
type: 'string'
};
},
peg$c233 = "'",
peg$c234 = peg$literalExpectation("'", false),
peg$c235 = "\\",
peg$c236 = peg$literalExpectation("\\", false),
peg$c237 = function peg$c237() {
return '"';
},
peg$c238 = function peg$c238() {
return text();
},
peg$c239 = "\\'",
peg$c240 = peg$literalExpectation("\\'", false),
peg$c241 = function peg$c241() {
return "'";
},
peg$c242 = function peg$c242(bl) {
// escape character \. \\n => \n. Remove one backslash in the result string.
return bl.join('');
},
peg$c243 = function peg$c243() {
// replace line continuation
return '';
},
peg$c244 = /^[0-9]/,
peg$c245 = peg$classExpectation([["0", "9"]], false, false),
peg$c246 = "=",
peg$c247 = peg$literalExpectation("=", false),
peg$c248 = "true",
peg$c249 = peg$literalExpectation("true", true),
peg$c250 = "false",
peg$c251 = peg$literalExpectation("false", true),
peg$c252 = function peg$c252(_boolean) {
return {
type: 'boolean',
value: _boolean
};
},
peg$c253 = function peg$c253(minus, number) {
return {
type: 'number',
value: minus ? -number : number
};
},
peg$c254 = function peg$c254(left, right) {
return parseFloat(left.join("") + "." + right.join(""));
},
peg$c255 = function peg$c255(digits) {
return parseInt(digits.join(""), 10);
},
peg$currPos = 0,
peg$savedPos = 0,
peg$posDetailsCache = [{
line: 1,
column: 1
}],
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, location) {
location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos);
throw peg$buildStructuredError([peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location);
}
function error(message, location) {
location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos);
throw peg$buildSimpleError(message, location);
}
function peg$literalExpectation(text, ignoreCase) {
return {
type: "literal",
text: text,
ignoreCase: ignoreCase
};
}
function peg$classExpectation(parts, inverted, ignoreCase) {
return {
type: "class",
parts: parts,
inverted: inverted,
ignoreCase: ignoreCase
};
}
function peg$anyExpectation() {
return {
type: "any"
};
}
function peg$endExpectation() {
return {
type: "end"
};
}
function peg$otherExpectation(description) {
return {
type: "other",
description: description
};
}
function peg$computePosDetails(pos) {
var details = peg$posDetailsCache[pos],
p;
if (details) {
return details;
} else {
p = pos - 1;
while (!peg$posDetailsCache[p]) {
p--;
}
details = peg$posDetailsCache[p];
details = {
line: details.line,
column: details.column
};
while (p < pos) {
if (input.charCodeAt(p) === 10) {
details.line++;
details.column = 1;
} else {
details.column++;
}
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$buildSimpleError(message, location) {
return new peg$SyntaxError(message, null, null, location);
}
function peg$buildStructuredError(expected, found, location) {
return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
}
function peg$parserules() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = [];
s2 = peg$parseexpr();
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parseexpr();
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c0();
}
s0 = s1;
return s0;
}
function peg$parseexpr() {
var s0, s1;
s0 = peg$currPos;
s1 = peg$parseTableSyntax();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c1(s1);
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseRefSyntax();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c2(s1);
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseEnumSyntax();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c3(s1);
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseTableGroupSyntax();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c4(s1);
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseProjectSyntax();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c5(s1);
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$parse__();
}
}
}
}
}
return s0;
}
function peg$parseProjectSyntax() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8;
s0 = peg$currPos;
s1 = peg$parseproject();
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
s3 = peg$parse__();
if (s3 !== peg$FAILED) {
s4 = peg$parsename();
if (s4 !== peg$FAILED) {
s3 = [s3, 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) {
if (input.charCodeAt(peg$currPos) === 123) {
s4 = peg$c6;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c7);
}
}
if (s4 !== peg$FAILED) {
s5 = peg$parse_();
if (s5 !== peg$FAILED) {
s6 = peg$parseProjectBody();
if (s6 !== peg$FAILED) {
s7 = peg$parse_();
if (s7 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s8 = peg$c8;
peg$currPos++;
} else {
s8 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c9);
}
}
if (s8 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c10(s2, 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;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseProjectBody() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$parse_();
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parseProjectElement();
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parseProjectElement();
}
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c11(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseProjectElement() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$parse_();
if (s1 !== peg$FAILED) {
s2 = peg$parseObjectNoteElement();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c12(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parse_();
if (s1 !== peg$FAILED) {
s2 = peg$parseTableSyntax();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c13(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parse_();
if (s1 !== peg$FAILED) {
s2 = peg$parseRefSyntax();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c14(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parse_();
if (s1 !== peg$FAILED) {
s2 = peg$parseEnumSyntax();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c15(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseTableGroupSyntax();
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c16(s1);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parse_();
if (s1 !== peg$FAILED) {
s2 = peg$parseProjectField();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c17(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
}
}
}
}
return s0;
}
function peg$parseProjectField() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
s1 = peg$parsename();
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 58) {
s3 = peg$c18;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c19);
}
}
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = peg$parseStringLiteral();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c20(s1, s5);
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;
}
return s0;
}
function peg$parseTableGroupSyntax() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
s0 = peg$currPos;
s1 = peg$parsetable_group();
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parsesp();
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parsesp();
}
} else {
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s3 = peg$parseschema_name();
if (s3 === peg$FAILED) {
s3 = null;
}
if (s3 !== peg$FAILED) {
s4 = peg$parsename();
if (s4 !== peg$FAILED) {
s5 = peg$parse_();
if (s5 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 123) {
s6 = peg$c6;
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c7);
}
}
if (s6 !== peg$FAILED) {
s7 = peg$parse_();
if (s7 !== peg$FAILED) {
s8 = peg$parsetable_group_body();
if (s8 !== peg$FAILED) {
s9 = peg$parse_();
if (s9 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s10 = peg$c8;
peg$currPos++;
} else {
s10 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c9);
}
}
if (s10 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c21(s3, s4, 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;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsetable_group_body() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
s1 = [];
s2 = peg$currPos;
s3 = peg$parseschema_name();
if (s3 === peg$FAILED) {
s3 = null;
}
if (s3 !== peg$FAILED) {
s4 = peg$parsename();
if (s4 !== peg$FAILED) {
s5 = peg$parse__();
if (s5 !== peg$FAILED) {
s3 = [s3, s4, s5];
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$currPos;
s3 = peg$parseschema_name();
if (s3 === peg$FAILED) {
s3 = null;
}
if (s3 !== peg$FAILED) {
s4 = peg$parsename();
if (s4 !== peg$FAILED) {
s5 = peg$parse__();
if (s5 !== peg$FAILED) {
s3 = [s3, s4, s5];
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c22(s1);
}
s0 = s1;
return s0;
}
function peg$parseRefSyntax() {
var s0, s1;
s0 = peg$currPos;
s1 = peg$parseref_long();
if (s1 === peg$FAILED) {
s1 = peg$parseref_short();
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c23(s1);
}
s0 = s1;
return s0;
}
function peg$parseref_long() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8;
s0 = peg$currPos;
s1 = peg$parseref();
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
s3 = peg$parse__();
if (s3 !== peg$FAILED) {
s4 = peg$parsename();
if (s4 !== peg$FAILED) {
s3 = [s3, 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) {
if (input.charCodeAt(peg$currPos) === 123) {
s4 = peg$c6;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c7);
}
}
if (s4 !== peg$FAILED) {
s5 = peg$parse_();
if (s5 !== peg$FAILED) {
s6 = peg