Is there a way of defining a Lexer rule like:
DESCRIPTOR : 'INIT'(.)*'END';
So DESCRIPTOR returns the content between the two labels INIT and END?
I guess I can use return values, such as:
DESCRIPTOR returns [String content]
@init {
content="";
}: 'INIT'(.)*'END';
But I don’t get how I can access to such value.
Note that lexer rules (the ones start start with a capital) cannot have a
returnsclause, only parser rules can.But the rule:
works just fine. By default, ANTLR matches
.*and.+reluctantly (ungreedily), so the rule above matches “INIT” followed by zero or more chars until the first"END".EDIT
Ah, you want to strip the
"INIT"and"END"from the token. You can do that as follows:where
$textis short forgetText()(i.e. the entire string the token matched).