Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Tree Based Syntax

We have native syntax support for List and Maps. We should also support arbitrary nested tree structures. e.g. DOMish APIs or Ant tasks or Jelly tags or Swing widgets or whatever. Each may have their own particular factory mechanism to create the tree of objects - however they can share the same markup syntax to define them - in a concise alternative to XML.

In general we'd like to support a few kinds of markup...

generic tree structures making groovy.lang.Node a first class syntax like Map and List are
custom tree structures beans, DOMs, Swing, Ant, Jelly etc
metadata JDK 1.5 style


Here's an example syntax

The above invokes a number of methods on the owner class using named-parameter passing syntax. Then the button method would create JButton etc. The { } is used to define a closure which adds its content to the newly created node. Also notice that the action parameter is passed as a closure - which is ideal for working with UI centric listeners etc.

Note that within the 'markup' you can embed normal expressions - i.e. this markup syntax is a normal part of the Groovy language. e.g.

Using this simple mechanism we can easily create any structured tree of data - or provide an event based model too. Note in Groovy you can just overload the invokeMethodname, arguments to have a simple polymorphic tree creation - such as for DOMis structures or Ant tasks or Jelly tags etc.

Here's an example of some HTML using some mixed content which is typically hard to do neatly in some markup languages

Finally here's an example of creating some namespaced XML structure XSD...

There's a converter from XML to groovy markup so you can try out this new markup language on any XML documents you have already.


List references if any


Comments below -
Having a format output for Excel would be "groovy". One could plug in HSSF from the jakarta poi project.

The html example above does not run using groovy 1.0 beta 5. It does not seem to like the mixed content a'link' ["The Text"] syntax.

To output elements or attributes with a '-' in their name, you need to use '_' in Groovy. For example, to generate a web-app descriptor for a Servlet app:


Which leaves the question of how to generate elements with '_' in the name.

  • No labels