Something went wrong. Try again.
A parser and stringifier for the KDL Document Language bram.tngl.io/kdl
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142import {T_EOF} from "./parser/tokenize.js";
/** @import {Location, Token} from "./parser/token.js" */
/** * Error thrown when invalid KDL is encountered */export class InvalidKdlError extends Error { /** * @hidden */ name = "InvalidKdlError";
/** * The location of the start of the error, if it can be tied to a single location * * @readonly * @type {Location=} */ start;
/** * The location of the end of the error, if it can be tied to a single location * * @readonly * @type {Location=} */ end;
/** * Token tied to the error, if it can be tied to a single token * * @readonly * @type {Token=} */ token;
/** * Collection of more specific errors * * If this property is present, then the message of this error will be something generic and * the errors in this property will contain more useful information. * * @readonly * @type {InvalidKdlError[]=} */ errors;
/** * @param {string} message * @param {ErrorOptions & {token?: Token; start?: Location; end?: Location; errors?: InvalidKdlError[]}} [options] */ constructor( message, {token, start = token?.start, end = token?.end, errors, ...options} = {}, ) { if (token?.type === T_EOF) { message = `${message} at end of input`; } else if (start) { message = `${message} at ${start.line}:${start.column}`; }
super(message, options);
this.token = token; this.start = start; this.end = end; this.errors = errors; }
/** * Returns an iterable for the details of this error * * If this error contains more detailed errors, this iterable yields those detailed errors. * If this error doesn't have more detailed errors, this iterable yields this error itself. * * @returns {Generator<InvalidKdlError, void, void>} */ *flat() { if (this.errors == null) { yield this; return; }
for (const error of this.errors) { yield* error.flat(); } }}
export class InvalidKdlQueryError extends Error { /** * @hidden */ name = "InvalidKdlQueryError";
/** * The location of the start of the error, if it can be tied to a single location * * @readonly * @type {Location=} */ start;
/** * The location of the end of the error, if it can be tied to a single location * * @readonly * @type {Location=} */ end;
/** * Token tied to the error, if it can be tied to a single token * * @readonly * @type {Token=} */ token;
/** * @param {string} message * @param {ErrorOptions & {token?: Token; start?: Location; end?: Location}} [options] */ constructor( message, {token, start = token?.start, end = token?.end, ...options} = {}, ) { if (token?.type === T_EOF) { message = `${message} at end of input`; } else if (start) { message = `${message} at ${start.line}:${start.column}`; }
super(message, options);
this.token = token; this.start = start; this.end = end; }}