[antlr-interest] Problem w/ string rule

Anthony Youngman Anthony.Youngman at ECA-International.com
Thu May 20 01:33:31 PDT 2004


Ummm ...

Just a quickie (I've been reading the ANTLR manual :-) and the language
I'm implementing can use ", ', or \ as the string delimiter.

Might it be an idea to have two rules

STRINGDATA : (options {greedy=false;} : (.)* ) ;
STRING : '"' STRINGDATA '"'
       | '\'' STRINGDATA '\''
       | '\\' STRINGDATA '\\'
       ;

And (given that I've been reading the ESC stuff :-) I presume if my
STRINGDATA looked for things like \r or \t, then the "greedy=false" bit
of stringdata would mean that the third option for STRING would eat the
\ before the ESC would see it?

(This is more as info for me and hints to chiplastique than a current
need for a definitive answer - I can always experiment :-)

Cheers,
Wol

-----Original Message-----
From: chiplastique [mailto:jeremyj at imtc.gatech.edu] 
Sent: 19 May 2004 23:18
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Problem w/ string rule

I have the following simple lexer rule for identifying strings:

STRING
	:	'"' (~'"')* '"'
	;

This rule should recognize any sequence of characters enclosed by 
double quotes.  However, I've discovered that strings including 
certain punctuation characters such as '\', '`', or ';' cause ANTLR 
to throw a TokenStreamRecognitionException in the STRING rule.

Is this a bug or am I doing something wrong?  I'm using the 2.7.2 
runtime for C#.

Thanks!



 
Yahoo! Groups Links



 





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

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 8272 5300, 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