Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to import and parse a file with xtext and generate an EMF model out of it?
How to import and parse a file with xtext and generate an EMF model out of it? [message #1019392] Fri, 15 March 2013 15:31 Go to next message
Lefteris Skoutaris is currently offline Lefteris SkoutarisFriend
Messages: 24
Registered: March 2013
Junior Member
Greetings to all.

I am working on a project where I need to parse and model input files.

I have installed xtext and created a grammar to generate a parser for a specific file data structure which is represented as an EMF model (as an ecore package).

However, I do not know how import a file with realistic content and parse it in order to generate an EMF model based on that specific file.

For example create, a tree like structure but every branch now contains the real data.

Thank you in advance for your help.
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1020778 is a reply to message #1019392] Mon, 18 March 2013 22:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i dont get your question? can you please elaborate?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1020951 is a reply to message #1020778] Tue, 19 March 2013 08:49 Go to previous messageGo to next message
Lefteris Skoutaris is currently offline Lefteris SkoutarisFriend
Messages: 24
Registered: March 2013
Junior Member
Hello Christian,

Well, I have used initially xtext to develop a language based on a file structure and also generate a parser that "understands" every other file having this structure. The structure is represented as an EMF diagram.

What I would like to do next is to give as input to the parser, a file with realistic data content and parse it in order to create an ecore diagram that containts the file's values.

However, I do not know how to do that in eclipse. Hope I was more clear this time.

Lef.
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1020972 is a reply to message #1020951] Tue, 19 March 2013 09:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi i still have no clue? Files are usually created manually or if you
have a model in memory using the serializer

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1021071 is a reply to message #1020972] Tue, 19 March 2013 13:26 Go to previous messageGo to next message
Paul Rontidis is currently offline Paul RontidisFriend
Messages: 10
Registered: March 2013
Junior Member
Hello,
Do you wish to export an EMF XMI from a DSL Xtext file?
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1021091 is a reply to message #1021071] Tue, 19 March 2013 14:07 Go to previous messageGo to next message
Lefteris Skoutaris is currently offline Lefteris SkoutarisFriend
Messages: 24
Registered: March 2013
Junior Member
Thank you both for your kind replies!

@Christian: Serialization is about transforming the EMF model to its textual representation. I would like to do the reverse.

@Paul: Yes I think this is the case. As long as the .XMI represents the imported file's data values. How do I do that?
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1021133 is a reply to message #1021091] Tue, 19 March 2013 15:08 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
The textual representation is actually the model, it's just serialized as text instead of xmi.
If you really need a XMI file from that search the forum you'll find plenty of topics on that subject.
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1021233 is a reply to message #1021133] Tue, 19 March 2013 17:49 Go to previous messageGo to next message
Paul Rontidis is currently offline Paul RontidisFriend
Messages: 10
Registered: March 2013
Junior Member
This link is very usefull. In case you have trouble opening the produced XMI try defining a schemaLocation.

[Updated on: Tue, 19 March 2013 17:51]

Report message to a moderator

Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1021421 is a reply to message #1021233] Wed, 20 March 2013 03:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Maybe you are simply looking for http://wiki.eclipse.org/Xtext/FAQ#How_do_I_load_my_model_in_a_standalone_Java_application.C2.A0.3F

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1029602 is a reply to message #1019392] Fri, 29 March 2013 22:59 Go to previous messageGo to next message
Lefteris Skoutaris is currently offline Lefteris SkoutarisFriend
Messages: 24
Registered: March 2013
Junior Member
I guess I am not that explanatory. For example look at the second section in this link: http://www.eclipse.org/henshin/examples.php?example=bank

I have created already an .ecore model. However, I want to create a so called dynamic EMF instance model as an .xmi but I do not want to populate this .xmi manually but insert its values from a file (in my case some data from a .txt file).

How can I do that? Plus I have problem running the editor (i have installed the henshin incubation plugin).

[Updated on: Fri, 29 March 2013 23:26]

Report message to a moderator

Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1029833 is a reply to message #1029602] Sat, 30 March 2013 07:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

what about

(1) create a genmodel for the ecore and generate java classes (if not already done)
(2) create a grammar for existing ecore
(3) generate the language
(4) read the model as described above,
(5) persist it as xmi http://www.eclipse.org/forums/index.php/mv/msg/382898/922220/#msg_922220


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1029834 is a reply to message #1029833] Sat, 30 March 2013 07:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
But: what do you want to do with the xmi? read it again? then the serializing would be senseless

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030071 is a reply to message #1019392] Sat, 30 March 2013 16:37 Go to previous messageGo to next message
Lefteris Skoutaris is currently offline Lefteris SkoutarisFriend
Messages: 24
Registered: March 2013
Junior Member
I have created a grammar and generated the language however i do not know how to use it to create a dynamic instance on .xmi.

I have a .txt file with some realistic data content for which I have build a DSL. Now, the ecore file represents a model of that .txt file but does not contain real values (only classes and attributes names).

I want to generate an .xmi that represents the .txt file. Then I will use this .xmi as input to the henshin editor and define some rules on it.

There must be a way to somehow with eclipse to:
1. parse the .txt file
2. map the .txt contents to the .ecore diagram
3. generate an .xmi dynamic instance that containts the values of the .txt file.

Then somehow import this .xmi to the henshin editor.

[Updated on: Sat, 30 March 2013 16:39]

Report message to a moderator

Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030078 is a reply to message #1030071] Sat, 30 March 2013 16:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

did you try the steps i suggested. btw cant the henshin editor directly work with your test.mydsl file?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030092 is a reply to message #1030078] Sat, 30 March 2013 17:24 Go to previous messageGo to next message
Lefteris Skoutaris is currently offline Lefteris SkoutarisFriend
Messages: 24
Registered: March 2013
Junior Member
hi again and thanks for your help Smile

Well, I have created an xtext project, the grammar file MyDsl.text which I used to generate the parser, serializer and the language. Two files are also generated: an .ecore and a .genmodel. I am not sure how I can make use of step 5 that you proposed (im not as guru as you:))I cannot find a .mydsl file.

