Problem adding custom feature & operations with implementations to Xtext generated ECore model [message #1609854] |
Tue, 10 February 2015 11:30 |
Evermind Mising name Messages: 7 Registered: July 2009 |
Junior Member |
|
|
Hi everybody,
I am new to Xtext and EMF. I have a simple Xtext syntax which is simplified from real case:
Expression:
PrimaryExpression | GroupExpression;
PrimaryExpression:
variable=ID '= ' value=ID ';' ;
GroupExpression:
'(' exprs+=Expression+ ')';
So the syntax accepts code like:
((((x=y;)e=f;g=h;(a=b;)c=d;)))
What I want to do is:
1. adding a feature 'index' to generated 'GroupExpression' Java interface, so that I can traverse AST later and assign a sequence number to each GroupExpression instance;
I managed to achieve this by adding a "phantom" syntax fragment into GroupExpression, just like:
GroupIndex: '00000000000000000'; // Recognize an identifier that pratically cannot be matched accidently
GroupExpression:
'(' index=GroupIndex? exprs+=Expression+ ')'; // index can never be matched, but Xtext will generate a feature for it, so I can use it to store calculated index value.
This can get THIS thing done, however I think it is limited and not elegant. Wonder if there is a better way.
2.I want to add an operation "void evaluate(String expr)" to generated interface Expression, and provide a default implementation that can be baked into generated code. I didn't find a way to achieve this though. I found some article saying "Generation gap pattern" which is using EcoreGenerator and it will
automatically search for "ImplCustom" classes and generate factory that actually create custom impl class, however I tried and got incomplete generated code. I also read this issue 402669 [ht tps://bugs.eclipse.org/bugs/show_bug.cgi?id=402669] and found that EcoreGeneratorFragment used in generated workflow doesn't support ImplCustom classes at all. So currently I have no way to deal with this problem.
So could someone please tell me is there any official or elegant way to achieve this? Thanks!
[Updated on: Tue, 10 February 2015 11:32] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04166 seconds