Basically, ZML is a markup language with a C-style syntax and lots of syntactic sugar. Furthermore the ZML toolchain provides a ZML to XML compiler, which means that ZML is a convinient way of writing XML. So you could regard it as an alternativ to a feature rich XML editor.
But ZML is more. It is also a technique of code generation, thus an alternativ to Model Driven Architecture. These two aspects fit together when you know that ZML code generation is done with XSLT. Using the ZML syntax instead of the XML syntax for XSLT stylesheets makes it very easy to write a code generation tool whenever approriate. No BNF, flex and bison, no theoretical knowledge about gramar and parser classes. Just some XML, XSLT and XPATH, denoted in a convinent way.
example
Assume our task is to implement a vending machine. A vending machine is an instance of a statemachine. So the first thing we do is to define a meta-model for statemachines. It lists the basic entities of which a state machine consists.
# statemachine.zls decl statemachine(name) decl state(name) decl event(name) decl transition(target) decl start
Now we define the vending machine as a model of a state machine
# automat.zml
include statemachine.zls
statemachine "vending machine" {
state standby {
start
event coin {
transition choose
}
event abort {
transition standby
}
}
state choose {
event abort {
transition standby
}
event juice {
transition deliver
}
}
state deliver {
event done {
transition standby
}
}
}
The above document can be transformed into XML. So we can write XSLT stylesheets to generate whatever we need. For example we could generate a dot file, which gives us a visualization of the vending machine.
An other XSLT stylesheet could generate a C++ implemenation of the vending machine. An example output of the resulting application could look like this:
$ ./vending_machine coin transition to state choose juice transition to state deliver done transition to state standby coin transition to state choose abort transition to state standby
Once the meta-model and the XSLT stylesheets are done, the effort starts to pay off. Assume you need to update the visualization and the implementation of the vending machine, because as a new requirement it has to offer soda, too. All you have to do now is to extend the model file of the vending machine and rerun the XSLT transformation. That's all.
What makes code generation with ZML so easy, is the fact that XSLT stylesheets are XML documents. Thus they can be written in ZML, too. The tutorial shows in detail, what the involved documents of this example look like. If you compare the ZML and the XML variants of the XSLT stylesheets, you see what a benefit the ZML syntax is.
documentation
Besides the tutorial and the api we have no documentation yet.
However, there are many working examples for the ZML notation and for the code generation. They should cover all features of ZML. Feel free to have a look at them.
references
ZML is heavily based on YML, which is developed by Volker Birk. We wanted to try some different approaches which Volker did not want to have for YML at that time. So ZML is a proof of concept for the following differences to YML:
- context-free grammar for ZML
- assignment of attribute values to attributes is mapped to Python's system for paramter handling.
- most literals don't need quotes
- support for definition of subtrees
- unicode support
download
Choose one of the following:
- Get the current version as bz2 file
- Browse the hg repository to get other revisions
- clone the repository with hg clone http://hg.projects.spamt.net/hg/zml
status
ZML is currently not actively maintained as the proof of concept is considered successful. Besides one open issue, though. Namely you need to know about the internal name mangling if you use non-Python names within embedded code blocks. And of course besides the lack of documentation.copying
ZML is published by Rico Schiekel, Alexander Bernauer and Jonathan Häberle under the GPL 2.0 (and not later).