[stringtemplate-interest] Fwd: [antlr-interest] Problem with carriage returns in c# stringtemplate

Terence Parr parrt at cs.usfca.edu
Mon Oct 24 12:48:10 PDT 2005


forwarded from antlr-interest...
Ter

Begin forwarded message:

> From: "Luis Leal" <luisl at scarab.co.za>
> Date: October 24, 2005 6:57:18 AM PDT
> To: <antlr-interest at antlr.org>
> Subject: RE: [antlr-interest] Problem with carriage returns in  
> c#    stringtemplate
> Reply-To: luisl at scarab.co.za
>
>
> Hi Mark,
>
> Some investigation has revealed the following:
>
> 1. When you use a string literal the template actually contains a  
> carriage
> return and a new line
> 2. When you read the template from an embedded resource the template
> contains "\r\n" instead of a carriage return and a new line
>
> The second case sends the lexer down a path where \r is not defined  
> as a
> valid escape character. I've just uploaded a new C# version to
> www.stringtemplate.org which fixes this problem.
>
> Regards
>
> Luis
>
> -----Original Message-----
> From: Tech [mailto:tech at swingkid.fsnet.co.uk]
> Sent: 23 October 2005 11:32 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Problem with carriage returns in c#
> stringtemplate
>
>
> Thanks for your reply Luis.
>
> No, this is not my whole template group, but I was trying to reduce  
> the
> problem. I agree with you that your code works. However, if you  
> copy the
> string into a text file (removing the escape characters from the
> quotation marks) and include it as an embedded resource, it doesn't  
> work!
>
>      //StringReader sr = new StringReader("group TestOutput;
>     program(statements)::= << class Wrapper { <statements;
>     separator=\"\r\n\"> } >>");
>      Stream s =
>     typeof(Class1).Assembly.GetManifestResourceStream 
> ("Project1.Test.stg");
>     StreamReader sr = new StreamReader(s);
>     StringTemplateGroup stg = new StringTemplateGroup(sr,
>     typeof(antlr.stringtemplate.language.AngleBracketTemplateLexer));
>
> where Test.stg contains
>
>     group TestOutput; program(statements)::= << class Wrapper {
>     <statements; separator="\r\n"> } >>
>
> I have tried copying the StreamReader contents into a string before
> constructing the StringTemplateGroup, but that doesn't help. It seems
> more like a .Net issue than a StringTemplate issue, but I can't figure
> it out. I wonder if it is an encoding thing?
>
> Always curious,
>
> Mark



More information about the stringtemplate-interest mailing list