I have the following ANTLR (version 3) grammar:
grammar GRM;
options
{
language = C;
output = AST;
}
create_statement : CREATE_KEYWORD SPACE_KEYWORD FILE_KEYWORD SPACE_KEYWORD value -> ^(value);
value : NUMBER | STRING;
CREATE_KEYWORD : 'CREATE';
FILE_KEYWORD : 'FILE';
SPACE_KEYWORD : ' ';
NUMBER : DIGIT+;
STRING : (LETTER | DIGIT)+;
fragment DIGIT : '0'..'9';
fragment LETTER : 'a'..'z' | 'A'..'Z';
With this grammar, I am able to successfully parse strings like CREATE FILE dump
or CREATE FILE output
. However, when I try to parse a string like CREATE FILE file
it doesn't work. ANTLR matches the text file
(in the string) with lexer rule FILE_KEYWORD
which is not the match that I was expecting. I was expecting it to match with lexer rule STRING
.
How can I force ANTLR to do this?