Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » transform model in XMI to xtext model
transform model in XMI to xtext model [message #531059] Mon, 03 May 2010 14:38 Go to next message
Yu Sun is currently offline Yu SunFriend
Messages: 58
Registered: July 2009
Member
Hi guys,

I have build the textual DSL, and I know the code to transform the textual DSL file to XMI. However, how to transform the XMI model back to textual DSL? Any advice?

Thanks.

Yu
Re: transform model in XMI to xtext model [message #531066 is a reply to message #531059] Mon, 03 May 2010 15:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14718
Registered: July 2009
Senior Member
Hello Yu,

have a look at http://www.eclipse.org/Xtext/documentation/0_7_2/xtext.html# serialization. Just add the Contents of your XMI resource to a Xtext resource and call save (just the other way round than creating the xmi)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: transform model in XMI to xtext model [message #531071 is a reply to message #531066] Mon, 03 May 2010 15:30 Go to previous messageGo to next message
Yu Sun is currently offline Yu SunFriend
Messages: 58
Registered: July 2009
Member
I got it. Thanks a lot Christian.
Re: transform model in XMI to xtext model [message #531160 is a reply to message #531071] Mon, 03 May 2010 23:38 Go to previous messageGo to next message
Yu Sun is currently offline Yu SunFriend
Messages: 58
Registered: July 2009
Member
Hi guys,

I have made the transformation from XMI to xtext working. However, there is one interesting problem:

In my xtext, I defined my own SHORT type, which is:

terminal SHORT returns ecore:Eshort :
    INT's'
;


I also defined my own TerminalConverters to get the short value by removing the last 's'. It works perfect, and transforming the xtext file to XMI model also works fine.

However, now when I transform the XMI model back to xtext file, the short values in the xtext file does not contain the 's', which is not a correct xtext file in my grammar.

Is there anything I can do to solve this problem?

Thanks a lot.

Yu

[Updated on: Mon, 03 May 2010 23:39]

Report message to a moderator

Re: transform model in XMI to xtext model [message #531201 is a reply to message #531160] Tue, 04 May 2010 07:44 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Yu,

please override the toString(Value) method in your value converter
implementation that removes the 's' from the parsed input. The
toString() should add it as it is required in the concrete syntax.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 04.05.10 01:38, schrieb Yu Sun:
> Hi guys,
>
> I have made the transformation from XMI to xtext working. However, there
> is one interesting problem:
>
> In my xtext, I defined my own SHORT type, which is:
>
> <CODE>
> terminal SHORT returns ecore:Eshort :
> INT's'
> ;
> </CODE>
>
> I also defined my own TerminalConverters to get the short value by
> removing the last 's'. It works perfect, and transforming the xtext file
> to XMI model also works fine.
>
> However, now when I transform the XMI model back to xtext file, the
> short values in the xtext file does not contain the 's', which is not a
> correct xtext file in my grammar.
>
> Is there anything I can do to solve this problem?
>
> Thanks a lot.
>
> Yu
>
>
Re: transform model in XMI to xtext model [message #531304 is a reply to message #531201] Tue, 04 May 2010 13:50 Go to previous messageGo to next message
Yu Sun is currently offline Yu SunFriend
Messages: 58
Registered: July 2009
Member
Thanks Sebastian. That works!

Another question about this part is that the textual dsl file being transformed from XMI model do not have line separators and indent.

I guess that the only way to realize this is to add line separators into the grammar, right?

Sorry for so many questions. I really appreciate all your help.

Yu
Re: transform model in XMI to xtext model [message #531312 is a reply to message #531304] Tue, 04 May 2010 14:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14718
Registered: July 2009
Senior Member
Hello Yu,

for whitespace handling you can implement a formatter as described in http://www.eclipse.org/Xtext/documentation/0_7_2/xtext.html# formatting

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: transform model in XMI to xtext model [message #531393 is a reply to message #531312] Tue, 04 May 2010 17:26 Go to previous message
Yu Sun is currently offline Yu SunFriend
Messages: 58
Registered: July 2009
Member
Thank you so much, Christian.
Previous Topic:a grammar design question
Next Topic:configureImportantInformation gone in 1.0 nightly?
Goto Forum:
  


Current Time: Fri Sep 27 02:53:15 GMT 2024

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

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

Back to the top