UNPKG

@qrvey/formula-lang

Version:

QFormula support for qrvey projects

121 lines 4.51 kB
import { ERROR_DICTIONARY, ERROR_LIST } from './dictionary'; export class BaseError extends Error { constructor(code, message, node) { super(message); this.code = code; this.message = message; this.node = node; this.code = code; this.node = node; } toString() { var _a, _b; if (this.node === undefined) { return `${this.code}: ${this.message}`; } else if ('name' in this.node) { return `${this.code}: ${this.message} ${(_a = this.node) === null || _a === void 0 ? void 0 : _a.name}`; } else if ('type' in this.node) { return `${this.code}: ${this.message} ${(_b = this.node) === null || _b === void 0 ? void 0 : _b.type}`; } return ''; } } export class GenericError extends BaseError { constructor(message = ERROR_DICTIONARY[ERROR_LIST.unknown].message) { super(ERROR_DICTIONARY[ERROR_LIST.unknown].code, message); } } export class FunctionError extends BaseError { constructor(node, errorDict) { super(errorDict.code, errorDict.message, node); this.node = node; } } export class UnknownFunctionError extends FunctionError { constructor(node) { super(node, ERROR_DICTIONARY[ERROR_LIST.unknownFunction]); this.node = node; } } export class ArgumentError extends FunctionError { constructor(node, errorDict) { super(node, errorDict); this.node = node; } } export class ArgumentValidatorError extends FunctionError { constructor(node, validator) { var _a, _b; super(node, { message: (_a = validator.message) !== null && _a !== void 0 ? _a : '', code: (_b = validator.code) !== null && _b !== void 0 ? _b : ERROR_LIST.unknown, }); this.node = node; this.validator = validator; } } export class MissingArgumentError extends ArgumentError { constructor(node, parameter, argumentIndex) { super(node, ERROR_DICTIONARY[ERROR_LIST.missingArg]); this.node = node; this.parameter = parameter; this.argumentIndex = argumentIndex; } toString() { return `${this.code}: ${this.message} ${this.parameter.identifier}`; } } export class MissingParenthesisError extends BaseError { constructor(node) { super(ERROR_DICTIONARY[ERROR_LIST.missingParenthesis].code, ERROR_DICTIONARY[ERROR_LIST.missingParenthesis].message, node); this.node = node; } } export class UnknownTokenError extends BaseError { constructor(node) { super(ERROR_DICTIONARY[ERROR_LIST.unknownToken].code, ERROR_DICTIONARY[ERROR_LIST.unknownToken].message, node); this.node = node; } } export class NotAllowedOperationError extends BaseError { constructor(node) { super(ERROR_DICTIONARY[ERROR_LIST.notAllowedOperation].code, ERROR_DICTIONARY[ERROR_LIST.notAllowedOperation].message, node); this.node = node; } get leftPrimitive() { var _a; return (_a = this.node.left) === null || _a === void 0 ? void 0 : _a.primitive; } get rightPrimitive() { var _a; return (_a = this.node.right) === null || _a === void 0 ? void 0 : _a.primitive; } } export class TooManyArgumentsError extends BaseError { constructor(node) { super(ERROR_DICTIONARY[ERROR_LIST.tooManyArguments].code, ERROR_DICTIONARY[ERROR_LIST.tooManyArguments].message, node); this.node = node; } } export class InvalidArgumentError extends BaseError { constructor(node, validatorResponse, argumentIndex) { super((validatorResponse === null || validatorResponse === void 0 ? void 0 : validatorResponse.code) || '', (validatorResponse === null || validatorResponse === void 0 ? void 0 : validatorResponse.message) || '', node); this.node = node; this.validatorResponse = validatorResponse; this.argumentIndex = argumentIndex; } } export class InferredPrimitiveError extends BaseError { constructor(expression) { super(ERROR_DICTIONARY[ERROR_LIST.inferredPrimitive].code, ERROR_DICTIONARY[ERROR_LIST.inferredPrimitive].message, expression); this.expression = expression; } } export class CircularDependencyError extends BaseError { constructor() { super(ERROR_DICTIONARY[ERROR_LIST.circularDependency].code, ERROR_DICTIONARY[ERROR_LIST.circularDependency].message); } } //# sourceMappingURL=definitions.js.map