/*
 * AntlrLexerErrorListener.java
 * ---------------------------------
 * Copyright (c) 2017
 * RESOLVE Software Research Group
 * School of Computing
 * Clemson University
 * All rights reserved.
 * ---------------------------------
 * This file is subject to the terms and conditions defined in
 * file 'LICENSE.txt', which is part of this source code package.
 */
package edu.clemson.cs.rsrg.statushandling;

import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;

/**
 * <p>A custom listener class for the compiler that reports lexer errors.</p>
 *
 * @author Yu-Shan Sun
 * @version 1.0
 */
public class AntlrLexerErrorListener extends BaseErrorListener {

    // ==========================================================
    // Member Fields
    // ==========================================================

    /**
     * <p>This is the status handler for the RESOLVE compiler.</p>
     */
    private final StatusHandler myStatusHandler;

    // ==========================================================
    // Constructors
    // ==========================================================

    /**
     * <p>This creates an ANTLR4 error listener with the current
     * error handler deployed by the compiler.</p>
     *
     * @param statusHandler An status handler to display debug or error messages.
     */
    public AntlrLexerErrorListener(StatusHandler statusHandler) {
        myStatusHandler = statusHandler;
    }

    // ===========================================================
    // Public Methods
    // ===========================================================

    /**
     * <p>This is thrown when we encounter an syntax error when
     * parsing the input string.</p>
     *
     * @param recognizer A recognizer provided by the ANTLR4.
     * @param offendingSymbol The offending token.
     * @param line The line number where the error occurred.
     * @param charPositionInLine The position in the line where the error occurred.
     * @param msg The message to be displayed.
     * @param e The exception thrown.
     */
    @Override
    public final void syntaxError(Recognizer<?, ?> recognizer,
            Object offendingSymbol, int line, int charPositionInLine,
            String msg, RecognitionException e) {
        myStatusHandler.error(null, "line " + line + ":" + charPositionInLine
                + " " + msg);
    }

}
@@ -406,16 +406,127 @@
 dling;%0A%0A
+import edu.clemson.cs.rsrg.parsing.data.Location;%0Aimport edu.clemson.cs.rsrg.parsing.data.ResolveTokenFactory;%0A
 import o
@@ -2457,58 +2457,435 @@
     
-myStatusHandler.error(null
+// Only do this if we have a ResolveTokenFactory%0A        if (recognizer.getTokenFactory() != null%0A                && recognizer.getTokenFactory() instanceof ResolveTokenFactory) %7B%0A            // Build a location%0A            ResolveTokenFactory tokenFactory =%0A                    (ResolveTokenFactory) recognizer.getTokenFactory();%0A            myStatusHandler.error(new Location(tokenFactory.getFile()
 , 
-%22
 line
- %22 + line + %22:%22 +
+,%0A                   
  cha
@@ -2899,16 +2899,24 @@
 onInLine
+), msg);
 %0A       
@@ -2916,24 +2916,26 @@
         
+%7D%0A
         
 + %22 %22 + 
@@ -2926,16 +2926,176 @@
         
+// Otherwise simply return the raw string.%0A        else %7B%0A            myStatusHandler.error(null, %22Line %22 + line + %22:%22%0A                    + charPositionInLine 
 + %22 %22 + 
@@ -3096,20 +3096,30 @@
 %22 %22 + msg);%0A
+        %7D%0A
     %7D%0A%0A%7D

Create a location if possible