[antlr-interest] lexer: embedded quotes assistance

Edwards, Waverly Waverly.Edwards at genesys.com
Fri Aug 24 14:56:34 PDT 2007


>>>
Well, by the first definition (that permits embedded NEWLINEs), the only
way a string could possibly be unterminated is if an EOF occurs before
the final quote -- in which case it should throw some kind of
RecognitionException, because it can't match the final quote.
<<<

I intentionally left out the closing quote to see what would happen.  I
got an error message, but have forgotten what it was.  I was looking to
see how to intercept the existing error message for one that works
better for me.

>>>
If embedded NEWLINEs are only permitted following the line continuation
character, then you really should add that to the rule the way I
described, to avoid having typos make strings consume the remainder of
the file.
<<<

Ah, I see what you mean.

>>... Doesn't Java have a "replace all" function already?

I looked and didn't find one.  I had to work for that one a little
didn't I?
It would definitely make for shorter, prettier code.


Thanks,


W.

-----Original Message-----
From: Gavin Lambert [mailto:antlr at mirality.co.nz] 
Sent: Friday, August 24, 2007 5:42 PM
To: Edwards, Waverly; antlr
Subject: RE: [antlr-interest] lexer: embedded quotes assistance

At 04:23 25/08/2007, Edwards, Waverly wrote:
 >I haven't figured out how to get ANTLR to tell me the string is
>unterminated but I will.

Well, by the first definition (that permits embedded NEWLINEs), the only
way a string could possibly be unterminated is if an EOF occurs before
the final quote -- in which case it should throw some kind of
RecognitionException, because it can't match the final quote.

If embedded NEWLINEs are only permitted following the line continuation
character, then you really should add that to the rule the way I
described, to avoid having typos make strings consume the remainder of
the file.


I'm also a little surprised at how involved your replace calls are.
Doesn't Java have a "replace all" function already?



More information about the antlr-interest mailing list