"use strict";
var lang_extensions_1 = require("../lang/lang_extensions");
var utils_1 = require("../utils/utils");
var exceptions;
(function (exceptions) {
    // hacks to bypass no support for custom Errors in javascript/typescript
    function isRecognitionException(error) {
        var recognitionExceptions = [
            lang_extensions_1.functionName(MismatchedTokenException),
            lang_extensions_1.functionName(NoViableAltException),
            lang_extensions_1.functionName(EarlyExitException),
            lang_extensions_1.functionName(NotAllInputParsedException)];
        // can't do instanceof on hacked custom js exceptions
        return utils_1.contains(recognitionExceptions, error.name);
    }
    exceptions.isRecognitionException = isRecognitionException;
    function MismatchedTokenException(message, token) {
        this.name = lang_extensions_1.functionName(MismatchedTokenException);
        this.message = message;
        this.token = token;
        this.resyncedTokens = [];
    }
    exceptions.MismatchedTokenException = MismatchedTokenException;
    // must use the "Error.prototype" instead of "new Error"
    // because the stack trace points to where "new Error" was invoked"
    MismatchedTokenException.prototype = Error.prototype;
    function NoViableAltException(message, token) {
        this.name = lang_extensions_1.functionName(NoViableAltException);
        this.message = message;
        this.token = token;
        this.resyncedTokens = [];
    }
    exceptions.NoViableAltException = NoViableAltException;
    NoViableAltException.prototype = Error.prototype;
    function NotAllInputParsedException(message, token) {
        this.name = lang_extensions_1.functionName(NotAllInputParsedException);
        this.message = message;
        this.token = token;
        this.resyncedTokens = [];
    }
    exceptions.NotAllInputParsedException = NotAllInputParsedException;
    NotAllInputParsedException.prototype = Error.prototype;
    function EarlyExitException(message, token) {
        this.name = lang_extensions_1.functionName(EarlyExitException);
        this.message = message;
        this.token = token;
        this.resyncedTokens = [];
    }
    exceptions.EarlyExitException = EarlyExitException;
    EarlyExitException.prototype = Error.prototype;
})(exceptions = exports.exceptions || (exports.exceptions = {}));
