问题
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