Freitag, 1. Juni 2007
Freitag, 11. Mai 2007
A small experiment in diagram-layout-from-AST
If the previous post sounded too vaporware to you, this time you'll see code snippets for a view that auto-layouts the EPackage contents of a selected EClass, for example in the Ecore Sample Editor. OK, right away I want to mention that this code is my HelloWorld 0.1 attempt at layouting. If you're already into programming diagram editors, stop reading this post!!!
Most of the setup code for the view in question comes from a plugin to visualize OCL Abstract Syntax Trees, an article about which you can find here.
Instead of using a
TreeViewer, this time I'm using a GraphViewer, courtesy of Zest, the Eclipse Visualization Toolkit. Again, I'm using Zest in a most basic manner, you'll see the moment you visit Zest's homepage that it's way more powerful than what my example conveys.In a lucid moment I realized that in order to customize the figure to display (a class figure) an
IStylingGraphModelFactory should be provided, like this one: |
All in all, the plugin structure is as follows:
I don't even dare call it a "proof of concept", but anyway I felt some code should be thrown in to support my argument.
The IDE generator I'm working on should provide an extension point to let querying the current AST, to support this and other use cases. Yes. I think so.
diagram layout out of textual representation
How to cook your own DSL language.
Consider statecharts. Diagrams are nice to browse, but hard to edit. Let’s say we have an IDE for a textual notation of statecharts. I like this comparison [1]:
Which is faster?
textual Environment:
1 move cursor to position
2 type “|| await C”
graphical Environment:
1 make room: shift neighbor states, enlarge parent state
2 click on “add state”
3 move mouse to location and place new state
4 click on “add state”
5 move mouse to location and place new state
6 double click on new state, toggle terminal field
7 click on “initial state”
8 move mouse to location and place new initial state
9 click on “transition”
10 move mouse to location of initial state
11 press left mouse button and keep pressed until reaching state
12 click on “transition”
13 move mouse to location of state
14 press left mouse button and keep pressed until reaching terminal
state
15 double click on transition
16 write “C” in trigger field
17 press “OK”
18 click on “delimiter line”
19 move mouse to location and place delimiter line
The underlying argument is that having a true DSL infrastructure, including access to the Abstract Syntax Tree (AST) of the doc being edited, gives you a lot of mileage, e.g. enabling the suggested use (auto-layout).
There's more related work, of course (the idea cannot be new), but I don't see it being mentioned often enough in DSL tooling circles. Diomidis Spinellis has a nice prototype to layout UML class diagrams from Java source, to achieve things like:
given the following input:
// Author: Vadim Nasardinov
// Version: $Id: ceg-mv.xml,v 1.1 2005/11/23 22:21:22 dds Exp $
import java.util.List;
import java.util.Map;
/**
* @assoc "1..1" - "0..n" Adapter
* @assoc "" - "0..n" ObjectType
* @assoc "" - "0..n" ObjectMap
* @assoc "" - "0..n" Table
* @assoc "" - "0..n" DataOperation
**/
class Root {
private Map m_adapters;
private List m_types;
private List m_maps;
private List m_tables;
private List m_ops;
public Adapter getAdapter(Class klass) {}
}
class Adapter {
public Root getRoot();
}
abstract class Element {
Root getRoot() {}
}
class ObjectType extends Element {}
/**
* @has "1..1" - "1..1" ObjectType
**/
class ObjectMap extends Element {
private ObjectType m_type;
}
class Table extends Element {}
class DataOperation extends Element {}
Notice that it's possible to generate different diagram views from the same source description.
Actually, all this detour into diagrams actually aims at reinforcing the view that language engineering (by means of metamodeling, with well-formedness and type-checking conditions specified in OCL) is a good thing, that also comes to benefit in case you're all for diagrams. But I won't peruse any further this visual path, for that you can check two generators of diagram editors:
- the Eclipse Graphical Modeling Framework
- the Tiger Project at Tech Univ Berlin (Germany)
Have fun (and please come back to this textual DSLs blog soon :)
References:
[1] The Kiel Statechart Layouter
Mittwoch, 9. Mai 2007
existing prototypes
- xText by the OpenArchitectureWare team
- TCS, by Frédéric Jouault (INRIA)
- TEF, by Markus Scheidgen (Uni Humboldt)
- Gymnast, by Chris J Daly (IBM)
- SAFARI (just about to become an Eclipse project)
A hard test for any IDE generator for a custom DSL is whether the input specification encodes more constraints than just grammar (I'm talking about well-formedness rules such as declarations-before-usages and type-checking rules. Same observations go for other tools not on this list). More details on this criteria can be found in the aforementioned presentation.
APIs for programming text editors
- A talk at EclipseCon 2004, Text Editors and How to Implement Your Own by Kai-Uwe Mätzel
- The EclipseCon 2006 tutorial Text Editor Recipes (by Tom Eicher and Martin Aeschlimann) and its slides
Don't worry! More references will come later! (and will be available as URLs in commented source code). Want tutorials? I've found these useful:
how it all started
What’s it about? First go to the ongoing Google Summer of code (2007) projects for Eclipse . From there, just dig into this project description
The motivation for the whole thing is lowering the learning curve to tooling a custom DSL. For example, a DSL more readable than BPEL, or a DSL that wall-papers over the many EJB3 APIs, and so on. It’s not that difficult to design one’s own DSL (especially if one pays attention to abstract syntax, well-formedness rules, and type checking, all achievable with metamodeling and OCL). What’s missing then is the IDE for one's brainchild.
There’s growing interest in Domain Specific Languages (fuelled by Model Driven Architecture). Martin Fowler describes in “A Language Workbench in Action” the kind of DSL definitions that current tools support, plus or minus some features.
http://www.martinfowler.com/articles/mpsAgree.html
Before starting this project I just wanted to be a user of (let’s call it) language engineering technology. So I reviewed what research teams with a lot of experience had to offer for Eclipse, and I realized that my needs were not high in their priority list. In the end, someday that will change, so check from time to time what’s new at places like: http://www.meta-environment.org/ and http://harmonia.cs.berkeley.edu
Back to my project. From the start, I can identify two problem areas:
- the mechanics of programming a text editor under Eclipse, and
- other prototypes nearby this technology niche