UNPKG

@qrvey/formula-lang

Version:

QFormula support for qrvey projects

138 lines 6.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CircularDependencyError = exports.InferredPrimitiveError = exports.InvalidArgumentError = exports.TooManyArgumentsError = exports.NotAllowedOperationError = exports.UnknownTokenError = exports.MissingParenthesisError = exports.MissingArgumentError = exports.ArgumentValidatorError = exports.ArgumentError = exports.UnknownFunctionError = exports.FunctionError = exports.GenericError = exports.BaseError = void 0; const dictionary_1 = require("./dictionary"); 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 ''; } } exports.BaseError = BaseError; class GenericError extends BaseError { constructor(message = dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.unknown].message) { super(dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.unknown].code, message); } } exports.GenericError = GenericError; class FunctionError extends BaseError { constructor(node, errorDict) { super(errorDict.code, errorDict.message, node); this.node = node; } } exports.FunctionError = FunctionError; class UnknownFunctionError extends FunctionError { constructor(node) { super(node, dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.unknownFunction]); this.node = node; } } exports.UnknownFunctionError = UnknownFunctionError; class ArgumentError extends FunctionError { constructor(node, errorDict) { super(node, errorDict); this.node = node; } } exports.ArgumentError = ArgumentError; 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 : dictionary_1.ERROR_LIST.unknown, }); this.node = node; this.validator = validator; } } exports.ArgumentValidatorError = ArgumentValidatorError; class MissingArgumentError extends ArgumentError { constructor(node, parameter, argumentIndex) { super(node, dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.missingArg]); this.node = node; this.parameter = parameter; this.argumentIndex = argumentIndex; } toString() { return `${this.code}: ${this.message} ${this.parameter.identifier}`; } } exports.MissingArgumentError = MissingArgumentError; class MissingParenthesisError extends BaseError { constructor(node) { super(dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.missingParenthesis].code, dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.missingParenthesis].message, node); this.node = node; } } exports.MissingParenthesisError = MissingParenthesisError; class UnknownTokenError extends BaseError { constructor(node) { super(dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.unknownToken].code, dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.unknownToken].message, node); this.node = node; } } exports.UnknownTokenError = UnknownTokenError; class NotAllowedOperationError extends BaseError { constructor(node) { super(dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.notAllowedOperation].code, dictionary_1.ERROR_DICTIONARY[dictionary_1.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; } } exports.NotAllowedOperationError = NotAllowedOperationError; class TooManyArgumentsError extends BaseError { constructor(node) { super(dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.tooManyArguments].code, dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.tooManyArguments].message, node); this.node = node; } } exports.TooManyArgumentsError = TooManyArgumentsError; 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; } } exports.InvalidArgumentError = InvalidArgumentError; class InferredPrimitiveError extends BaseError { constructor(expression) { super(dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.inferredPrimitive].code, dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.inferredPrimitive].message, expression); this.expression = expression; } } exports.InferredPrimitiveError = InferredPrimitiveError; class CircularDependencyError extends BaseError { constructor() { super(dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.circularDependency].code, dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.circularDependency].message); } } exports.CircularDependencyError = CircularDependencyError; //# sourceMappingURL=definitions.js.map