[antlr-interest] Lexing colons again (consume and getColumn)

Anthony Youngman Anthony.Youngman at ECA-International.com
Fri May 14 04:23:03 PDT 2004


Two little bits of lexer ...

NUMBER_LITERAL	: {getColumn() == 1}? INT {if (LA(1) == ':')
consume();_ttype = LABEL;}
			| ( INT (DECIMAL (INT)?)? | DECIMAL INT ) ;

and

IDENT
	: ( ALPHA ( ALPHA|NUMERIC|'.'|'$'|'%'|'_')* )
		{
			if (state == STATEMENT) {
            if (LA(1) == ':' && getColumn() == 1) {
					int len=text.length();
					consume();
					text.setLength(len);
					_ttype = LABEL;
               state = STATEMENT;

In both cases, having tested for the colon, I want to throw it away, as
it is sometimes optional (even after IDENT!) so best ignored. "consume"
seems to add it to the token currently being processed. What do I call
instead?

And for IDENT, I want to get the token's starting column. I thought
"getColumn" was wrong (it feels wrong and doesn't seem to work), so is
there a $getColumn, and is that what I'm looking for?

Note to Ter - reading the lexer section of the manual, getColumn is only
mentioned in passing, and while there's a table of various functions,
the fact that getColumn is missing means it's obviously incomplete. Is
there other stuff missing?

Cheers,
Wol


****************************************************************************

This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.

****************************************************************************



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list