[antlr-interest] StringTemplate does not work as expected using a simple string template group
Kim Slattery
slattery.kim at gmail.com
Thu Apr 28 10:42:48 PDT 2011
Sorry: incomplete thought. Every time, it translates it to simply:
<pack>
What am I not getting?
On Thu, Apr 28, 2011 at 12:41 PM, Kim Slattery <slattery.kim at gmail.com>wrote:
> I have been trying to parse this and translate it using a .stg file, and it
> does not work. Every time, it parses I have no idea what's going on.
> Help!?
>
> Hop.stg:
>
> group Hop;
> start(p) ::= "<pack>"
> package(name) ::= "packagedafdjk <name>"
> qualified_name(name) ::= "<name>"
>
>
> HopSymbolTableWalker.g:
>
> tree grammar HopSymbolTableWalker;
>
> options {
> tokenVocab=Hop;
> ASTLabelType=CommonTree;
> output = template;
> }
> ...
> start
> @after{$st = %start(p={$pack.text});}
> : (pack = package_rule ref = reference+ // -> start(pack={$
> pack.st})
> | ref = reference+ pack = package_rule
> | pack = package_rule // -> start(pack={$
> pack.st})
> | ref = reference+
> | )
> cl = class_declaration EOF //Declaring a class name
> ;
>
> package_rule
> @after{$st = %package(name={$qn.text});}
> : PACKAGE_NAME qn=qualified_name
> {
> thisPackage = $qn.type;
> }
> ;
>
> qualified_name returns [QualifiedNameDescriptor type]
> @after {$st = %{result};}
> @init {
> String result = "";
> }
> : ^(QUALIFIED_NAME ids+= ID (PERIOD ids+=ID)*)
> {
> QualifiedNameDescriptor t = new QualifiedNameDescriptor();
> t.setLineBegin(((CommonTree)$ids.get(0)).token.getLine());
>
> t.setColumnBegin(((CommonTree)$ids.get(0)).token.getCharPositionInLine());
> /*t.setNameFromList($ids);
> */
> String name = "";
> Iterator it = $ids.iterator();
>
> while(it.hasNext()) {
> name += ((CommonTree) it.next()).getText();
>
> if(it.hasNext()) {
> name += $PERIOD.text;
> }
>
> }
> t.setName(name);
>
> result = name;
>
> t.setLineEnd(((CommonTree)$ids.get($ids.size() - 1)).token.getLine());
> t.setColumnEnd(((CommonTree)$ids.get($ids.size() -
> 1)).token.getCharPositionInLine());
> $type = t;
> } //->
> qualified_name(name={result})
> ;
>
>
>
> Thanks for your ideas. I'm absolutely stuck.
>
> Kim
>
More information about the antlr-interest
mailing list