[antlr-interest] StringTemplate does not work as expected using a simple string template group

Kim Slattery slattery.kim at gmail.com
Thu Apr 28 11:44:46 PDT 2011


Glaring syntax error in the above--I forgot to change the string template
for start to <p> from <pack>.  This shouldn't be the problem, but I'll let
you know if it is.

On Thu, Apr 28, 2011 at 12:54 PM, Terence Parr <parrt at cs.usfca.edu> wrote:

> if you get <...>That means that somehow ST is interpreting it using $...$
> not <...> I think. not sure why that would be.
> Ter
> On Apr 28, 2011, at 10:42 AM, Kim Slattery wrote:
>
> > 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
> >>
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>


More information about the antlr-interest mailing list