Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Create dynamically primitive types that are defined in a types ecore model
Create dynamically primitive types that are defined in a types ecore model [message #1783039] Wed, 07 March 2018 05:50 Go to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
Hi guys,

beside my dsl I have a second ecore model that specify types.
In that model there is for example the root class type and the class primitive types that extends from types.

Now I want to create dynamically instances of the primitive types with the name integer, string and boolean so that i can refer to these types out of my dsl.

Where can I do this stuff? In the Scoping? And how?

A small example would be really helpful. Basically I think xbase should do similar things.

Many thanks!
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783040 is a reply to message #1783039] Wed, 07 March 2018 06:16 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
PS: I think this is not the use case of the IDerivedState computer or is it?
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783041 is a reply to message #1783039] Wed, 07 March 2018 06:19 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 614
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Basically you want to define a dynamic type system. As source of inspiration look at the Xsemantics project: https://projects.eclipse.org/proposals/eclipse-xsemantics
It allows to define (static) type system rules and produces the Xtext artifacts for supporting that type system.

For more information on it contact Lorenzo Bettini direct.
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783044 is a reply to message #1783041] Wed, 07 March 2018 06:36 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
Hi Karsten,

many thanks! I will take a look into it
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783053 is a reply to message #1783041] Wed, 07 March 2018 09:51 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
Hi Karsten,

after I take a look to the Xsemantics I'm not sure if it will help me.

Maybe I will concretize my scenario:

I have a dsl and the model of the dsl is generated automatically with the generate keyword. It has the extension ".myDsl"

In my dsl it's possible to refer to external emf model elements that has been created by a user in an graphical emf editor (.boxmodel). In the editor the user can create Elements of the class
"BoxType". For instance a BoxType can contain a different number of contacts.

So the class of "BoxType" looks like this:

BoxType:
name : EString
contacts: Contact (0...* as containments)

At the end the user can create for example BoxType B1 (with 10 contacts) and BoyType B2 (with 12 contacts)

Now it my dsl it should be possible to declare a variable for a specific BoxType or for a primitive type.

So that the user can write the following:

   set int x = 5;
   set B1 y;
   set B2 z;


Now I had the following approach: I create a third model for types (.types).
The meta-model of the type-model looks like this:

Type
name : EString

PrimitiveType-> Type

ModelType-> Type

The BoxType of the Metamodel (.boxmodel) extends from ModelType.

In a variable declaration I can refer to Elements of Type

Variable:
	'set' =>(type=[types::Type|ID] name=ID) ('=' right=Expression)? ';'
;


But currently I have the problem that I can not refer to default primitive Types like ('int', 'string', etc.) because I have to instantiate them dynamically for the first time and have to but them to the index. So at the end I need the possibility to instantiate a primitive type with name = 'int' and so on. More or less it's a dynamically created library that provides the default primitive types.

But I have no idea where to do this stuff.

PS: In the dsl itself the user has no chance to define types. So he can only define boxTypes with a graphical emf editor or he can use the primitive types.
Maybe the upper approach is to complicated and there is a easier approach.

About suggestions for improvement, I would be very happy.

[Updated on: Wed, 07 March 2018 09:59]

Report message to a moderator

Re: Create dynamically primitive types that are defined in a types ecore model [message #1783059 is a reply to message #1783053] Wed, 07 March 2018 10:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
there is no "Nice" solution to that. you can put the objects somewhere into scope (local or gobal scope provider)
or you could provide some std lib .yourdsl files and put them onto classpath


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783062 is a reply to message #1783059] Wed, 07 March 2018 10:19 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
Hi Christian,

first many thanks. Could you give me a small example how I can dynamically instantiate an element of an external model element and how to put it then to the scope?

[Updated on: Wed, 07 March 2018 10:20]

Report message to a moderator

Re: Create dynamically primitive types that are defined in a types ecore model [message #1783063 is a reply to message #1783062] Wed, 07 March 2018 10:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
yourfactory.instance.createXXXX
EObjectDEscription.create(.....) / Scopes.scopeFor......


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783064 is a reply to message #1783063] Wed, 07 March 2018 10:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
i cannot create example cause it will take half an hour and will serve as an example for a shitty concept. and i dont want this.

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783067 is a reply to message #1783064] Wed, 07 March 2018 10:26 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
Okay :)

What is generally shitty on this concept? And what would be a better approach? I would be very happy about some tips or hints.
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783068 is a reply to message #1783067] Wed, 07 March 2018 10:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
did you consider have a std lib file and put the standard lib onto the classpath of the model projects?

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783070 is a reply to message #1783068] Wed, 07 March 2018 10:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
and as i said: there is NO NICE solution on that that will make everybody happy and will be shiny and great.

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783083 is a reply to message #1783053] Wed, 07 March 2018 13:39 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 614
Registered: July 2009
Location: Dortmund, Germany
Senior Member

As Christian says often such things would be handled by some "built in" library that is always in your scope. One approach here is to customize the global scope provider and provide a "scope with library". The library does not necessarily be on the classpath, its just the easiest way. A customization of the global scope provider would allow you to bundle the library into a plugin.

Unfortunately implementations that I have are closed source and don't have the time to anonymize that. But would be worth a blog post some day.
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783092 is a reply to message #1783083] Wed, 07 March 2018 19:23 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
Hi Christian and Karsten,

many thanks for your help! A blog post would be really helpful.
But already your support here on the forum is really grateful.

Currently I try the stdlib approach as proposed from Christian and as described in the book of "Implementing Domain-Specific Languages with Xtext and Xtend".

But currently I stuck at this problem that was already described in this post https://www.eclipse.org/forums/index.php/t/916943/ and https://stackoverflow.com/questions/46557127/xtext-ide-not-loading-library. So far the libraries are not indexed.

I also tried the example of the book and therefore I have the same problem. I also deleted the runtime workspace and double check the dependencies as proposed from Christian.

But hope I will find a way to solve the problem in the next hours ;)

Thx and have a nice evening!
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783093 is a reply to message #1783083] Wed, 07 March 2018 19:23 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
No Message Body

[Updated on: Wed, 07 March 2018 19:24]

Report message to a moderator

Re: Create dynamically primitive types that are defined in a types ecore model [message #1783095 is a reply to message #1783093] Wed, 07 March 2018 20:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
Please post a screenshot of you model project with dependencies expanded in the package explorer

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783148 is a reply to message #1783095] Thu, 08 March 2018 14:06 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
It works now!
I removed the runtime-workspace again and checked that the autobuild is selected.
Re: Create dynamically primitive types that are defined in a types ecore model [message #1783155 is a reply to message #1783148] Thu, 08 March 2018 15:01 Go to previous message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 614
Registered: July 2009
Location: Dortmund, Germany
Senior Member

+1

[Updated on: Thu, 08 March 2018 15:02]

Report message to a moderator

Previous Topic:Omitting root name in references
Next Topic:LSP: resolving types
Goto Forum:
  


Current Time: Sat Sep 22 01:45:37 GMT 2018

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

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

Back to the top