I have created an Xtext grammar working with arithmetic expressions (and functions and whatnot, but for the sake of this question we'll keep it easy) and now I am wondering whether I could visualise it with just Emfatic annotations and EuGENia.

I'm starting to doubt that, however, but I could be overlooking something terribly simplistic.

The grammar is as follows (as described in [1]):

grammar org.xtext.example.test.Test with org.eclipse.xtext.common.Terminals import "http://www.eclipse.org/emf/2002/Ecore" as ecore generate test "http://www.xtext.org/example/test/Test" Addition returns Expression: Multiplication ({Addition.left=current} op='+' right=Multiplication)*; Multiplication returns Expression: Primary ({Multiplication.left=current} op='*' right=Primary)*; Primary returns Expression: NumberLiteral | '(' Addition ')'; NumberLiteral: value=INT;

The resulting Emfatic document:

@namespace(uri="http://www.xtext.org/example/test/Test", prefix="test") package test; class Expression { } class NumberLiteral extends Expression { attr int value; } class Addition extends Expression { val Expression left; attr String ~op; val Expression right; } class Multiplication extends Expression { val Expression left; attr String ~op; val Expression right; }

The general goal is to create a (bidirectially editable) visualisation approximating the AST shown in [1], but any kind of hint could be helpful, especially since this is a rather 'open' question, for lack of a better word.

Thanks for your time.

--

[1] http://blog.efftinge.de/2010/08/parsing-expressions-with-xtext.html]]>

Would this help?

http://www.eclipse.org/epsilon/doc/articles/eugenia-phantom-nodes/

Cheers,

Dimitris]]>

I actually looked at phantom nodes, i.e. that exact page, a little earlier.

I thought it would only be useful for later finetuning of the model, but it actually seems to have worked decently on first try.

However, the visualisation seems to be missing a level at the top as well as correct names for the operations (see attachment) - that's a mistake in annotations, though, I reckon.

In any case, thanks for your help.

//

After playing around for quite a while, I can say that I have no idea on how to make it work properly, sadly.]]>

grammar org.xtext.example.test.Test with org.eclipse.xtext.common.Terminals generate test "http://www.xtext.org/example/test/Test" Calcs: calc+=Calculation*; Calculation: (literal=StringLiteral operation='=')? term=Addition; Addition returns Expression: Multiplication ({Addition.left=current} operation='+' right=Multiplication)*; Multiplication returns Expression: Primary ({Multiplication.left=current} operation='*' right=Primary)*; Primary returns Expression: NumberLiteral | '(' Addition ')'; NumberLiteral: name=INT; StringLiteral: name=STRING;

@namespace(uri="http://www.xtext.org/example/test/Test", prefix="test") package test; @gmf.diagram(foo="bar",diagram.extension="arith_diagram") class Calcs { val Calculation[*] calc; } @gmf.node(label="operation") class Calculation { @gmf.link() val StringLiteral literal; attr String operation; @gmf.link() val Expression term; } class Expression { } @gmf.node(label="name", phantom="true") class NumberLiteral extends Expression { attr int name; } @gmf.node(label="name", phantom="true") class StringLiteral { attr String name; } @gmf.node(label="operation", phantom="true") class Addition extends Expression { @gmf.link() val Expression left; attr String operation; @gmf.link() val Expression right; } @gmf.node(label="operation", phantom="true") class Multiplication extends Expression { @gmf.link() val Expression left; attr String operation; @gmf.link() val Expression right; }

However, I run into errors, mostly NPE's, after rewriting formulae.

Example:

4*2+3*5

4*(2+3)*5

After recreating the diagram, those are gone, so I thought I might want to note that in case that behaviour stems from a bug.

Also, on another note: I seem to be unable to reference attributes via the name "~op" (the assignment is "op" in the grammar), even though EMFatic seems to turn them into "~op".]]>

after a little work I managed to put up the important formulae in tree-form.

I did this by heavily annotating every function, i.e. every parameter of every function got a gmf.link() to show in the tree.

And that, as you might imagine, caused me to run into out-of-heapspace errors and the like and made it impossible to generate diagram code.

As, first of all, the tree view doesn't look all too nice and secondly is costly, I wonder if I could instead put at lease the Parameters of a proper, non-primitive function (i.e. everything except +-*/) into that function's compartment (or as that function's property)?

I did try gmf.compartment(foo="bar") on the parameters, but that didn't seem to work ("Called feature domainMetaElement on undefined object").

A snippet of the grammar look as following:

Function_Simple: Abs | Cos; Abs: name='Abs''('add=Addition')'; Cos: name='Cos''('add=Addition')';

As you can see those functions can include additions by themselves, so the corresponding Emfatic file snippet looks as follows:

class Expression { } @gmf.node(label="name", phantom="true") class Function_Simple extends Expression { attr String name; @gmf.compartment(foo="bar") // that doesn't work, @gmf.link() does val Expression add; } class Abs extends Function_Simple { } class Cos extends Function_Simple { }

Any help would, as always, be greatly appreciated.

// Edit:

Nevermind, I now transformed that graphic into a pure compartment model. The possibility of an outright mix seems unlikely.

However, putting function parameters into the model as property values still seems interesting.

And, another related question that arose: Instead of modeling the elements as "Abs, Cos, ...", can I just annotate them somehow to only make them "Function_Simple", and, again, have the function's name only as a property value?

It is the same with primitive functions - they'll show up as Addition, Multiplication, ... instead of as an Expression, which makes for poor ability to bidirectionally edit the diagram.]]>

It may just be me being too tired after a long day, but I'm afraid I've lost the plot here. It'd really help if you could provide a minimal metamodel and perhaps a sketch of the desired visualisation so that I can investigate.

Cheers,

Dimitris]]>

thank you for at least trying to understand my problem!

As requested, here's a small sample grammar and a very simple sketch of the desired outcome.

I'm just wondering whether this representation is possible simply using Eugenia annotations (or at least getting close to it) or whether I'd have to dig into those diagram files themselves.

Sample grammar:

grammar org.xtext.example.test.Test with org.eclipse.xtext.common.Terminals generate test "http://www.xtext.org/example/test/Test" Calcs: calc+=Calculation*; Calculation: (literal=StringLiteral operation='=')? term=Addition; Addition returns Expression: Multiplication (({Addition.left=current} operation='+' | {Substraction.left=current} operation='-') right=Multiplication)*; Multiplication returns Expression: Primary (({Multiplication.left=current} operation='*' | {Division.left=current} operation='/') right=Primary)*; Primary returns Expression: NumberLiteral | StringLiteral | Function_Simple | '(' Addition ')'; Function_Simple: Abs | ACos ; Abs: name='Abs''('val=NumberLiteral')'; ACos: name='ACos''('add=Addition')'; NumberLiteral: name=INT; StringLiteral: name=STRING;

Thank you for your help and time.]]>

Phantom nodes and expression-backed labels [1] should hopefully do the trick here.

Cheers,

Dimitris

[1] http://wiki.eclipse.org/Graphical_Modeling_Framework/Versions/GMF_2.3]]>