import { includes } from "lodash-es"; const MISMATCHED_TOKEN_EXCEPTION = "MismatchedTokenException"; const NO_VIABLE_ALT_EXCEPTION = "NoViableAltException"; const EARLY_EXIT_EXCEPTION = "EarlyExitException"; const NOT_ALL_INPUT_PARSED_EXCEPTION = "NotAllInputParsedException"; const RECOGNITION_EXCEPTION_NAMES = [ MISMATCHED_TOKEN_EXCEPTION, NO_VIABLE_ALT_EXCEPTION, EARLY_EXIT_EXCEPTION, NOT_ALL_INPUT_PARSED_EXCEPTION, ]; Object.freeze(RECOGNITION_EXCEPTION_NAMES); // hacks to bypass no support for custom Errors in javascript/typescript export function isRecognitionException(error) { // can't do instanceof on hacked custom js exceptions return includes(RECOGNITION_EXCEPTION_NAMES, error.name); } class RecognitionException extends Error { constructor(message, token) { super(message); this.token = token; this.resyncedTokens = []; // fix prototype chain when typescript target is ES5 Object.setPrototypeOf(this, new.target.prototype); /* istanbul ignore next - V8 workaround to remove constructor from stacktrace when typescript target is ES5 */ if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } } } export class MismatchedTokenException extends RecognitionException { constructor(message, token, previousToken) { super(message, token); this.previousToken = previousToken; this.name = MISMATCHED_TOKEN_EXCEPTION; } } export class NoViableAltException extends RecognitionException { constructor(message, token, previousToken) { super(message, token); this.previousToken = previousToken; this.name = NO_VIABLE_ALT_EXCEPTION; } } export class NotAllInputParsedException extends RecognitionException { constructor(message, token) { super(message, token); this.name = NOT_ALL_INPUT_PARSED_EXCEPTION; } } export class EarlyExitException extends RecognitionException { constructor(message, token, previousToken) { super(message, token); this.previousToken = previousToken; this.name = EARLY_EXIT_EXCEPTION; } } //# sourceMappingURL=exceptions_public.js.map