[antlr-interest] Can lexer rules return values?

Gavin Lambert antlr at mirality.co.nz
Fri Feb 15 23:54:19 PST 2008


At 20:29 16/02/2008, Steve Bennett wrote:
 >I was sure I read something about lexer fragment rules being 
able
 >to return values, but it doesn't seem to work. My rule:

IIRC, there was some discussion that they ought to be able to, but 
I don't think they can at the moment, no.

I think you can use scopes (though I also recall some discussion 
that scopes didn't work in the lexer, but I think that was for a 
much older version), or failing that, some member variables.

 >fragment EXTENSION_TAG_OPEN returns [boolean selfclose=false]:
 >    LT EXTENSION_NAME (SPACE* ATTR)? SPACE* (SLASH
 >{$selfclose=true;})? GT
 >  ;

This is looking complicated enough (and with embedded whitespace 
to boot) that perhaps it ought to be in the parser instead.



More information about the antlr-interest mailing list