Example usage for org.antlr.v4.runtime Recognizer getTokenFactory

List of usage examples for org.antlr.v4.runtime Recognizer getTokenFactory

Introduction

In this page you can find the example usage for org.antlr.v4.runtime Recognizer getTokenFactory.

Prototype

public abstract TokenFactory<?> getTokenFactory();

Source Link

Usage

From source file:edu.clemson.cs.rsrg.statushandling.AntlrLexerErrorListener.java

License:Open Source License

/**
 * <p>This is thrown when we encounter an syntax error when
 * parsing the input string.</p>/*from  ww  w.j  a va  2s  .  c  o m*/
 *
 * @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) {
    // Only do this if we have a ResolveTokenFactory
    if (recognizer.getTokenFactory() != null && recognizer.getTokenFactory() instanceof ResolveTokenFactory) {
        // Build a location
        ResolveTokenFactory tokenFactory = (ResolveTokenFactory) recognizer.getTokenFactory();
        myStatusHandler.error(new Location(tokenFactory.getFile(), line, charPositionInLine), msg);
    }
    // Otherwise simply return the raw string.
    else {
        myStatusHandler.error(null, "Line " + line + ":" + charPositionInLine + " " + msg);
    }
}