1

I find myself wanting to write <prop1.subprop1:sometemplate> to apply a template to a list in a property of a property. To do this, I have to make two levels of template: I have to invoke the outer one on prop1 and and then have it process the next property down.

Data model:

class Clazz {
    String name;
    Class parent;
}

Goal:

class(c) ::= <<
   <c.parent.name> <! oops, not allowed !>
>>

So I end up with

<c.parent:{ p | <p.name> }>

which is a little clumsy.

Then I got to this:

class Attr {
   List<String> requiredParameters;
   Attr baseObject;
}

and I want to generate:

def __init__(self, reqparam1, ... rewqparamN)

where the first 'reqparam' is from the deepest item. I tried to write the following, but ST gives me syntax errors in the second template where I try to recurse to build a list.

self_and_list(list) ::= << self<if(first(list))>, <endif><list;separator=", "> >>

recurse_req(attr) ::= "<[<attr.baseObject:recurse_req()>, <attr.requiredParameters>]>"

self_and_req_params(attribute) ::= "<self_and_list(<attribute:recurse_req()>)>"
bmargulies
  • 97,814
  • 39
  • 186
  • 310

0 Answers0