[antlr-interest] HELP: Escape sequences and string template

Loring Craymer lgcraymer at yahoo.com
Fri Aug 15 17:03:37 PDT 2008


Actually, on looking at the ST grammars, it appears that \" is given special handlng in the lexer and there is no way to have a template output the character sequence \".  Since backslashes are processed only by the ST lexer and not during intermediate processing, maybe ST should recognize <\> (or something similar) as an output backslash.  This might help for other escape sequences, as well, although ST seems to do the "right thing" most of the time.
--Loring



----- Original Message ----
> From: Johannes Luber <jaluber at gmx.de>
> To: Foust <javafoust at gmail.com>
> Cc: antlr-interest at antlr.org
> Sent: Friday, August 15, 2008 4:06:46 PM
> Subject: Re: [antlr-interest] HELP: Escape sequences and string template
> 
> Foust schrieb:
> > Ramanand ,
> > 
> > Another way to deal with the backslash issue is to use forward slashes until
> > the final output phase, at which time they can be replaced with backslashes.
> > Maybe it would be useful for StringTemplate to support character sequence
> > replacement...
> > 
> > But depending upon how the strings are being used in your Java code, you may
> > be able to architect it so that you can translate them at runtime.
> > 
> > That may be unnecessary, however, since Java's File class handles forward
> > slashes, even under Windows.
> > 
> > Brent
> 
> Windows does accept forward slashes instead backslashes anyway, only the 
> path completion doesn't work with forward slashes.
> 
> Johannes
> 
> > Ramanand wrote:
> >> Hi!
> >>
> >> On Aug 15, 2008, at 10:33 PM, Ramanand Mandayam wrote:
> >>
> >>> However the output of the string template processing phase deletes
> >>> the first '\' and prints only the second one. When the generated
> >>> code is processed as a JAVA file the compiler (as it should)
> >>> generates errors complaining about invalid unicode characters.
> >>>
> >>> Does the string template process need some special treatment when
> >>> dealing with '\' characters.
> >>
> >> Classical double escape issue: If you are always going to print that
> >> string, double escape it (i.e. escape each \ to \\) in the lexer rule.
> >> It's ugly, but most likely the only way.
> >>
> >> cheers,
> >> -k
> >> --
> >> Kay Röpke
> >> http://classdump.org/
> >>
> >>
> >>
> >>
> > 
> > 



      



More information about the antlr-interest mailing list