Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Auto edit DSL file on compile(Like auto edit but not while writing, just on compiling like code generator)
Auto edit DSL file on compile [message #1784505] Wed, 28 March 2018 15:10 Go to next message
Eclipse UserFriend
Hello,

for my DSL it is required to add Integer IDs to some of my elements. But I don't want users to need to write them own their own, so they should be auto generated. I know you can do this with auto edit while writing the elements. But I would like to have them generated in the DSL file just when it compiles and not while writing. Is this possible?

Here is an example:

Grammar:
Model:
element+=element*;

Element:
name=ID ("id" "=" id=ID)?;

DSL file:

element1
element2

DSL file after compile:

element1 id = 0
element2 id = 1

Thanks for helping

Best Regards
Marco Liebhardt
Re: Auto edit DSL file on compile [message #1784508 is a reply to message #1784505] Wed, 28 March 2018 15:53 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

This Sounds like a usecase for a Model 2Model Transformation not Inside the Generator but inside a so callled IDerivedStateComputer
You can find an example here
http://xtextcasts.org/episodes/18-model-optimization
Re: Auto edit DSL file on compile [message #1784515 is a reply to message #1784508] Wed, 28 March 2018 16:42 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for answering.

Correct me if i'm wrong but IDerivedStateComputer just adds additional state to the AST model not the actual DSL file and it's transient. But the IDs of the elements need to be permanent. Each element needs to keep its ID no matter if you add or delete other elements.

For example if you add element3 into the upper example and compile it again it should look like this:

element1 id = 0
element3 id = 2
element2 id = 1
Re: Auto edit DSL file on compile [message #1784516 is a reply to message #1784515] Wed, 28 March 2018 16:54 Go to previous messageGo to next message
Eclipse UserFriend
But why on generation / compilation

Of course you could change and save the resource on generation but I'd consider that very ugly
Re: Auto edit DSL file on compile [message #1784518 is a reply to message #1784516] Wed, 28 March 2018 17:04 Go to previous messageGo to next message
Eclipse UserFriend
The IDs need to be permanent so they need to be in the DSL file, but they are not really relevant for the programmer and just make the code less clear. Therefore I wanted to add them automatically on compile when the programmer is done with writing the current code block.
Re: Auto edit DSL file on compile [message #1784520 is a reply to message #1784518] Wed, 28 March 2018 17:23 Go to previous message
Eclipse UserFriend
Maybe having a look at auto edit helps too.
Previous Topic:Rename element gives NPE
Next Topic:Xtext grammar which do not generate an EMF java interface
Goto Forum:
  


Current Time: Fri Jun 20 19:11:24 EDT 2025

Powered by FUDForum. Page generated in 0.04434 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top