@ephemeras/profile
Version:
Profile manager for ephemeras.
1,360 lines (1,350 loc) • 73.6 kB
JavaScript
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunk3HT76LNNcjs = require('../chunk-3HT76LNN.cjs');
// ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/parser.js
var require_parser = _chunk3HT76LNNcjs.__commonJS.call(void 0, {
"../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/parser.js"(exports2, module2) {
"use strict";
var ParserEND = 1114112;
var ParserError = class _ParserError extends Error {
/* istanbul ignore next */
constructor(msg, filename, linenumber) {
super("[ParserError] " + msg, filename, linenumber);
this.name = "ParserError";
this.code = "ParserError";
if (Error.captureStackTrace) Error.captureStackTrace(this, _ParserError);
}
};
var State = class {
constructor(parser) {
this.parser = parser;
this.buf = "";
this.returned = null;
this.result = null;
this.resultTable = null;
this.resultArr = null;
}
};
var Parser = class {
constructor() {
this.pos = 0;
this.col = 0;
this.line = 0;
this.obj = {};
this.ctx = this.obj;
this.stack = [];
this._buf = "";
this.char = null;
this.ii = 0;
this.state = new State(this.parseStart);
}
parse(str) {
if (str.length === 0 || str.length == null) return;
this._buf = String(str);
this.ii = -1;
this.char = -1;
let getNext;
while (getNext === false || this.nextChar()) {
getNext = this.runOne();
}
this._buf = null;
}
nextChar() {
if (this.char === 10) {
++this.line;
this.col = -1;
}
++this.ii;
this.char = this._buf.codePointAt(this.ii);
++this.pos;
++this.col;
return this.haveBuffer();
}
haveBuffer() {
return this.ii < this._buf.length;
}
runOne() {
return this.state.parser.call(this, this.state.returned);
}
finish() {
this.char = ParserEND;
let last;
do {
last = this.state.parser;
this.runOne();
} while (this.state.parser !== last);
this.ctx = null;
this.state = null;
this._buf = null;
return this.obj;
}
next(fn) {
if (typeof fn !== "function") throw new ParserError("Tried to set state to non-existent state: " + JSON.stringify(fn));
this.state.parser = fn;
}
goto(fn) {
this.next(fn);
return this.runOne();
}
call(fn, returnWith) {
if (returnWith) this.next(returnWith);
this.stack.push(this.state);
this.state = new State(fn);
}
callNow(fn, returnWith) {
this.call(fn, returnWith);
return this.runOne();
}
return(value) {
if (this.stack.length === 0) throw this.error(new ParserError("Stack underflow"));
if (value === void 0) value = this.state.buf;
this.state = this.stack.pop();
this.state.returned = value;
}
returnNow(value) {
this.return(value);
return this.runOne();
}
consume() {
if (this.char === ParserEND) throw this.error(new ParserError("Unexpected end-of-buffer"));
this.state.buf += this._buf[this.ii];
}
error(err) {
err.line = this.line;
err.col = this.col;
err.pos = this.pos;
return err;
}
/* istanbul ignore next */
parseStart() {
throw new ParserError("Must declare a parseStart method");
}
};
Parser.END = ParserEND;
Parser.Error = ParserError;
module2.exports = Parser;
}
});
// ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime.js
var require_create_datetime = _chunk3HT76LNNcjs.__commonJS.call(void 0, {
"../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime.js"(exports2, module2) {
"use strict";
module2.exports = (value) => {
const date = new Date(value);
if (isNaN(date)) {
throw new TypeError("Invalid Datetime");
} else {
return date;
}
};
}
});
// ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/format-num.js
var require_format_num = _chunk3HT76LNNcjs.__commonJS.call(void 0, {
"../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/format-num.js"(exports2, module2) {
"use strict";
module2.exports = (d, num) => {
num = String(num);
while (num.length < d) num = "0" + num;
return num;
};
}
});
// ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime-float.js
var require_create_datetime_float = _chunk3HT76LNNcjs.__commonJS.call(void 0, {
"../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime-float.js"(exports2, module2) {
"use strict";
var f = require_format_num();
var FloatingDateTime = class extends Date {
constructor(value) {
super(value + "Z");
this.isFloating = true;
}
toISOString() {
const date = `${this.getUTCFullYear()}-${f(2, this.getUTCMonth() + 1)}-${f(2, this.getUTCDate())}`;
const time = `${f(2, this.getUTCHours())}:${f(2, this.getUTCMinutes())}:${f(2, this.getUTCSeconds())}.${f(3, this.getUTCMilliseconds())}`;
return `${date}T${time}`;
}
};
module2.exports = (value) => {
const date = new FloatingDateTime(value);
if (isNaN(date)) {
throw new TypeError("Invalid Datetime");
} else {
return date;
}
};
}
});
// ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-date.js
var require_create_date = _chunk3HT76LNNcjs.__commonJS.call(void 0, {
"../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-date.js"(exports2, module2) {
"use strict";
var f = require_format_num();
var DateTime = global.Date;
var Date2 = class extends DateTime {
constructor(value) {
super(value);
this.isDate = true;
}
toISOString() {
return `${this.getUTCFullYear()}-${f(2, this.getUTCMonth() + 1)}-${f(2, this.getUTCDate())}`;
}
};
module2.exports = (value) => {
const date = new Date2(value);
if (isNaN(date)) {
throw new TypeError("Invalid Datetime");
} else {
return date;
}
};
}
});
// ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-time.js
var require_create_time = _chunk3HT76LNNcjs.__commonJS.call(void 0, {
"../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-time.js"(exports2, module2) {
"use strict";
var f = require_format_num();
var Time = class extends Date {
constructor(value) {
super(`0000-01-01T${value}Z`);
this.isTime = true;
}
toISOString() {
return `${f(2, this.getUTCHours())}:${f(2, this.getUTCMinutes())}:${f(2, this.getUTCSeconds())}.${f(3, this.getUTCMilliseconds())}`;
}
};
module2.exports = (value) => {
const date = new Time(value);
if (isNaN(date)) {
throw new TypeError("Invalid Datetime");
} else {
return date;
}
};
}
});
// ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/toml-parser.js
var require_toml_parser = _chunk3HT76LNNcjs.__commonJS.call(void 0, {
"../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/toml-parser.js"(exports, module) {
"use strict";
module.exports = makeParserClass(require_parser());
module.exports.makeParserClass = makeParserClass;
var TomlError = class _TomlError extends Error {
constructor(msg) {
super(msg);
this.name = "TomlError";
if (Error.captureStackTrace) Error.captureStackTrace(this, _TomlError);
this.fromTOML = true;
this.wrapped = null;
}
};
TomlError.wrap = (err) => {
const terr = new TomlError(err.message);
terr.code = err.code;
terr.wrapped = err;
return terr;
};
module.exports.TomlError = TomlError;
var createDateTime = require_create_datetime();
var createDateTimeFloat = require_create_datetime_float();
var createDate = require_create_date();
var createTime = require_create_time();
var CTRL_I = 9;
var CTRL_J = 10;
var CTRL_M = 13;
var CTRL_CHAR_BOUNDARY = 31;
var CHAR_SP = 32;
var CHAR_QUOT = 34;
var CHAR_NUM = 35;
var CHAR_APOS = 39;
var CHAR_PLUS = 43;
var CHAR_COMMA = 44;
var CHAR_HYPHEN = 45;
var CHAR_PERIOD = 46;
var CHAR_0 = 48;
var CHAR_1 = 49;
var CHAR_7 = 55;
var CHAR_9 = 57;
var CHAR_COLON = 58;
var CHAR_EQUALS = 61;
var CHAR_A = 65;
var CHAR_E = 69;
var CHAR_F = 70;
var CHAR_T = 84;
var CHAR_U = 85;
var CHAR_Z = 90;
var CHAR_LOWBAR = 95;
var CHAR_a = 97;
var CHAR_b = 98;
var CHAR_e = 101;
var CHAR_f = 102;
var CHAR_i = 105;
var CHAR_l = 108;
var CHAR_n = 110;
var CHAR_o = 111;
var CHAR_r = 114;
var CHAR_s = 115;
var CHAR_t = 116;
var CHAR_u = 117;
var CHAR_x = 120;
var CHAR_z = 122;
var CHAR_LCUB = 123;
var CHAR_RCUB = 125;
var CHAR_LSQB = 91;
var CHAR_BSOL = 92;
var CHAR_RSQB = 93;
var CHAR_DEL = 127;
var SURROGATE_FIRST = 55296;
var SURROGATE_LAST = 57343;
var escapes = {
[CHAR_b]: "\b",
[CHAR_t]: " ",
[CHAR_n]: "\n",
[CHAR_f]: "\f",
[CHAR_r]: "\r",
[CHAR_QUOT]: '"',
[CHAR_BSOL]: "\\"
};
function isDigit(cp) {
return cp >= CHAR_0 && cp <= CHAR_9;
}
function isHexit(cp) {
return cp >= CHAR_A && cp <= CHAR_F || cp >= CHAR_a && cp <= CHAR_f || cp >= CHAR_0 && cp <= CHAR_9;
}
function isBit(cp) {
return cp === CHAR_1 || cp === CHAR_0;
}
function isOctit(cp) {
return cp >= CHAR_0 && cp <= CHAR_7;
}
function isAlphaNumQuoteHyphen(cp) {
return cp >= CHAR_A && cp <= CHAR_Z || cp >= CHAR_a && cp <= CHAR_z || cp >= CHAR_0 && cp <= CHAR_9 || cp === CHAR_APOS || cp === CHAR_QUOT || cp === CHAR_LOWBAR || cp === CHAR_HYPHEN;
}
function isAlphaNumHyphen(cp) {
return cp >= CHAR_A && cp <= CHAR_Z || cp >= CHAR_a && cp <= CHAR_z || cp >= CHAR_0 && cp <= CHAR_9 || cp === CHAR_LOWBAR || cp === CHAR_HYPHEN;
}
var _type = Symbol("type");
var _declared = Symbol("declared");
var hasOwnProperty = Object.prototype.hasOwnProperty;
var defineProperty = Object.defineProperty;
var descriptor = { configurable: true, enumerable: true, writable: true, value: void 0 };
function hasKey(obj, key) {
if (hasOwnProperty.call(obj, key)) return true;
if (key === "__proto__") defineProperty(obj, "__proto__", descriptor);
return false;
}
var INLINE_TABLE = Symbol("inline-table");
function InlineTable() {
return Object.defineProperties({}, {
[_type]: { value: INLINE_TABLE }
});
}
function isInlineTable(obj) {
if (obj === null || typeof obj !== "object") return false;
return obj[_type] === INLINE_TABLE;
}
var TABLE = Symbol("table");
function Table() {
return Object.defineProperties({}, {
[_type]: { value: TABLE },
[_declared]: { value: false, writable: true }
});
}
function isTable(obj) {
if (obj === null || typeof obj !== "object") return false;
return obj[_type] === TABLE;
}
var _contentType = Symbol("content-type");
var INLINE_LIST = Symbol("inline-list");
function InlineList(type) {
return Object.defineProperties([], {
[_type]: { value: INLINE_LIST },
[_contentType]: { value: type }
});
}
function isInlineList(obj) {
if (obj === null || typeof obj !== "object") return false;
return obj[_type] === INLINE_LIST;
}
var LIST = Symbol("list");
function List() {
return Object.defineProperties([], {
[_type]: { value: LIST }
});
}
function isList(obj) {
if (obj === null || typeof obj !== "object") return false;
return obj[_type] === LIST;
}
var _custom;
try {
const utilInspect = eval("require('util').inspect");
_custom = utilInspect.custom;
} catch (_) {
}
var _inspect = _custom || "inspect";
var BoxedBigInt = class {
constructor(value) {
try {
this.value = global.BigInt.asIntN(64, value);
} catch (_) {
this.value = null;
}
Object.defineProperty(this, _type, { value: INTEGER });
}
isNaN() {
return this.value === null;
}
/* istanbul ignore next */
toString() {
return String(this.value);
}
/* istanbul ignore next */
[_inspect]() {
return `[BigInt: ${this.toString()}]}`;
}
valueOf() {
return this.value;
}
};
var INTEGER = Symbol("integer");
function Integer(value) {
let num = Number(value);
if (Object.is(num, -0)) num = 0;
if (global.BigInt && !Number.isSafeInteger(num)) {
return new BoxedBigInt(value);
} else {
return Object.defineProperties(new Number(num), {
isNaN: { value: function() {
return isNaN(this);
} },
[_type]: { value: INTEGER },
[_inspect]: { value: () => `[Integer: ${value}]` }
});
}
}
function isInteger(obj) {
if (obj === null || typeof obj !== "object") return false;
return obj[_type] === INTEGER;
}
var FLOAT = Symbol("float");
function Float(value) {
return Object.defineProperties(new Number(value), {
[_type]: { value: FLOAT },
[_inspect]: { value: () => `[Float: ${value}]` }
});
}
function isFloat(obj) {
if (obj === null || typeof obj !== "object") return false;
return obj[_type] === FLOAT;
}
function tomlType(value) {
const type = typeof value;
if (type === "object") {
if (value === null) return "null";
if (value instanceof Date) return "datetime";
if (_type in value) {
switch (value[_type]) {
case INLINE_TABLE:
return "inline-table";
case INLINE_LIST:
return "inline-list";
/* istanbul ignore next */
case TABLE:
return "table";
/* istanbul ignore next */
case LIST:
return "list";
case FLOAT:
return "float";
case INTEGER:
return "integer";
}
}
}
return type;
}
function makeParserClass(Parser) {
class TOMLParser extends Parser {
constructor() {
super();
this.ctx = this.obj = Table();
}
/* MATCH HELPER */
atEndOfWord() {
return this.char === CHAR_NUM || this.char === CTRL_I || this.char === CHAR_SP || this.atEndOfLine();
}
atEndOfLine() {
return this.char === Parser.END || this.char === CTRL_J || this.char === CTRL_M;
}
parseStart() {
if (this.char === Parser.END) {
return null;
} else if (this.char === CHAR_LSQB) {
return this.call(this.parseTableOrList);
} else if (this.char === CHAR_NUM) {
return this.call(this.parseComment);
} else if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
return null;
} else if (isAlphaNumQuoteHyphen(this.char)) {
return this.callNow(this.parseAssignStatement);
} else {
throw this.error(new TomlError(`Unknown character "${this.char}"`));
}
}
// HELPER, this strips any whitespace and comments to the end of the line
// then RETURNS. Last state in a production.
parseWhitespaceToEOL() {
if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
return null;
} else if (this.char === CHAR_NUM) {
return this.goto(this.parseComment);
} else if (this.char === Parser.END || this.char === CTRL_J) {
return this.return();
} else {
throw this.error(new TomlError("Unexpected character, expected only whitespace or comments till end of line"));
}
}
/* ASSIGNMENT: key = value */
parseAssignStatement() {
return this.callNow(this.parseAssign, this.recordAssignStatement);
}
recordAssignStatement(kv) {
let target = this.ctx;
let finalKey = kv.key.pop();
for (let kw of kv.key) {
if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
throw this.error(new TomlError("Can't redefine existing key"));
}
target = target[kw] = target[kw] || Table();
}
if (hasKey(target, finalKey)) {
throw this.error(new TomlError("Can't redefine existing key"));
}
if (isInteger(kv.value) || isFloat(kv.value)) {
target[finalKey] = kv.value.valueOf();
} else {
target[finalKey] = kv.value;
}
return this.goto(this.parseWhitespaceToEOL);
}
/* ASSSIGNMENT expression, key = value possibly inside an inline table */
parseAssign() {
return this.callNow(this.parseKeyword, this.recordAssignKeyword);
}
recordAssignKeyword(key) {
if (this.state.resultTable) {
this.state.resultTable.push(key);
} else {
this.state.resultTable = [key];
}
return this.goto(this.parseAssignKeywordPreDot);
}
parseAssignKeywordPreDot() {
if (this.char === CHAR_PERIOD) {
return this.next(this.parseAssignKeywordPostDot);
} else if (this.char !== CHAR_SP && this.char !== CTRL_I) {
return this.goto(this.parseAssignEqual);
}
}
parseAssignKeywordPostDot() {
if (this.char !== CHAR_SP && this.char !== CTRL_I) {
return this.callNow(this.parseKeyword, this.recordAssignKeyword);
}
}
parseAssignEqual() {
if (this.char === CHAR_EQUALS) {
return this.next(this.parseAssignPreValue);
} else {
throw this.error(new TomlError('Invalid character, expected "="'));
}
}
parseAssignPreValue() {
if (this.char === CHAR_SP || this.char === CTRL_I) {
return null;
} else {
return this.callNow(this.parseValue, this.recordAssignValue);
}
}
recordAssignValue(value) {
return this.returnNow({ key: this.state.resultTable, value });
}
/* COMMENTS: #...eol */
parseComment() {
do {
if (this.char === Parser.END || this.char === CTRL_J) {
return this.return();
}
} while (this.nextChar());
}
/* TABLES AND LISTS, [foo] and [[foo]] */
parseTableOrList() {
if (this.char === CHAR_LSQB) {
this.next(this.parseList);
} else {
return this.goto(this.parseTable);
}
}
/* TABLE [foo.bar.baz] */
parseTable() {
this.ctx = this.obj;
return this.goto(this.parseTableNext);
}
parseTableNext() {
if (this.char === CHAR_SP || this.char === CTRL_I) {
return null;
} else {
return this.callNow(this.parseKeyword, this.parseTableMore);
}
}
parseTableMore(keyword) {
if (this.char === CHAR_SP || this.char === CTRL_I) {
return null;
} else if (this.char === CHAR_RSQB) {
if (hasKey(this.ctx, keyword) && (!isTable(this.ctx[keyword]) || this.ctx[keyword][_declared])) {
throw this.error(new TomlError("Can't redefine existing key"));
} else {
this.ctx = this.ctx[keyword] = this.ctx[keyword] || Table();
this.ctx[_declared] = true;
}
return this.next(this.parseWhitespaceToEOL);
} else if (this.char === CHAR_PERIOD) {
if (!hasKey(this.ctx, keyword)) {
this.ctx = this.ctx[keyword] = Table();
} else if (isTable(this.ctx[keyword])) {
this.ctx = this.ctx[keyword];
} else if (isList(this.ctx[keyword])) {
this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
} else {
throw this.error(new TomlError("Can't redefine existing key"));
}
return this.next(this.parseTableNext);
} else {
throw this.error(new TomlError("Unexpected character, expected whitespace, . or ]"));
}
}
/* LIST [[a.b.c]] */
parseList() {
this.ctx = this.obj;
return this.goto(this.parseListNext);
}
parseListNext() {
if (this.char === CHAR_SP || this.char === CTRL_I) {
return null;
} else {
return this.callNow(this.parseKeyword, this.parseListMore);
}
}
parseListMore(keyword) {
if (this.char === CHAR_SP || this.char === CTRL_I) {
return null;
} else if (this.char === CHAR_RSQB) {
if (!hasKey(this.ctx, keyword)) {
this.ctx[keyword] = List();
}
if (isInlineList(this.ctx[keyword])) {
throw this.error(new TomlError("Can't extend an inline array"));
} else if (isList(this.ctx[keyword])) {
const next = Table();
this.ctx[keyword].push(next);
this.ctx = next;
} else {
throw this.error(new TomlError("Can't redefine an existing key"));
}
return this.next(this.parseListEnd);
} else if (this.char === CHAR_PERIOD) {
if (!hasKey(this.ctx, keyword)) {
this.ctx = this.ctx[keyword] = Table();
} else if (isInlineList(this.ctx[keyword])) {
throw this.error(new TomlError("Can't extend an inline array"));
} else if (isInlineTable(this.ctx[keyword])) {
throw this.error(new TomlError("Can't extend an inline table"));
} else if (isList(this.ctx[keyword])) {
this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
} else if (isTable(this.ctx[keyword])) {
this.ctx = this.ctx[keyword];
} else {
throw this.error(new TomlError("Can't redefine an existing key"));
}
return this.next(this.parseListNext);
} else {
throw this.error(new TomlError("Unexpected character, expected whitespace, . or ]"));
}
}
parseListEnd(keyword) {
if (this.char === CHAR_RSQB) {
return this.next(this.parseWhitespaceToEOL);
} else {
throw this.error(new TomlError("Unexpected character, expected whitespace, . or ]"));
}
}
/* VALUE string, number, boolean, inline list, inline object */
parseValue() {
if (this.char === Parser.END) {
throw this.error(new TomlError("Key without value"));
} else if (this.char === CHAR_QUOT) {
return this.next(this.parseDoubleString);
}
if (this.char === CHAR_APOS) {
return this.next(this.parseSingleString);
} else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
return this.goto(this.parseNumberSign);
} else if (this.char === CHAR_i) {
return this.next(this.parseInf);
} else if (this.char === CHAR_n) {
return this.next(this.parseNan);
} else if (isDigit(this.char)) {
return this.goto(this.parseNumberOrDateTime);
} else if (this.char === CHAR_t || this.char === CHAR_f) {
return this.goto(this.parseBoolean);
} else if (this.char === CHAR_LSQB) {
return this.call(this.parseInlineList, this.recordValue);
} else if (this.char === CHAR_LCUB) {
return this.call(this.parseInlineTable, this.recordValue);
} else {
throw this.error(new TomlError("Unexpected character, expecting string, number, datetime, boolean, inline array or inline table"));
}
}
recordValue(value) {
return this.returnNow(value);
}
parseInf() {
if (this.char === CHAR_n) {
return this.next(this.parseInf2);
} else {
throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'));
}
}
parseInf2() {
if (this.char === CHAR_f) {
if (this.state.buf === "-") {
return this.return(-Infinity);
} else {
return this.return(Infinity);
}
} else {
throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'));
}
}
parseNan() {
if (this.char === CHAR_a) {
return this.next(this.parseNan2);
} else {
throw this.error(new TomlError('Unexpected character, expected "nan"'));
}
}
parseNan2() {
if (this.char === CHAR_n) {
return this.return(NaN);
} else {
throw this.error(new TomlError('Unexpected character, expected "nan"'));
}
}
/* KEYS, barewords or basic, literal, or dotted */
parseKeyword() {
if (this.char === CHAR_QUOT) {
return this.next(this.parseBasicString);
} else if (this.char === CHAR_APOS) {
return this.next(this.parseLiteralString);
} else {
return this.goto(this.parseBareKey);
}
}
/* KEYS: barewords */
parseBareKey() {
do {
if (this.char === Parser.END) {
throw this.error(new TomlError("Key ended without value"));
} else if (isAlphaNumHyphen(this.char)) {
this.consume();
} else if (this.state.buf.length === 0) {
throw this.error(new TomlError("Empty bare keys are not allowed"));
} else {
return this.returnNow();
}
} while (this.nextChar());
}
/* STRINGS, single quoted (literal) */
parseSingleString() {
if (this.char === CHAR_APOS) {
return this.next(this.parseLiteralMultiStringMaybe);
} else {
return this.goto(this.parseLiteralString);
}
}
parseLiteralString() {
do {
if (this.char === CHAR_APOS) {
return this.return();
} else if (this.atEndOfLine()) {
throw this.error(new TomlError("Unterminated string"));
} else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I) {
throw this.errorControlCharInString();
} else {
this.consume();
}
} while (this.nextChar());
}
parseLiteralMultiStringMaybe() {
if (this.char === CHAR_APOS) {
return this.next(this.parseLiteralMultiString);
} else {
return this.returnNow();
}
}
parseLiteralMultiString() {
if (this.char === CTRL_M) {
return null;
} else if (this.char === CTRL_J) {
return this.next(this.parseLiteralMultiStringContent);
} else {
return this.goto(this.parseLiteralMultiStringContent);
}
}
parseLiteralMultiStringContent() {
do {
if (this.char === CHAR_APOS) {
return this.next(this.parseLiteralMultiEnd);
} else if (this.char === Parser.END) {
throw this.error(new TomlError("Unterminated multi-line string"));
} else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) {
throw this.errorControlCharInString();
} else {
this.consume();
}
} while (this.nextChar());
}
parseLiteralMultiEnd() {
if (this.char === CHAR_APOS) {
return this.next(this.parseLiteralMultiEnd2);
} else {
this.state.buf += "'";
return this.goto(this.parseLiteralMultiStringContent);
}
}
parseLiteralMultiEnd2() {
if (this.char === CHAR_APOS) {
return this.return();
} else {
this.state.buf += "''";
return this.goto(this.parseLiteralMultiStringContent);
}
}
/* STRINGS double quoted */
parseDoubleString() {
if (this.char === CHAR_QUOT) {
return this.next(this.parseMultiStringMaybe);
} else {
return this.goto(this.parseBasicString);
}
}
parseBasicString() {
do {
if (this.char === CHAR_BSOL) {
return this.call(this.parseEscape, this.recordEscapeReplacement);
} else if (this.char === CHAR_QUOT) {
return this.return();
} else if (this.atEndOfLine()) {
throw this.error(new TomlError("Unterminated string"));
} else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I) {
throw this.errorControlCharInString();
} else {
this.consume();
}
} while (this.nextChar());
}
recordEscapeReplacement(replacement) {
this.state.buf += replacement;
return this.goto(this.parseBasicString);
}
parseMultiStringMaybe() {
if (this.char === CHAR_QUOT) {
return this.next(this.parseMultiString);
} else {
return this.returnNow();
}
}
parseMultiString() {
if (this.char === CTRL_M) {
return null;
} else if (this.char === CTRL_J) {
return this.next(this.parseMultiStringContent);
} else {
return this.goto(this.parseMultiStringContent);
}
}
parseMultiStringContent() {
do {
if (this.char === CHAR_BSOL) {
return this.call(this.parseMultiEscape, this.recordMultiEscapeReplacement);
} else if (this.char === CHAR_QUOT) {
return this.next(this.parseMultiEnd);
} else if (this.char === Parser.END) {
throw this.error(new TomlError("Unterminated multi-line string"));
} else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) {
throw this.errorControlCharInString();
} else {
this.consume();
}
} while (this.nextChar());
}
errorControlCharInString() {
let displayCode = "\\u00";
if (this.char < 16) {
displayCode += "0";
}
displayCode += this.char.toString(16);
return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in strings, use ${displayCode} instead`));
}
recordMultiEscapeReplacement(replacement) {
this.state.buf += replacement;
return this.goto(this.parseMultiStringContent);
}
parseMultiEnd() {
if (this.char === CHAR_QUOT) {
return this.next(this.parseMultiEnd2);
} else {
this.state.buf += '"';
return this.goto(this.parseMultiStringContent);
}
}
parseMultiEnd2() {
if (this.char === CHAR_QUOT) {
return this.return();
} else {
this.state.buf += '""';
return this.goto(this.parseMultiStringContent);
}
}
parseMultiEscape() {
if (this.char === CTRL_M || this.char === CTRL_J) {
return this.next(this.parseMultiTrim);
} else if (this.char === CHAR_SP || this.char === CTRL_I) {
return this.next(this.parsePreMultiTrim);
} else {
return this.goto(this.parseEscape);
}
}
parsePreMultiTrim() {
if (this.char === CHAR_SP || this.char === CTRL_I) {
return null;
} else if (this.char === CTRL_M || this.char === CTRL_J) {
return this.next(this.parseMultiTrim);
} else {
throw this.error(new TomlError("Can't escape whitespace"));
}
}
parseMultiTrim() {
if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
return null;
} else {
return this.returnNow();
}
}
parseEscape() {
if (this.char in escapes) {
return this.return(escapes[this.char]);
} else if (this.char === CHAR_u) {
return this.call(this.parseSmallUnicode, this.parseUnicodeReturn);
} else if (this.char === CHAR_U) {
return this.call(this.parseLargeUnicode, this.parseUnicodeReturn);
} else {
throw this.error(new TomlError("Unknown escape character: " + this.char));
}
}
parseUnicodeReturn(char) {
try {
const codePoint = parseInt(char, 16);
if (codePoint >= SURROGATE_FIRST && codePoint <= SURROGATE_LAST) {
throw this.error(new TomlError("Invalid unicode, character in range 0xD800 - 0xDFFF is reserved"));
}
return this.returnNow(String.fromCodePoint(codePoint));
} catch (err) {
throw this.error(TomlError.wrap(err));
}
}
parseSmallUnicode() {
if (!isHexit(this.char)) {
throw this.error(new TomlError("Invalid character in unicode sequence, expected hex"));
} else {
this.consume();
if (this.state.buf.length >= 4) return this.return();
}
}
parseLargeUnicode() {
if (!isHexit(this.char)) {
throw this.error(new TomlError("Invalid character in unicode sequence, expected hex"));
} else {
this.consume();
if (this.state.buf.length >= 8) return this.return();
}
}
/* NUMBERS */
parseNumberSign() {
this.consume();
return this.next(this.parseMaybeSignedInfOrNan);
}
parseMaybeSignedInfOrNan() {
if (this.char === CHAR_i) {
return this.next(this.parseInf);
} else if (this.char === CHAR_n) {
return this.next(this.parseNan);
} else {
return this.callNow(this.parseNoUnder, this.parseNumberIntegerStart);
}
}
parseNumberIntegerStart() {
if (this.char === CHAR_0) {
this.consume();
return this.next(this.parseNumberIntegerExponentOrDecimal);
} else {
return this.goto(this.parseNumberInteger);
}
}
parseNumberIntegerExponentOrDecimal() {
if (this.char === CHAR_PERIOD) {
this.consume();
return this.call(this.parseNoUnder, this.parseNumberFloat);
} else if (this.char === CHAR_E || this.char === CHAR_e) {
this.consume();
return this.next(this.parseNumberExponentSign);
} else {
return this.returnNow(Integer(this.state.buf));
}
}
parseNumberInteger() {
if (isDigit(this.char)) {
this.consume();
} else if (this.char === CHAR_LOWBAR) {
return this.call(this.parseNoUnder);
} else if (this.char === CHAR_E || this.char === CHAR_e) {
this.consume();
return this.next(this.parseNumberExponentSign);
} else if (this.char === CHAR_PERIOD) {
this.consume();
return this.call(this.parseNoUnder, this.parseNumberFloat);
} else {
const result = Integer(this.state.buf);
if (result.isNaN()) {
throw this.error(new TomlError("Invalid number"));
} else {
return this.returnNow(result);
}
}
}
parseNoUnder() {
if (this.char === CHAR_LOWBAR || this.char === CHAR_PERIOD || this.char === CHAR_E || this.char === CHAR_e) {
throw this.error(new TomlError("Unexpected character, expected digit"));
} else if (this.atEndOfWord()) {
throw this.error(new TomlError("Incomplete number"));
}
return this.returnNow();
}
parseNoUnderHexOctBinLiteral() {
if (this.char === CHAR_LOWBAR || this.char === CHAR_PERIOD) {
throw this.error(new TomlError("Unexpected character, expected digit"));
} else if (this.atEndOfWord()) {
throw this.error(new TomlError("Incomplete number"));
}
return this.returnNow();
}
parseNumberFloat() {
if (this.char === CHAR_LOWBAR) {
return this.call(this.parseNoUnder, this.parseNumberFloat);
} else if (isDigit(this.char)) {
this.consume();
} else if (this.char === CHAR_E || this.char === CHAR_e) {
this.consume();
return this.next(this.parseNumberExponentSign);
} else {
return this.returnNow(Float(this.state.buf));
}
}
parseNumberExponentSign() {
if (isDigit(this.char)) {
return this.goto(this.parseNumberExponent);
} else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
this.consume();
this.call(this.parseNoUnder, this.parseNumberExponent);
} else {
throw this.error(new TomlError("Unexpected character, expected -, + or digit"));
}
}
parseNumberExponent() {
if (isDigit(this.char)) {
this.consume();
} else if (this.char === CHAR_LOWBAR) {
return this.call(this.parseNoUnder);
} else {
return this.returnNow(Float(this.state.buf));
}
}
/* NUMBERS or DATETIMES */
parseNumberOrDateTime() {
if (this.char === CHAR_0) {
this.consume();
return this.next(this.parseNumberBaseOrDateTime);
} else {
return this.goto(this.parseNumberOrDateTimeOnly);
}
}
parseNumberOrDateTimeOnly() {
if (this.char === CHAR_LOWBAR) {
return this.call(this.parseNoUnder, this.parseNumberInteger);
} else if (isDigit(this.char)) {
this.consume();
if (this.state.buf.length > 4) this.next(this.parseNumberInteger);
} else if (this.char === CHAR_E || this.char === CHAR_e) {
this.consume();
return this.next(this.parseNumberExponentSign);
} else if (this.char === CHAR_PERIOD) {
this.consume();
return this.call(this.parseNoUnder, this.parseNumberFloat);
} else if (this.char === CHAR_HYPHEN) {
return this.goto(this.parseDateTime);
} else if (this.char === CHAR_COLON) {
return this.goto(this.parseOnlyTimeHour);
} else {
return this.returnNow(Integer(this.state.buf));
}
}
parseDateTimeOnly() {
if (this.state.buf.length < 4) {
if (isDigit(this.char)) {
return this.consume();
} else if (this.char === CHAR_COLON) {
return this.goto(this.parseOnlyTimeHour);
} else {
throw this.error(new TomlError("Expected digit while parsing year part of a date"));
}
} else {
if (this.char === CHAR_HYPHEN) {
return this.goto(this.parseDateTime);
} else {
throw this.error(new TomlError("Expected hyphen (-) while parsing year part of date"));
}
}
}
parseNumberBaseOrDateTime() {
if (this.char === CHAR_b) {
this.consume();
return this.call(this.parseNoUnderHexOctBinLiteral, this.parseIntegerBin);
} else if (this.char === CHAR_o) {
this.consume();
return this.call(this.parseNoUnderHexOctBinLiteral, this.parseIntegerOct);
} else if (this.char === CHAR_x) {
this.consume();
return this.call(this.parseNoUnderHexOctBinLiteral, this.parseIntegerHex);
} else if (this.char === CHAR_PERIOD) {
return this.goto(this.parseNumberInteger);
} else if (isDigit(this.char)) {
return this.goto(this.parseDateTimeOnly);
} else {
return this.returnNow(Integer(this.state.buf));
}
}
parseIntegerHex() {
if (isHexit(this.char)) {
this.consume();
} else if (this.char === CHAR_LOWBAR) {
return this.call(this.parseNoUnderHexOctBinLiteral);
} else {
const result = Integer(this.state.buf);
if (result.isNaN()) {
throw this.error(new TomlError("Invalid number"));
} else {
return this.returnNow(result);
}
}
}
parseIntegerOct() {
if (isOctit(this.char)) {
this.consume();
} else if (this.char === CHAR_LOWBAR) {
return this.call(this.parseNoUnderHexOctBinLiteral);
} else {
const result = Integer(this.state.buf);
if (result.isNaN()) {
throw this.error(new TomlError("Invalid number"));
} else {
return this.returnNow(result);
}
}
}
parseIntegerBin() {
if (isBit(this.char)) {
this.consume();
} else if (this.char === CHAR_LOWBAR) {
return this.call(this.parseNoUnderHexOctBinLiteral);
} else {
const result = Integer(this.state.buf);
if (result.isNaN()) {
throw this.error(new TomlError("Invalid number"));
} else {
return this.returnNow(result);
}
}
}
/* DATETIME */
parseDateTime() {
if (this.state.buf.length < 4) {
throw this.error(new TomlError("Years less than 1000 must be zero padded to four characters"));
}
this.state.result = this.state.buf;
this.state.buf = "";
return this.next(this.parseDateMonth);
}
parseDateMonth() {
if (this.char === CHAR_HYPHEN) {
if (this.state.buf.length < 2) {
throw this.error(new TomlError("Months less than 10 must be zero padded to two characters"));
}
this.state.result += "-" + this.state.buf;
this.state.buf = "";
return this.next(this.parseDateDay);
} else if (isDigit(this.char)) {
this.consume();
} else {
throw this.error(new TomlError("Incomplete datetime"));
}
}
parseDateDay() {
if (this.char === CHAR_T || this.char === CHAR_SP) {
if (this.state.buf.length < 2) {
throw this.error(new TomlError("Days less than 10 must be zero padded to two characters"));
}
this.state.result += "-" + this.state.buf;
this.state.buf = "";
return this.next(this.parseStartTimeHour);
} else if (this.atEndOfWord()) {
return this.returnNow(createDate(this.state.result + "-" + this.state.buf));
} else if (isDigit(this.char)) {
this.consume();
} else {
throw this.error(new TomlError("Incomplete datetime"));
}
}
parseStartTimeHour() {
if (this.atEndOfWord()) {
return this.returnNow(createDate(this.state.result));
} else {
return this.goto(this.parseTimeHour);
}
}
parseTimeHour() {
if (this.char === CHAR_COLON) {
if (this.state.buf.length < 2) {
throw this.error(new TomlError("Hours less than 10 must be zero padded to two characters"));
}
this.state.result += "T" + this.state.buf;
this.state.buf = "";
return this.next(this.parseTimeMin);
} else if (isDigit(this.char)) {
this.consume();
} else {
throw this.error(new TomlError("Incomplete datetime"));
}
}
parseTimeMin() {
if (this.state.buf.length < 2 && isDigit(this.char)) {
this.consume();
} else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
this.state.result += ":" + this.state.buf;
this.state.buf = "";
return this.next(this.parseTimeSec);
} else {
throw this.error(new TomlError("Incomplete datetime"));
}
}
parseTimeSec() {
if (isDigit(this.char)) {
this.consume();
if (this.state.buf.length === 2) {
this.state.result += ":" + this.state.buf;
this.state.buf = "";
return this.next(this.parseTimeZoneOrFraction);
}
} else {
throw this.error(new TomlError("Incomplete datetime"));
}
}
parseOnlyTimeHour() {
if (this.char === CHAR_COLON) {
if (this.state.buf.length < 2) {
throw this.error(new TomlError("Hours less than 10 must be zero padded to two characters"));
}
this.state.result = this.state.buf;
this.state.buf = "";
return this.next(this.parseOnlyTimeMin);
} else {
throw this.error(new TomlError("Incomplete time"));
}
}
parseOnlyTimeMin() {
if (this.state.buf.length < 2 && isDigit(this.char)) {
this.consume();
} else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
this.state.result += ":" + this.state.buf;
this.state.buf = "";
return this.next(this.parseOnlyTimeSec);
} else {
throw this.error(new TomlError("Incomplete time"));
}
}
parseOnlyTimeSec() {
if (isDigit(this.char)) {
this.consume();
if (this.state.buf.length === 2) {
return this.next(this.parseOnlyTimeFractionMaybe);
}
} else {
throw this.error(new TomlError("Incomplete time"));
}
}
parseOnlyTimeFractionMaybe() {
this.state.result += ":" + this.state.buf;
if (this.char === CHAR_PERIOD) {
this.state.buf = "";
this.next(this.parseOnlyTimeFraction);
} else {
return this.return(createTime(this.state.result));
}
}
parseOnlyTimeFraction() {
if (isDigit(this.char)) {
this.consume();
} else if (this.atEndOfWord()) {
if (this.state.buf.length === 0) throw this.error(new TomlError("Expected digit in milliseconds"));
return this.returnNow(createTime(this.state.result + "." + this.state.buf));
} else {
throw this.error(new TomlError("Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z"));
}
}
parseTimeZoneOrFraction() {
if (this.char === CHAR_PERIOD) {
this.consume();
this.next(this.parseDateTimeFraction);
} else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
this.consume();
this.next(this.parseTimeZoneHour);
} else if (this.char === CHAR_Z) {
this.consume();
return this.return(createDateTime(this.state.result + this.state.buf));
} else if (this.atEndOfWord()) {
return this.returnNow(createDateTimeFloat(this.state.result + this.state.buf));
} else {
throw this.error(new TomlError("Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z"));
}
}
parseDateTimeFraction() {
if (isDigit(this.char)) {
this.consume();
} else if (this.state.buf.length === 1) {
throw this.error(new TomlError("Expected digit in milliseconds"));
} else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
this.consume();
this.next(this.parseTimeZoneHour);
} else if (this.char === CHAR_Z) {
this.consume();
return this.return(createDateTime(thi