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

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -