Generate Xtext grammar from Ecore file without the project wizard [message #1859464] |
Fri, 09 June 2023 06: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 #1859576 is a reply to message #1859478] |
Fri, 16 June 2023 07: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 07:07] by Moderator
|
|
|
Re: Generate Xtext grammar from Ecore file without the project wizard [message #1859580 is a reply to message #1859576] |
Fri, 16 June 2023 11:09  |
Eclipse User |
|
|
|
i still can follow you
- if you use an external ecore in xtext you also have to have a genmodel and the javaclasses that the genmodel produces.
- no xtext involved so far
- you can use these java classes for the eclasses in your xtend code.
now you do something with xtext, what is the something?
if you have use ecore based model instances with emf means e.g. from xmi or xml,
you dont need xtext to serialize and parse the model?
is this what you are asking for?
who produces your model instance?
xtend is just "java" with ability to write template expressions
=> all you can do in java with emf you can do with xtend with emf.
https://www.vogella.com/tutorials/EclipseEMF/article.html
[Updated on: Fri, 16 June 2023 11:10] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04593 seconds