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

Tech tech at swingkid.fsnet.co.uk
Mon Oct 24 23:39:08 PDT 2005


Thanks Luis,
                I've just tried downloading the patch, but the link is 
broken. Thanks for the explanation though, it's always good to know 
about these kinds of subtle differences.

Mark

Luis Leal wrote:

>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
>
>
>
>--
>No virus found in this outgoing message.
>Checked by AVG Free Edition.
>Version: 7.1.361 / Virus Database: 267.12.4/146 - Release Date: 21/10/2005
>
>
>
>
>
>
>
>
>  
>


-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.361 / Virus Database: 267.12.5/147 - Release Date: 24/10/2005




More information about the antlr-interest mailing list