I have the following Antlr grammar:
grammar MyGrammar;
doc : intro planet;
intro : 'hi';
planet : 'world';
MLCOMMENT
: '/*' ( options {greedy=false;} : . )* '*/' { $channel = HIDDEN; };
WHITESPACE : (
(' ' | '\t' | '\f')+
|
// handle newlines
( '\r\n' // DOS/Windows
| '\r' // Macintosh
| '\n' // Unix
)
)
{ $channel = HIDDEN; };
In the ANTLRWorks 1.2.3 interpreter, the inputs hi world
,hi/**/world
and hi /*A*/ world
work, as expected.
However, the input hiworld
, which shouldn't work, is also accepted.
How do I make hiworld
fail? How do I force at least one whitespace(or comment) between "hi" and "world"?
Note that I've used only MLCOMMENT and WHITESPACE in this example to simplify, but other kinds of comments would be supported.