Visual Language Howto
In this post I describe a possible toolchain that lets you define your own visual language in an instant.
To make things less abstract I use Visual Haskell as an example. The idea of a visual notion of Haskell was first (to my knowledge) introduced in the paper Visual Haskell: A First Attempt by John Reekie.
To get an impression of the following steps have a look at the image below:

Now I explain the steps shortly:
- Define the metamodel: As a very first step you have to define your metamodel, i.e. the language constructs of your visual language. In UML you have packages and classes for example. So before you can define Visual Haskell you first have to decide how deep you want to model the language. For simplicity and clarity we just model the concepts Package (=Directory), Module, Function and TypeDecl. We use the Eclipse Modeling Framework and Ecore as a metametamodel. The standard tree editor provided by EMF is enough to define the needed EClasses. The result of this first step is the file haskell.ecore, our metamodel.
- Specify and generate the editor: This step is not really needed to proceed, because EMF provides a simple tree editor for your metamodel for free. However, we want a Visual Haskell and a tree editor may not be visual enough... Nowadays nobody programs such a simple diagram editor by hand. Instead there are nice diagram editor generators out there, for example DiaMeta or the Eclipse Graphical Modeling Framework. I prefer DiaMeta because it is a product of my university department :-) and it supports syntax-directed as well as free-hand editing.
- Edit a model: The result of this step is a xmi-file that corresponds to the previously defined metamodel. We provide a short Data.xmi just to give you an impression.
- Generate code: UML is so widely used, because it is possible to generate a lot of code from the model. And for sure nobody would model Haskell if she had to write the code represented by the model herself. Thank God, there is a nice framework that supports you in writing your code generator: openArchitectureWare. All you have to do is to install the framework, define a workflow and some templates and you are done. The templates are defined in a language called xpand that is very easy to use and that provides support for file creation, modularization of templates, protected regions (very important if you want to regenerate the code after manual changes) and so on. We provide an example workflow and a template for modules.
That's it! We are done already.
Note, that the described toolchain is just an example. And it worked for me quite well. Nevertheless, you should have a look at the many other tools out there, that provide similar functionality and may be even better suited for your purpose.
I hope that you now are motivated and qualified to try some ((meta)meta)modeling on your own. Feel free to post questions or comments, I'll try to answer :-)
Tags: haskell visual modeling emf diameta gmf openarchitectureware
0 Comments:
Kommentar veröffentlichen
<< Home