Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How could i parse string and link its model with my files in eclipse project?(How could i parse string and link its model with my files in eclipse project?)
How could i parse string and link its model with my files in eclipse project? [message #1703271] Thu, 30 July 2015 07:15 Go to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
How could i parse string and link its model with my files in eclipse project?, as i read that we dont have to use standalone mode while working with eclipse projects.

Example of what i want to do:
I have file1.dsl in my project which contains some statements but the declaration of these statements are not in another file, i need to put them only in my code
Re: How could i parse string and link its model with my files in eclipse project? [message #1703297 is a reply to message #1703271] Thu, 30 July 2015 11:38 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Hi Kimi,

please give a more complete example of what you would like to do. Maybe a little project would help people understand your intention better.

Cheers,
Stefan
Re: How could i parse string and link its model with my files in eclipse project? [message #1703305 is a reply to message #1703297] Thu, 30 July 2015 12:50 Go to previous messageGo to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
Hi Stefan,

I have eclipse project contains 2 files, file1.dsl and file2.dsl, you can see the contents of the files below.
file1.dsl contains some statements as shown below and file2.dsl contains the declarations of the variables. (like in C++ or Java we have declarations and usage)
At this step file1.dsl and file2.dsl will be parsed successfully without any errors.

Lets imagine that we will delete this project and will create another one and the new project will contain only file1.dsl (which contains the usage)
At this step this file (file1.dsl) will contains some errors after parsing it, because we are using variables without declarations.
So what i need is to parse the content of file2.dsl directly without adding this file to the project.
I need to add the content of file2.dsl directly as a string in the code and parse it. just like that ( "int a;int b;" )
And link file1.dsl with the model generated after parsing my string

file1.dsl
------------------
a++;
b++;

file2.dsl
-----------------
int a;
int b;


Thanks

[Updated on: Thu, 30 July 2015 12:52]

Report message to a moderator

Re: How could i parse string and link its model with my files in eclipse project? [message #1703322 is a reply to message #1703305] Thu, 30 July 2015 15:45 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Okay, could you elaborate a little more on the use case? My guess is that you want some "standard declarations" that are always there? Like a standard library?
Re: How could i parse string and link its model with my files in eclipse project? [message #1703325 is a reply to message #1703322] Thu, 30 July 2015 16:06 Go to previous messageGo to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
Exactly i want some standard declarations like standard library
In addition to that i need some declarations that will be added in certain cases.
Re: How could i parse string and link its model with my files in eclipse project? [message #1703438 is a reply to message #1703325] Fri, 31 July 2015 14:44 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

If your language uses the Java classpath, you can just put your standard models into a jar and include that in the client projects.

Otherwise I would suggest customizing the scope provider to put the standard models on the scope where needed. This gives you very fine grained control.
Re: How could i parse string and link its model with my files in eclipse project? [message #1703456 is a reply to message #1703271] Fri, 31 July 2015 16:29 Go to previous messageGo to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
Hi stefan,
Thanks so much for your help.
I have started working with xtext short time ago, so my info are limited a little bit
What do you mean by "your language use java classpath"?
Do you have a page which explain with more details about how to use scope provider and java classpath with my language?
Re: How could i parse string and link its model with my files in eclipse project? [message #1703481 is a reply to message #1703456] Sat, 01 August 2015 04:00 Go to previous messageGo to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
This is my situation right now, Just to clear any confusion:

My project contains file1.dsl only, so a model for this file will be created. (This file contains usage of variable without declarations)

Currently i am able to create another model from hard-coded string containing the variables declarations.

The problem is that fiel1.dsl in eclipse project contains sytnax errors because it doesnt see the declarations, it seems like the models are not linked.

[Updated on: Sat, 01 August 2015 04:05]

Report message to a moderator

Re: How could i parse string and link its model with my files in eclipse project? [message #1703483 is a reply to message #1703481] Sat, 01 August 2015 04:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
hi

the easiest is:

make the project the user model in a java project. put the model the user edits in the source folder. put the libary in a jar file. and add this jar file to the classpath of the java project


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How could i parse string and link its model with my files in eclipse project? [message #1703504 is a reply to message #1703483] Sat, 01 August 2015 16:34 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Hi Kimi,

Christian already described how my first suggestion would work. It is definitely the easiest if it is okay for the user projects to be Java projects.

If you want to go the scope provider route, you would create your own implementation of IGlobalScopeProvider (you can override DefaultGlobalScopeProvider as a starting point). In there, you load your hardcoded library models into a ResourceSet, use the ResourceDescription.Manager to get EObjectDescriptions ("index entries") for those library models and then add those to the scope returned from the GlobalScopeProvider.

If you are new to customizing Xtext languages, you should have a look at the user guide about scoping and dependency injection before continuing down that road.

Hope that helps =)
Stefan
Re: How could i parse string and link its model with my files in eclipse project? [message #1703525 is a reply to message #1703504] Sun, 02 August 2015 13:50 Go to previous message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
Hi,
I am a little bit confused.
As i said by adding file1.dsl and file2.dsl in eclipse project every thing work smoothly and i got no syntax errors in file1.dsl, cross reference is working also without any modifications in GlobalScopeProvider.
My expectations after removing file2.dsl from the project and loading it from the code as shown below, my expectation was that every thing will work correctly and syntax errors of file1.dsl will disappear.

URI uri = URI.createURI("file2.dsl");
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
Resource resource = resourceSet.getResource(uri, true);
EcoreUtil2.resolveLazyCrossReferences(resource, null);

Even if the way of loading the resource is wrong but i have only to load it in correct way but without any modifications in GlobalScopeProvider.

[Updated on: Sun, 02 August 2015 13:59]

Report message to a moderator

Previous Topic:problem in the autocomplete method, Xtext bug?
Next Topic:Hidden tokens are replaced by a whitespace
Goto Forum:
  


Current Time: Tue Mar 19 04:01:57 GMT 2024

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

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

Back to the top