Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext] Using existing enums from imported metamodel
[Xtext] Using existing enums from imported metamodel [message #517508] Sun, 28 February 2010 22:46 Go to next message
Eclipse UserFriend
Originally posted by: ogucuk.gmail.com

Dear Xtext gurus,

is it not possible to directly use the enumerations that are defined in
an imported metamodel without explicitely introducing them in the grammar?

We use an imported metamodel instead of generating our own from the
Xtext grammar. In our Ecore metamodel, we had already defined literals
for our enumerations. Now we want to reference the enumeration in our
Xtext grammar, i.e:

Entity :
type=[metamodel::EnumType]
;

Code generations is no problem but in the editor I do not see the enum
literals in content assist. Also if I type the predefined literals, I
get parser errors.

What am I missing?
Re: [Xtext] Using existing enums from imported metamodel [message #517523 is a reply to message #517508] Mon, 01 March 2010 03:02 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Özgün,

since enumerations are datatypes, I doubt that you can use them in a
cross reference.
You could use you EnumType as follows:

enum EnumType returns metamodel::EnumType:
Foo | Bar;

Entity:
type=EnumType;

You have to list the enum literals because the grammar describes the
abstract and the concrete syntax. E.g. there may be situations where you
do not want to use every defined literal in your concrete syntax.

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

Am 28.02.10 23:46, schrieb Özgün:
> Dear Xtext gurus,
>
> is it not possible to directly use the enumerations that are defined in
> an imported metamodel without explicitely introducing them in the grammar?
>
> We use an imported metamodel instead of generating our own from the
> Xtext grammar. In our Ecore metamodel, we had already defined literals
> for our enumerations. Now we want to reference the enumeration in our
> Xtext grammar, i.e:
>
> Entity :
> type=[metamodel::EnumType]
> ;
>
> Code generations is no problem but in the editor I do not see the enum
> literals in content assist. Also if I type the predefined literals, I
> get parser errors.
>
> What am I missing?
Re: [Xtext] Using existing enums from imported metamodel [message #517524 is a reply to message #517523] Mon, 01 March 2010 03:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ogucuk.gmail.com

Hi Sebastian,

thanks again, for your prompt responses.

If I leave the brackets and the metamodel alias, Xtext thinks EnumType
is a parser rule and cannot resolve it. I was kind of hoping, maybe in
that case the brackets do mean that it is imported :) and not a
cross-ref. Do you have any suggestions?

Well, it is not a big deal but we would be happy if we could release the
grammar from the double declaration of enumerations (once in metamodel
and once in the grammar).

Thanking you

Özgün



Sebastian Zarnekow schrieb:
> Hi Özgün,
>
> since enumerations are datatypes, I doubt that you can use them in a
> cross reference.
> You could use you EnumType as follows:
>
> enum EnumType returns metamodel::EnumType:
> Foo | Bar;
>
> Entity:
> type=EnumType;
>
> You have to list the enum literals because the grammar describes the
> abstract and the concrete syntax. E.g. there may be situations where you
> do not want to use every defined literal in your concrete syntax.
>
> Hope that helps,
> Sebastian
Re: [Xtext] Using existing enums from imported metamodel [message #517527 is a reply to message #517524] Mon, 01 March 2010 08:25 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Özgün,

it is not possible to use enums without declaring an enum rule.

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

Am 01.03.10 08:56, schrieb Özgün:
> Hi Sebastian,
>
> thanks again, for your prompt responses.
>
> If I leave the brackets and the metamodel alias, Xtext thinks EnumType
> is a parser rule and cannot resolve it. I was kind of hoping, maybe in
> that case the brackets do mean that it is imported :) and not a
> cross-ref. Do you have any suggestions?
>
> Well, it is not a big deal but we would be happy if we could release the
> grammar from the double declaration of enumerations (once in metamodel
> and once in the grammar).
>
> Thanking you
>
> Özgün
>
>
>
> Sebastian Zarnekow schrieb:
>> Hi Özgün,
>>
>> since enumerations are datatypes, I doubt that you can use them in a
>> cross reference.
>> You could use you EnumType as follows:
>>
>> enum EnumType returns metamodel::EnumType:
>> Foo | Bar;
>>
>> Entity:
>> type=EnumType;
>>
>> You have to list the enum literals because the grammar describes the
>> abstract and the concrete syntax. E.g. there may be situations where
>> you do not want to use every defined literal in your concrete syntax.
>>
>> Hope that helps,
>> Sebastian
Re: [Xtext] Using existing enums from imported metamodel [message #517531 is a reply to message #517527] Mon, 01 March 2010 08:37 Go to previous message
Eclipse UserFriend
Originally posted by: ogucuk.gmail.com

Ok thank you

Sebastian Zarnekow schrieb:
> Hi Özgün,
>
> it is not possible to use enums without declaring an enum rule.
>
> Regards,
> Sebastian
Previous Topic:reference a concept from other model through its fully qualified identifier
Next Topic:[Xtext] Problem with the autogenerated code.
Goto Forum:
  


Current Time: Fri Mar 29 15:44:00 GMT 2024

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

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

Back to the top