For example, I define several lexer rules in my Grammar:
INT: 'int';
FLOAT: 'float';
...
DIGIT : [0-9];
NUMERIC : (DIGIT+ | DIGIT+ '.' DIGIT+ | '.' DIGIT+ | DIGIT+ '.');
...
I need to somehow mark keywords ('int', 'float', and some other), that when I get tokens by using TokenStream I can filter them by some custom sign.
It is possible?
Right now I see only one way - unite necessary lexers into some rule.
Update
I try to apply the first option of the first answer below, but get the next problems: I get an error: 'TOKENNAME is not a recognized token name'
For this case was an issue. I apply recommendations from here:
use
options { tokenVocab = MyLexer; }
instead of
import MyLexer;
and get the error: 'error(114): MyParser.g4:3:23: cannot find tokens file .\MyLexer.tokens'
Here says, how I understand, that it's may happen when ANTLR source files (MyParser.g4, MyLexer.g4) is placed in the same directory where placed generated package. But I set a property of output file to another directory. Maybe I get some miss understanding...
Here is a small example.