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

Luis Leal luisl at scarab.co.za
Mon Oct 24 06:57:18 PDT 2005


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







More information about the antlr-interest mailing list