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

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -