Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext: Include "enum"
Xtext: Include "enum" [message #1069717] Tue, 16 July 2013 12:53 Go to next message
Chris Hansen is currently offline Chris HansenFriend
Messages: 20
Registered: July 2013
Junior Member
Hello,

how can I import an enum that is defined in another Model?

Something like
[...]
Type = MyEnum

or 

import "/foo" as f
Type = [f::MyEnum]


doesn't work.

Regards,
Chris
Re: Xtext: Include "enum" [message #1069719 is a reply to message #1069717] Tue, 16 July 2013 12:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

are you tasling about Enums defined in the grammar?

this is not possible.
enums are datatypes and not references.

=> you have to import the metamodel and redefne the syntax.

or enums that are a concept in your language.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext: Include "enum" [message #1070025 is a reply to message #1069719] Wed, 17 July 2013 05:26 Go to previous messageGo to next message
Chris Hansen is currently offline Chris HansenFriend
Messages: 20
Registered: July 2013
Junior Member
Okay, thanks.
Re: Xtext: Include "enum" [message #1076401 is a reply to message #1070025] Wed, 31 July 2013 10:30 Go to previous messageGo to next message
Chris Hansen is currently offline Chris HansenFriend
Messages: 20
Registered: July 2013
Junior Member
One more question about how to Model an Enum:

I thought about this:

FilterPortType:
	type = ("long" | "int" | "unsigned int" | "string" | "char" | "double" | "boolean" | 
		"_FILTER_STATUS_T" | "_METHOD_STATUS_T" | STRING)	
;


as the Model of an enum.

But it seems to fail when I try to reference my self-made Enum from another Model (by [foo::FilterPortType]

Does my Enum need an ID to allow referencing, or what am I doing wrong there?
And if if does need an ID, how to model that? My aim is to provide an Enum that may be referenced / included from other Models.


Re: Xtext: Include "enum" [message #1076406 is a reply to message #1076401] Wed, 31 July 2013 10:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Am not quite sure at which metalevel you are now. You can only refer
to instances not to concepts. So if you would write Myenum: name=("a"
| "b" | "c"); you would at least need an instance of each element to
be able to refer to it. So why do you want to refer at all?

--
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: Xtext: Include "enum" [message #1076413 is a reply to message #1076406] Wed, 31 July 2013 11:05 Go to previous messageGo to next message
Chris Hansen is currently offline Chris HansenFriend
Messages: 20
Registered: July 2013
Junior Member
My only aim is to generate an Enum that can be used within different Models and Generators.

At the moment I am re-defining this generic Enum in every Model, but I don't like that.
Re: Xtext: Include "enum" [message #1076427 is a reply to message #1076413] Wed, 31 July 2013 11:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

so why dont you use real enums, and simply redefine syntax (dont know if this works)

enum MyEnum: a | b;
Object: value=MyEnum;



enum MyEnum returns otherdsl::MyEnum: a | b;
OtherObhect: value=MyEnum;



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext: Include "enum" [message #1076439 is a reply to message #1076427] Wed, 31 July 2013 12:00 Go to previous messageGo to next message
Chris Hansen is currently offline Chris HansenFriend
Messages: 20
Registered: July 2013
Junior Member
Thank you, that solves the first half of my Problem.

But I am still missing an idea how to "include" the Enum in different Models without re-defining them.

In your example, I have to copy the Enum-Options "a | b" into every Model that wants to use the Enum.
Re: Xtext: Include "enum" [message #1076458 is a reply to message #1076439] Wed, 31 July 2013 12:28 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

as i said. this is not possible on grammar level (besides inheritance)
=> as long as your enums are not a language concept it wont be possible.
if they are a langhuage concept it will work out of the box
(if the concept has an attribute named 'name')


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Get CharSequence from JvmOperation object
Next Topic:about outline view
Goto Forum:
  


Current Time: Sat Apr 20 15:17:06 GMT 2024

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

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

Back to the top