Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 19:10 Go to next message
Marco Liebhardt is currently offline Marco LiebhardtFriend
Messages: 3
Registered: March 2018
Junior Member
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 19:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto edit DSL file on compile [message #1784515 is a reply to message #1784508] Wed, 28 March 2018 20:42 Go to previous messageGo to next message
Marco Liebhardt is currently offline Marco LiebhardtFriend
Messages: 3
Registered: March 2018
Junior Member
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 20:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
But why on generation / compilation

Of course you could change and save the resource on generation but I'd consider that very ugly


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto edit DSL file on compile [message #1784518 is a reply to message #1784516] Wed, 28 March 2018 21:04 Go to previous messageGo to next message
Marco Liebhardt is currently offline Marco LiebhardtFriend
Messages: 3
Registered: March 2018
Junior Member
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 21:23 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Maybe having a look at auto edit helps too.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Rename element gives NPE
Next Topic:Xtext grammar which do not generate an EMF java interface
Goto Forum:
  


Current Time: Thu Apr 25 07:54:24 GMT 2024

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

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

Back to the top