antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

[C#] Errors shouldn't be written to console error

Open lextm opened this issue 2 years ago • 2 comments

There are several places in ANTLR runtime that errors are written to console error, like this.

While that looks harmless in most applications (GUI based, or web apps for example), it is annoying in console apps, as those ANTLR errors are written in their own pattern, with no (easy) way to disable or customize.

Any plan to revise the current design?

(Originally posted at https://github.com/tunnelvisionlabs/antlr4cs/issues/368)

lextm avatar Sep 09 '23 23:09 lextm

Well that particularly one should never happen, it's there to report an unknown exception type... But if it's in the way, it's easy to set your own error strategy on the parser, as follows:

parser.ErrorStrategy = new MyErrorStrategy();

You can achieve the same with error listeners.

ericvergnaud avatar Sep 10 '23 08:09 ericvergnaud

Hey @ericvergnaud, do you have an example repo for reference for various things that can be done with ErrorStrategy ? thanks!

neilscallywag avatar Feb 19 '25 09:02 neilscallywag