[stringtemplate-interest] How to access properties of an attribute of <first(multi-valued-attr)>

seitter.claus at muenchener-verein.de seitter.claus at muenchener-verein.de
Mon Feb 23 01:28:34 PST 2009


 
Hi Terence,
thank you very much for your hint. In the meantime, I found a solution that works fine for me. I now just pass in three lists in parallel (without a wrapping object) and apply a anonymous template to them:
entryMethod(once, cols1, cols2, cols3)::=<<
  void rule_r<first(col1)>(Map\<String, Attribut\> attrs, String id){
   <if(once)>
     rule_r<first(col1)>_default(attrs);
   <else>
       if(id.equals("<first(col3)>"))
       {
         rule_r<first(col1)>_<first(col2)>(attrs);
       }
     <rest(col1), rest(col2),rest(col3):{one,two,three|
  else if(id.equals("<three>")
  {
    rule_r<one>_<two>(attrs);
  }
}>
   <endif>
  }
>>

 

Best regards,

Claus <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


-----Ursprüngliche Nachricht-----
Von: Terence Parr [mailto:parrt at cs.usfca.edu]
Gesendet: Montag, 23. Februar 2009 03:20
An: Seitter Claus-Jochen
Cc: stringtemplate-interest at antlr.org
Betreff: Re: [stringtemplate-interest] How to access properties of an attribute of <first(multi-valued-attr)>



if everything is public then perhaps you're testing .one on some other object?  Perhaps an array of array not an array or something? 
Ter

On Feb 20, 2009, at 7:03 AM, < seitter.claus at muenchener-verein.de> wrote:


Hi all,
I just got stuck with the syntax of accessing properties of an attribut that is the result of an operation like <first(multi-valued-attr)>. My intention is to output text for java if clauses like
 
if(id.equals("a.b.c"))
{
    rule_a_b_c();
}
else if(id.equals("a.b.d"))
{
    rule_a_b_d();
 }

 

.....    .//many of them
 
else if(id.equals("a.b.z"))
{
    rule_a_b_z();
 }

 

here are my templates:

 

entryMethod(once, rows3cols)::=<<
  void rule_r<first(rows3cols).one>(Map\<String, Attribut\> attrs, String id){
   <if(once)>
     rule_r<first(rows3cols).one>_default(attrs);
   <else>
       if(id.equals("<first(rows3col).three>")
       {
         rule_r<first(rows3cols).one>_<first(rows3cols).two>(attrs);
       }
     <rest(rows3cols):entryIfs()>
   <endif>
  }
>>
entryIfs()::=<<
  else if(id.equals("<it.two>")
  {
    rule_r<it.one>_<it.three>(attrs);
  }
>>

 

the template is called from an antl3 tree parser:
//--------------------------------------------------------------------------------
entrytoken
  : ENTRY
  -> entryMethod
  (
    once={$rulestart::auths.size()== 1},
    rows3cols={Utils.makeRows3Cols(Utils.makeList(new Integer($all::ruleCnt).toString(),$rulestart::auths.size()),$rulestart::auths,Utils.dotList($rulestart::auths))} 
  )
  ;
//--------------------------------------------------------------------------------


the Object array I pass in  is an Array of 

public class Row3Cols {
 
  public String one;
  public String two;
  public String three;
 
  public Row3Cols(String one, String two, String three) {
    super();
    this.one = one;
    this.two = two;
    this.three = three;
  }
 
  public String getOne() {
    return one;
  }
 
  public String getTwo() {
    return two;
  }
 
  public String getThree() {
    return three;
  }
 
}
 
What happens is are exceptions on runtime:
 
Class [Lde.emvau.ruletool.compiler.Row3Cols; has no such attribute: one in template context [ruleSetClass aliasesBlocksAndMethods entryMethod]
java.lang.NoSuchFieldException: one
Exception in thread "main" java.util.NoSuchElementException: no such attribute: rows3col in template context [ruleSetClass aliasesBlocksAndMethods entryMethod else_subtemplate]
 
What am I missing? Any help appreciated !
Best Regards,
Claus
 
 


_______________________________________________
stringtemplate-interest mailing list
stringtemplate-interest at antlr.org
http://www.antlr.org/mailman/listinfo/stringtemplate-interest



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20090223/5f96f960/attachment-0001.html 


More information about the stringtemplate-interest mailing list