My installation has now three projects at the package explorer:
org.text.example.mydsl
org.text.example.mydsl.tests
org.text.example.mydsl.ui

In the same workspace I have run the wizard to install the henshin editor which created two files: .henshin and .henshin_diagram. However, I do not know how to get the editor opened and running.

As you can tell im a super duper newbie :/

[Updated on: Sat, 30 March 2013 17:24]

Report message to a moderator

Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030099 is a reply to message #1030092] Sat, 30 March 2013 17:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

if you create a new Xtext project the default file extension is mydsl and not .txt or something like that.
to make the xtext editor running you create a new runtime application. (choose run as eclipse app von projects context menu)
there you can create a new .mydsl file and work with the Xtext editor.
and you can do the henshin stuff there too (i currently have no idea on that to do with this henishin_diagram)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030109 is a reply to message #1030099] Sat, 30 March 2013 17:58 Go to previous messageGo to next message
Lefteris Skoutaris is currently offline Lefteris SkoutarisFriend
Messages: 24
Registered: March 2013
Junior Member
Yes you are right the xtext-based file extensions are mydsl. The .txt file contains the data I want to create a model out of and import it to the henshin graphical editor.

I have run a new eclipse application but it is empty. No projects are included in the package explorer. I tried to open a henhsin editor: File → New → Other → Henshin → Henshin transformation Diagram but i cannot because there is not project in the package explorer to link it.

I followed the isntructions in http://www.eclipse.org/henshin/examples.php?example=bank but i do not manage to open the graphical editor or create an .xmi file.

Arrrrrgggg... Why these people they do not provide a more detailed guide of how to setup this graphical editor.



Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030117 is a reply to message #1030109] Sat, 30 March 2013 18:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi of course it is empty you create a new project there

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030129 is a reply to message #1030117] Sat, 30 March 2013 18:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i just saw that henshin cannot handle xtext files. this is imho a bug on their side.
never the less the following works for me:

