diff options
Diffstat (limited to 'cmake/elfinfo/src/main/test/io/trygvis/ld/SystemOutReportingErrorListener.java')
-rw-r--r-- | cmake/elfinfo/src/main/test/io/trygvis/ld/SystemOutReportingErrorListener.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cmake/elfinfo/src/main/test/io/trygvis/ld/SystemOutReportingErrorListener.java b/cmake/elfinfo/src/main/test/io/trygvis/ld/SystemOutReportingErrorListener.java new file mode 100644 index 0000000..c21a2e2 --- /dev/null +++ b/cmake/elfinfo/src/main/test/io/trygvis/ld/SystemOutReportingErrorListener.java @@ -0,0 +1,32 @@ +package io.trygvis.ld; + +import org.antlr.v4.runtime.BaseErrorListener; +import org.antlr.v4.runtime.RecognitionException; +import org.antlr.v4.runtime.Recognizer; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class SystemOutReportingErrorListener extends BaseErrorListener { + @Nullable + private final String input; + + public SystemOutReportingErrorListener(@Nonnull String input) { + this.input = input; + } + + public SystemOutReportingErrorListener() { + input = null; + } + + public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { + System.out.println("line " + line + ":" + charPositionInLine + " " + msg); + if (input != null) { + System.out.println(input); + for (int i = 1; i < charPositionInLine; i++) { + System.out.print(' '); + } + } + System.out.println('^'); + } +} |