This is my trimmed down ANTLR4 grammar (note I'm using a constant false to replace my method that returns false ):
grammar AnnotProcessor;
cppCompilationUnit: content+ EOF;
content: anything
| {false}? .;
anything: ANY_CHAR;
ANY_CHAR: [_a-zA-Z0-9];
My test file contains only 1 word "hello" and the test results are like these:
D:\work\antlr4\work>java org.antlr.v4.runtime.misc.TestRig AnnotProcessor cppCompilationUnit -tree in.cpp
line 1:5 no viable alternative at input '<EOF>'
(cppCompilationUnit (content (anything h)) (content (anything e)) (content (anything l)) (content (anything l)) (content (anything o)))
D:\work\antlr4\work>java org.antlr.v4.runtime.misc.TestRig AnnotProcessor cppCompilationUnit -tokens in.cpp
[@0,0:0='h',<1>,1:0]
[@1,1:1='e',<1>,1:1]
[@2,2:2='l',<1>,1:2]
[@3,3:3='l',<1>,1:3]
[@4,4:4='o',<1>,1:4]
[@5,5:4='<EOF>',<-1>,1:5]
line 1:5 no viable alternative at input '<EOF>'
Why it keeps saying "line 1:5 no viable alternative at input '< EOF >'" when I add a semantic predicate (although a dummy here) as an alternative? If I remove the alternative with the false semantic predicate, the error disappears as expected.
PS: I'm using antlr-4.0-complete.jar