(1) rightklick on the .mydsl file
(2) choose open with "sample ecore model editor" or "sample reflective ecore model editor". then you can choose file save as and it can be saved as xmi
(3) then you can use henshin to do the m2m


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030140 is a reply to message #1030129] Sat, 30 March 2013 19:05 Go to previous messageGo to next message
Lefteris Skoutaris is currently offline Lefteris SkoutarisFriend
Messages: 24
Registered: March 2013
Junior Member
Ok let me take it step by step so that I understand the process.
Hmmm...

The .mydsl file is the file I want to parse? In this case my .txt file? I take the .txt and rename it to .mydsl?

And I do the "open with" process at the original eclipse or after running an instantiation? In which environment I must do this process?

What I did is:
1. Ran an eclipse instantiation
2. Created a project
3. Ran the henshin wizard and installed the henshin editor (.henshin and .henshin_diagram)
4. imported the file.txt (that includes the data i want to parse)
5. renamed it to file.mydsl and double clicked on it to run the henshin editor
6. But i got an error message (=Could not open the editor: The editor class could not be instantiated. This usually indicates a missing no-arg constructor or that the editor's class name was mistyped in plugin.xml)

Well I thought that if I rename it to .mydsl it will be parsed automatically and run the henshin editor as well.

In the source eclipse I cannot find a .mydsl file. Did you as well imported this file?

Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030145 is a reply to message #1030140] Sat, 30 March 2013 19:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

just let henshin be henshin for a moment. just work with the mydsl file in the runtime workspace. you should be able to open it
with the "mydsl edior"


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030156 is a reply to message #1030145] Sat, 30 March 2013 19:40 Go to previous messageGo to next message
Lefteris Skoutaris is currently offline Lefteris SkoutarisFriend
Messages: 24
Registered: March 2013
Junior Member
ok.

I dont have a .mydsl file at my running workspace. How did you do it?
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030159 is a reply to message #1030156] Sat, 30 March 2013 19:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
hi,

you simple create it.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030166 is a reply to message #1030159] Sat, 30 March 2013 19:56 Go to previous messageGo to next message
Lefteris Skoutaris is currently offline Lefteris SkoutarisFriend
Messages: 24
Registered: March 2013
Junior Member
ok just checking Smile

I have renamed the .txt to mydsl and imported it to the org.text.example.mydsl project. I get errors when I try to open it with either "sample ecore model editor" or "sample reflective ecore model editor".

I have attached screenshot of the working environment and error.
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030172 is a reply to message #1030166] Sat, 30 March 2013 20:06 Go to previous messageGo to next message
Lefteris Skoutaris is currently offline Lefteris SkoutarisFriend
Messages: 24
Registered: March 2013
Junior Member
hmmm... i think i should give you some space. Thank you very much though for the info and the help. I really appreciate it!

Ill try googling it some more and look for a solution...

[Updated on: Sat, 30 March 2013 20:07]

Report message to a moderator

Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030179 is a reply to message #1030172] Sat, 30 March 2013 20:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

(1) create the dsl and run the workflow (development workspace)
(2) run as eclipse application (spawns runtime workspace)
(3) in runtime workspace create the .mydsl file.
...


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to import and parse a file with xtext and generate an EMF model out of it? [message #1030184 is a reply to message #1030172] Sat, 30 March 2013 20:26 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I think Christian has overlooked the simpler solution that existed
before Xtext and for which there are a variety of tutorials.

Create your *.ecore and *.genmodel (nowadays you could use *.xcore)
Generate a (Tree) Editor for it using the GenModel Generate Model,
Editor options
Create and save a dynamic instance of the root object using the Ecore
Editor Create Dynamic Instance option
In a nested Eclipse use the generated tree editor to elaborate the
instance model.

Of course Xtext is better and GMF even more so, but each is
proportionately more learning effort.

Regards

Ed Willink


On 30/03/2013 20:06, Lefteris Skoutaris wrote:
> hmmm... i think i should give you some space. Thank you very much
> though for the info and the help. I really appreciate it!
>
> Ill try good some more and look for a solution...
Previous Topic:Escape Hatch
Next Topic:ResourceDescriptionStrategy for locally defined eObjects
Goto Forum:
  


Current Time: Thu Mar 28 12:25:25 GMT 2024

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

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

Back to the top