Grammar before moving tokens to a common file
lexer grammar ALexer;
COMMAND_START
: [a-zA-Z] -> pushMode(COMMAND_MODE)
;
EQUALS
: '=' -> pushMode(VALUE_MODE)
;
mode COMMAND_MODE;
COMMAND_NAME_REMAINDER
: ([a-zA-Z0-9_ ]? [a-zA-Z0-9])* -> popMode
;
mode VALUE_MODE;
IDENTIFIER
: A_Z ((UNDERSCORE | A_Z | DIGIT | WS)*? (UNDERSCORE | A_Z | DIGIT))* -> popMode
;
Grammar after moving tokens to a common file
Common lexer is imported by 3 other lexers. It has IDENTIFIER token which is shared.
lexer grammar CommonLexer;
..
..
IDENTIFIER
: A_Z ((UNDERSCORE | A_Z | DIGIT | WS)*? (UNDERSCORE | A_Z | DIGIT))*
;
The following lexer imports the Common lexer and has a few modes
lexer grammar ALexer;
import CommonLexer;
COMMAND_START
: [a-zA-Z] -> pushMode(COMMAND_MODE)
;
EQUALS
: '=' -> pushMode(VALUE_MODE)
;
mode COMMAND_MODE;
COMMAND_NAME_REMAINDER
: ([a-zA-Z0-9_ ]? [a-zA-Z0-9])* -> popMode
;
mode VALUE_MODE;
IDENTIFIER_VALUE_MODE
: IDENTIFIER -> type(IDENTIFIER), popMode
;
Parser grammar:
parser grammar AParser;
options { tokenVocab=ALexer; }
genericCommand
: COMMAND_START COMMAND_NAME_REMAINDER? (COLON parameterArray)?
;
Result: A command such as "Delete Resources: a;" which was earlier identified as COMMAND_START now is recognized as IDENTIFIER.
Question: How can I fix this? IDENTIFIER should remain in the CommonLexer.
Please let me know if you need more details, thanks.