java - Determining whether string complies with ANTLR4 grammar -



java - Determining whether string complies with ANTLR4 grammar -

how can test string against grammar see whether it's valid (i.e. no errors found, , no error recovery necessary)?

i've tried this a custom error strategy i'm still getting messages like

line 1:2 token recognition error at: 'x'

on console. need either way ensure errors result in exceptions, or way validate input doesn't rely on exceptions.

edit: seeing lexer error, not parser error. need update lexer ensure lexer incapable of failing match input character adding next lastly rule of lexer. pass erroneous character on parser handling (reporting, recovery, etc.).

err_char : . ;

in add-on this, need perform general steps below apply configuring parser simple string recognition.

you need 2 things work properly:

first, disable default error reporting mechanism(s).

parser.removeerrorlisteners();

second, disable default error recovery mechanism(s).

parser.seterrorstrategy(new bailerrorstrategy());

you'll parsecancellationexception, , no other reporting, if string not match.

if aren't using output parse operation, may wish improve efficiency of recognition process disabling parse tree construction.

parser.setbuildparsetree(false);

java validation antlr4

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -