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: 12388
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


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
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: 12388
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


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
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: 12388
Registered: July 2009
Senior Member
Maybe having a look at auto edit helps too.

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
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: Sat Nov 17 10:37:49 GMT 2018

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

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

Back to the top