/**
 * @module adaptive-expressions
 */
/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License.
 */

import { ANTLRErrorListener, Recognizer, RecognitionException } from 'antlr4ts';

/**
 * Error listener for Regex.
 */
export class RegexErrorListener implements ANTLRErrorListener<any> {
    static readonly Instance: RegexErrorListener = new RegexErrorListener();

    /**
     * Upon syntax error, notify any interested parties.
     *
     * @param _recognizer What parser got the error. From this object, you can access the context as well as the input stream.
     * @param _offendingSymbol Offending token in the input token stream, unless recognizer is a lexer, then it's null.
     * @param _line Line number in the input where the error occurred.
     * @param _charPositionInLine Character position within the line where the error occurred.
     * @param _msg Message to emit.
     * @param _e Exception generated by the parser that led to the reporting of an error.
     */
    syntaxError<T>(
        _recognizer: Recognizer<T, any>,
        _offendingSymbol: T,
        _line: number,
        _charPositionInLine: number,
        _msg: string,
        _e: RecognitionException | undefined,
    ): void {
        throw Error('Regular expression is invalid.');
    }
}
