Hi everyone,
I want to use if else in the StringTemplateGroup,if (x ="org") print 1234 else
print 5678, but <if(x=="org")> doesnot work.
tree grammar Treegrammar;
.....
importDeclaration
: ^(IMPORT_DECL importDeclarationTypeElement)
->assgin(x={$importDeclarationTypeElement.text})
;
.....
group T;
assgin(x)::= <<
<if(x=="org")><"1234"><else><"5678"><endif>
>>
Then I use the following, but it never replace.
In tree grammar Treegrammar, I add :
@members{
private StringTemplate template(String name)
{
return TestASTBlockStatement.templates.getInstanceOf(name);
}
}
TestASTBlockStatement.java is as follows:
public static StringTemplateGroup templates;
public class TestASTBlockStatement extends BaseTestCase {
public static StringTemplateGroup templates;
public void testNormal1() throws Exception {
FileReader groupFileR= new FileReader("T.stg");
templates= new StringTemplateGroup(groupFileR);
groupFileR.close();
CharStream input = new ANTLRFileStream("TestASTBlockStatment_testcase001");
ActionScript3Lexer lex = new ActionScript3Lexer(input);
ASTokenRewriteStream tokens = new ASTokenRewriteStream(lex);
ActionScript3Parser parser = new ActionScript3Parser(tokens);
parser.setTreeAdaptor(new ASCommonTreeAdaptor());
packageDeclaration_return retval=parser.packageDeclaration();
ASCommonTree tree = (ASCommonTree) retval.getTree();
ASCommonTreeNodeStream nodes = new ASCommonTreeNodeStream(tree);
nodes.setTokenStream(tokens);
Treegrammar walker = new Treegrammar(nodes);
walker.setTemplateLib(templates);
Treegrammar.packageDeclaration_return r2= walker.packageDeclaration() ;
System.out.println(tokens.toString());
}
and in the tree grammar Treegrammar;
importDeclaration returns [StringTemplate code]
: ^(IMPORT_DECL a=importDeclarationTypeElement)
{if($a.text.equals("org"))
{StringTemplate code=null;
code=template("assgin");
code.setAttribute("x",a);
}
;
There are no error but it does not work.
Any idea?
Thanks in advance.
Annie
_________________________________________________________________
怎样买车票更方便?微软春节搜索,第一时间为您提供火车票信息!
http://piao.live.com/?form=PANER01
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address