Show in Frame No Frame
Up Previous Next Title Page Index Contents Search

6.3.6 Iterating over all properties with do :()

All the properties of an object or other non-property can be iterated over with do :(). This is useful for meta-programming, i.e. writing a MERL generator that is not specific to a given language, and hence cannot know property names or structures ahead of time. MERL is not designed particularly for meta-programming, but more for normal DSM usage, where the generator is made for a specific modeling language. However, as a concession to make such meta-programming a little easier, we allow a little creative polymorphism for the the contents and containers commands, whose main functions are described in Section 6.6.2.

Within do :(), containers gives the local name of this property, which may be more familiar or readable to the end user than the property type name.

Within do :(), the elements being iterated over are the actual properties, so type will return the property type. This is in contrast to iterating over a named complex property, e.g. do :Attributes, where the elements being iterated over are the object(s) in the complex property, e.g. Attribute objects in this case. To descend more deeply into subobjects whilst within do :(), you can use do contents to iterate from the property into the property’s value. This lets you continue as if you had iterated normally directly into the value with something like do :Attributes. If the property’s content is not iterable, e.g. a simple String, do contents will do nothing.

Within this do contents, you can check the metatype to see if you are now in an object or other non-property which would allow recursive descent (e.g. when coming from an Object property or Collection of Objects property), or in a simple String from a Collection of Strings, or a line of Text from a Text property.
/* An example of listing properties deeply by local name */
propsDeeply()
do :()
{ containers ': ' id newline
  do contents where metatype <> 'Text' and metatype <> 'String'
  { propsDeeply() }
}
For a full example see _propsDeeplyInHTML in Graph’s Export Graph to HTML.

Show in Frame No Frame
Up Previous Next Title Page Index Contents Search