Generate Xtext grammar from Ecore file without the project wizard [message #1859464] |
Fri, 09 June 2023 10:52  |
Eclipse User |
|
|
|
Hello,
I have an Ecore metamodel I would like to use for automatically generating code. For this, I have written Xtend functions to process model members and output code; effectively I am using Xtext as a bridge between Ecore and Xtend.
I was wondering if it there is a way to generate a Xtext grammar from an Ecore file without using the "New Xtext Project From Ecore" wizard. Right now, every time I change my Ecore model, I have to generate a dummy project, copy over the (new) generated Xtext file over to the Xtext project with my Xtend functions and delete the dummy project. It would be especially practical if there was a way to automatically re-generate the Xtext grammar when the underlying Ecore model is changed.
Thanks in advance.
Regards
K.
|
|
|
|
|
Re: Generate Xtext grammar from Ecore file without the project wizard [message #1859482 is a reply to message #1859478] |
Fri, 09 June 2023 19:46   |
Eclipse User |
|
|
|
An Xtext grammar is much richer than an Ecore metamodel; it provides all sorts of syntax options that may be pleasing to a user.
(Conversely, in a small number of areas, an Ecore metamodel is richer than Xtext can synthesize.)
Using Ecore to Xtext you must be using some rather formulaic syntax that is no doubt adequate and predictable but not pleasant. If you want a formulaic syntax that is better than XML you might care to look at HUTN that is supported as part of the Eclipse Epsilon project.
Personally, I recommend maintaining both Xtext grammar and Ecore metamodel as primary source artefacts. The Ecore to Xtext generator, when it works, is deceptive; it seems to generate something but it is not pleasing and you find yourself improving it all at once and it falls apart. I prefer to steadily grow the Xtext grammar to cover more and more of the Ecore metamodel. (I also like to use an Xtext 2 LPG converter, available as part of the OCL project, to help ensure that my grammar is free of ambiguities.)
Regards
Ed Willink
|
|
|
|
Re: Generate Xtext grammar from Ecore file without the project wizard [message #1859576 is a reply to message #1859478] |
Fri, 16 June 2023 11:03   |
Eclipse User |
|
|
|
Hello,
I have a metamodel created in EMF. I would like to generate code using models of this metamodel. The metamodel contains Rust templates, for example there is an EClass named ConstructorImplementation that contains an EList of Fields. My code generator is supposed to "fill out" Xtend templates with the relevant values from the model (e.g. name of a Field) and then write the generated code in a Rust file.
At least what I've understood from the video that Tamas, is that no Xtext grammar is required to write Xtend methods, if the Ecore model already exists on its own. I deleted the automatically generated Xtext file (I used the project wizard "New Xtext Project from Existing Ecore Model...") and the Xtend file was still valid, as the types were being imported from the respective EMF project, and not from the Ecore model implied through the Xtext grammar (which, in return, was generated using the Rust template metamodel).
Now I am not sure how am I supposed to approach this. Can I just load some serialized model file and invoke the root generate method in my Xtend code generation class?
Is Xtend even meant for such an use case?
Thanks in advance.
Regards
K.
[Updated on: Fri, 16 June 2023 11:07] by Moderator Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 12.78949 seconds