Hi Folks,
I have been experimenting with import and tokenVocab. Here's what I have discovered:
1. A lexer grammar can reuse another lexer grammar using the import statement.
2. A lexer grammar cannot reuse another lexer grammar using the tokenVocab option.
3. A parser grammar cannot reuse a lexer grammar using the import statement.
4. A parser grammar can reuse a lexer grammar using the tokenVocab option.
5. The prefix of the filename for the parser and the lexer(s) must be the same. I have adopted this convention for naming parsers: AParser.g4. I name all lexers this way: ALexer.g4, ALexer2.g4, ALexer3.g4, etc.
Here are my conclusions:
a. To reuse a lexer grammar, a parser grammar must use this: options { tokenVocab=ALexer; }
b. To reuse another lexer grammar, a lexer grammar must use this: import ALexer2;
c. The filename prefix of all lexers and parser must be identical.
If I err in any of my statements, please let me know.
/Roger