How to throw meaningful error on syntax or parsing error [duplicate]

家住魔仙堡 提交于 2020-03-28 07:06:50

问题


I have a grammar for parsing jcl

The jcl looks like below /*comment line //PR1290@ JOB (10),'ISPW COB SN900E'

lexer and parser is working perfectly fine. Suppose instead of // if jcl starts from / currently lexer is throwing 1:0 token recognition error at: '/P'

Parser will throw no viable alternative input R1290@ JOB

I am looking for throwing error similar to eclipse while editing.

public void Test(){
//test 
//}

Above will say syntax error insert } to complete method body..

Something similar to this I want to point out right error message saying "jcl lines should start with // "

Example jcl line is below //NAME Operationname parameter=parametervalue

If // is missing i want to throw saying line should start with // Operation name should be either JOB or PROC if keyword is missing then enter valid keyword parameter

and if any parameter is missing i want to point out that write meaning full message to user.

I am using antlr 4.7.2 version


回答1:


You can start with adding your own error listener ...

See https://learning.oreilly.com/library/view/the-definitive-antlr/9781941222621/f_0062.html

I find it enough but you will likely need more



来源:https://stackoverflow.com/questions/60652322/how-to-throw-meaningful-error-on-syntax-or-parsing-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!