Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext / Xpand problem
Xtext / Xpand problem [message #642534] Wed, 01 December 2010 17:17 Go to next message
Mehdi Missing name is currently offline Mehdi Missing nameFriend
Messages: 22
Registered: December 2010
Junior Member
Hi,

i am new in Xtext / Xpand and i have a question :

I have built a textual DSL using Xtext and succesfully created a text output file from my Xtext model (defined in my plugin editor) using Xpand, my question is how do i go the other way around ? from the output file generated by Xpand to a model who is conform to my Xtext grammar ?

And thank you for your time.
Re: Xtext / Xpand problem [message #642589 is a reply to message #642534] Wed, 01 December 2010 21:22 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Do you mean: how to reconstruct the model from the output of an Xpand template?

You're going to implement round-tripping, are you? Wink (Round-tripping is generally considered an Anti-pattern around here.)

In general, the answer is: you can't unless the (Xpand-)mapping model → output is bijective. Often, some information is lost or the mapping back may be ambiguous. Provided the mapping is bijective, then you could either try and make a(n Xtext) grammar for the output, or use another, pre-existing parser for the format of the output (Java/XML/...) or you could even try and use regular expression to extract anything which should have come from a model element.


Re: Xtext / Xpand problem [message #642606 is a reply to message #642589] Wed, 01 December 2010 23:08 Go to previous messageGo to next message
Mehdi Missing name is currently offline Mehdi Missing nameFriend
Messages: 22
Registered: December 2010
Junior Member
i see, thank you for the quick respond but it's really problematique because i need to do my " Round-tripping thing " Very Happy

isn't there any other solution to do so ? even without using Xpand ? because the main reason i'm doing this is the Round-tripping (i kinda like this expression now) Laughing

and if it is possible using Xpand how do we do the mapping back ?

so any sugestions ?

And thank you for your time.

[Updated on: Wed, 01 December 2010 23:16]

Report message to a moderator

Re: Xtext / Xpand problem [message #642653 is a reply to message #642606] Thu, 02 December 2010 08:35 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Last sentence of my previous post held no less than three suggestions.

Re: Xtext / Xpand problem [message #642658 is a reply to message #642653] Thu, 02 December 2010 08:48 Go to previous messageGo to next message
Mehdi Missing name is currently offline Mehdi Missing nameFriend
Messages: 22
Registered: December 2010
Junior Member
when i said any sugestions i was talking about the possibility of using Xpand and how do we do the mapping back using xpand because i don't see how to do so ? ( a tutorial or an example would be of great help)

and you also sugested the possibility of using an existing java or xml parser ? but my output format is a format that i defined myself so i don't think that there is an existing parser for it.

thank you for your time and help.
Re: Xtext / Xpand problem [message #642664 is a reply to message #642658] Thu, 02 December 2010 09:01 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

write an Xtext grammar for your output format and Xpand templates that create the original format.

Alex
Re: Xtext / Xpand problem [message #642674 is a reply to message #642664] Thu, 02 December 2010 10:02 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Just to be completely clear: Xpand only provides mappings from (in-memory) model to text. Once it's text, it's just that: text. Xpand doesn't provide the mapping back.

It all depends on the format that the text happens to correspond to: if it's Java code or XML, then you're probably better off using a pre-existing parser, having that parse your text so you can grab the information required to reconstruct the model from it. If it's a completely custom format (possibly another DSL?), then there's nothing for it except to write another (Xtext) grammar which understands the format and pieces the model back together from it.

If you're able to do that, especially when you're able to reuse the existing (Ecore) metamodel, it's a sort of proof that the mapping is indeed bijective.

Btw: it would be interesting to see whether it's possible to derive the grammar from the Xpand template, but it's guaranteed to give you severe headaches for a few days in a row Wink


Re: Xtext / Xpand problem [message #642677 is a reply to message #642674] Thu, 02 December 2010 10:16 Go to previous messageGo to next message
Mehdi Missing name is currently offline Mehdi Missing nameFriend
Messages: 22
Registered: December 2010
Junior Member
Thank you for your answer it was realy clear and helpfull.

So i'm going to try - something - and see (something that includes severe headaches Rolling Eyes ).

by the way is there any other solutions beside Xpand ? i heard about another language named Jet, i didn't try it yet but is it worth the trouble or not ?

And Thank you again for the help i really apreciate it.
Re: Xtext / Xpand problem [message #642706 is a reply to message #642677] Thu, 02 December 2010 13:04 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
If you're refering to the JET template engine that is used by EMF to generate the Java model code: don't bother with it... It suffers from a JSP-like syntax and is quite limited. (In fact, I'm surprised EMF has stuck with it for so long instead of moving to Xpand, e.g.)

The headaches should only arise if you try to construct a completely generic solution. For a particular solution, it should be a matter of creating a(n Xtext) grammar and maybe do a model-2-model transformation if the target domain (i.e., the result of the Xpand mapping) is sufficiently lower-level than the original model.

If you're willing to share the DSL and Xpand template with us, we can be more specific in trying to help you.


Re: Xtext / Xpand problem [message #642784 is a reply to message #642706] Thu, 02 December 2010 16:48 Go to previous messageGo to next message
Mehdi Missing name is currently offline Mehdi Missing nameFriend
Messages: 22
Registered: December 2010
Junior Member
I actualy managed to find a good solution using an Xtext grammar (a model to model transformation) but now i have another problem :

in my xtext model (domain specific model) i defined a number of parameters to be able to write this in the plugin editor :

501 = TEST_Unit ( 15000 );

now my problem is that i must add the quote " to String values like this or else i have several Errors in the plugin editor :

"501" = TEST_Unit ( " 15000 Bac tests " );

Any solution for this kind of problem ?

As for my DSL this is the part where i'm having this problem :

Application :
{Application}
(Instance_def=EString) "=" (Instance_value=EString) "(" (Instance_long=EString) ");" ;

EString:
STRING | ID;

Thank you for your time - Again -

[Updated on: Thu, 02 December 2010 16:49]

Report message to a moderator

Re: Xtext / Xpand problem [message #642789 is a reply to message #642784] Thu, 02 December 2010 16:56 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
You can match integer numbers using the INT terminal rule.

Re: Xtext / Xpand problem [message #642914 is a reply to message #642789] Fri, 03 December 2010 10:27 Go to previous messageGo to next message
Mehdi Missing name is currently offline Mehdi Missing nameFriend
Messages: 22
Registered: December 2010
Junior Member
Ok, so i matched the integer numbers using the INT terminal rule for the instance def so now i have this :

Application :
{Application}
(Instance_def=INT) "=" (Instance_value=EString) "(" (Instance_long=EString) ");" ;

and this as a result in my editor :

501 = TEST_Unit ( " 15000-Bac tests " );

but i still have the quotes in the - Instance_long - and here is an exemple of what i would like to have :

501 = TEST_Unit ( 15000-Bac tests );

And thank you for your time.
Re: Xtext / Xpand problem [message #642927 is a reply to message #642914] Fri, 03 December 2010 11:38 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
OK, that means you'll have to create your own terminal rule to match those kinds of tokens. The User Guide explains how to do that. Just make sure the new terminal rule(s) don't overlap with existing ones -e.g., it may be necessary to deactivate the INT rule for this.


Re: Xtext / Xpand problem [message #642930 is a reply to message #642927] Fri, 03 December 2010 11:53 Go to previous message
Mehdi Missing name is currently offline Mehdi Missing nameFriend
Messages: 22
Registered: December 2010
Junior Member
Ok i'll try that and thank you for your time. Smile
Previous Topic:Loading text directly without any resource text file
Next Topic:Headless RCP app with xtext?
Goto Forum:
  


Current Time: Sat Apr 20 01:39:17 GMT 2024

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

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

Back to the top