java - check if method has comment with antlr -


changes java.g4

begining of file

grammar java;   @lexer::members {     public static final int whitespace = 1;     public static final int comments = 2; } 

end of file

// // whitespace , comments //  ws  :  [ \t\r\n\u000c]+ -> channel(whitespace) ;  // channel(1)  comment    :   '/*' .*? '*/' -> channel(comments)  ; // channel(2)  line_comment    :   '//' ~[\r\n]* -> channel(comments) ;   // channel(2) 

trying send comments , whitespace different channels done in book "the definitive antlr 4 reference" chapter 12.1 broadcasting tokens on different channels

upon executing antlr4 java.g4 following errors shown

java org.antlr.v4.tool java.g4     warning(155): java.g4:1017:35: rule ws contains lexer command unrecognized constant value; lexer interpreters may produce incorrect output     warning(155): java.g4:1019:40: rule comment contains lexer command unrecognized constant value; lexer interpreters may produce incorrect output     warning(155): java.g4:1021:45: rule line_comment contains lexer command unrecognized constant value; lexer interpreters may produce incorrect output 

i not see whats wrong?

you should replace following fragment:

@lexer::members {     public static final int whitespace = 1;     public static final int comments = 2; } 

with string:

channels { whitespace, comments } 

Comments