The Definitive ANTLR 4 Reference

The Definitive ANTLR 4 Reference

I noticed that your UnderlineListener on page 156 is applied to only the parser. When I applied it to the lexer, it will not work, because unrecognized tokens cannot be cast to CommonTokenStream. But can we underline the offending token if it causes a lexer error? If yes, can you show us how? Thank you for your time and help.

This is really a question for the antlr discussion forum not the book but you can override a lexer error method I believe to get bad token events. You can see what I do for this in the antlr 4 plugin for intellij. see my github.com/antlr4 stuff