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

Luis Leal luisl at scarab.co.za
Sun Oct 23 06:52:40 PDT 2005


Hi Mark,

Is this your complete group file?

The following code test works correctly with \r\n for me:

StringReader sr = new StringReader("group TestOutput; program(statements)
::= << class Wrapper { <statements; separator=\"\r\n\"> } >>");
StringTemplateGroup stg = new StringTemplateGroup(sr,
typeof(antlr.stringtemplate.language.AngleBracketTemplateLexer));
ArrayList a = new ArrayList();
a.Add(1);
a.Add(2);
a.Add(3);
StringTemplate st = stg.getInstanceOf("program");
st.setAttribute("statements", a);
string s = st.ToString();
Console.WriteLine(s);

Regards

Luis

-----Original Message-----
From: Tech [mailto:tech at swingkid.fsnet.co.uk]
Sent: 22 October 2005 04:28 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Problem with carriage returns in c#
stringtemplate


Hi,

I am trying to create a C# StringTemplateGroup(v2.2) file containing the
following template

   group TestOutput;

   // Basic statements

   program(statements) ::= <<
   class Wrapper
   {
       <statements; separator="\r\n">
   }
    >>

I am reading this file in using the AngleBracketLexer (code in C#)

       Stream stgStream =
typeof(JavascriptParser).Assembly.GetManifestResourceStream("translator.csha
rp.stg");

       TextReader stgReader = new StreamReader(stgStream);
       StringTemplateGroup stg = new StringTemplateGroup(stgReader,
typeof(antlr.stringtemplate.language.AngleBracketTemplateLexer));

running this code gives the following error:

   StringTemplate: error: problem parsing template 'program': line
   3:34: unexpected char: 'r'


putting "\\r" instead puts '\r' in the output as text. "\n" on its own
is accepted, but I need a carriage return as well. How do I put carriage
returns as an attribute separator?

Thanks,

Mark


--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.12.4/146 - Release Date: 21/10/2005







More information about the antlr-interest mailing list