antlr4 - Correct way to address wrong grammar in ANTLR -


i use antlr parse programming language. according antlr book (chapter 9.4) implemented "error alternatives". easy implementation described in book notifying error listener:

..... | id '{' expr '}' '}' {notifyerrorlisteners("too many braces");} ..... 

after reading book thought easier implement notifications listeners wrote in baselistener:

public void exitexprerror(@notnull myparser.exprerrorcontext ctx) {          parser.notifyerrorlisteners(ctx.start, "too many braces", null);  } 

in listener can extract start , stop token context gives me finer grained control mark error (ctx.start).

however listener in grammar file simplier , faster implement listener.

my question is:

is possible add arguments listener in grammar file?

something like:

.....     | id '{' expr '}' '}' {notifyerrorlisteners(ctx.start,"too many braces");} ..... 


Comments

Popular posts from this blog

Python Kivy ListView: How to delete selected ListItemButton? -

asp.net mvc 4 - A specified Include path is not valid. The EntityType '' does not declare a navigation property with the name '' -