[antlr-interest] Help: A simple string template question..
sarim
ssiddiqu at yahoo.com
Thu Jul 19 17:04:54 PDT 2007
Thanks much for the reply.
I actually had "\n" in the importdef() before as follows:
$import;separator=";\n"$
but that requires me to set:
query.setAttribute("import","import java.util.*");
query.setAttribute("import","import java.io.*");
I wanted to move the string "import" into the template definition so that I can only do:
query.setAttribute("import","java.util.*");
query.setAttribute("import","java.io.*");
Something like:
$prefix="import";import;separator=";\n"$
Is there a way to achieve this?
Thanks.
--Sarim.
Terence Parr <parrt at cs.usfca.edu> wrote:
On Jul 19, 2007, at 11:50 AM, sarim wrote:
>
>
> sarim wrote:
> Hi,
> I am new to StringTemplate. I have the following template:
> ************************
> group RuleTemplate;
> fulldef(package,import,rulename) ::= <<$packagedef()$
> $importdef(); separator="\n"$
This is doing a \n after the call. The call emits the improts. move
the \n into the importdef template.
Ter
*********************** ORIGINAL QUESTION ****************************************
Hi,
I am new to StringTemplate. I have the following template:
************************
group RuleTemplate;
fulldef(package,import,rulename) ::= <<$packagedef()$
$importdef(); separator="\n"$
$rulestart()$
>>
packagedef()::="package $package$"
importdef()::=<<
import $import$
>>
rulestart()::="rule $rulename$ "
********************
Here is how I am calling it:
String fileName="RuleTemplate.st";
try
{
StringTemplateGroup group = new StringTemplateGroup(new BufferedReader( new FileReader(new File (fileName ))),DefaultTemplateLexer.class);
StringTemplate query = group.getInstanceOf("fulldef");
query.setAttribute("package","org.com");
query.setAttribute("import","java.util.*");
query.setAttribute("import","java.io.*");
query.setAttribute("rulename","myfirstrule");
System.out.println(query);
....
*************************************
There are no errors and I see the following output:
***********************************
package org.com
import java.util.*java.io.*
rule myfirstrule
*****************************
I want to get:
package org.com
import java.util.*
import java.io.*
rule myfirstrule
How should I change my template so that I can get the desired output? Why is the "separator" not taking effect?
Thanks.
--Sarim.
---------------------------------
Building a website is a piece of cake.
Yahoo! Small Business gives you all the tools to get online.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070719/c675b76b/attachment.html
More information about the antlr-interest
mailing list