Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Deafult value for enums(Deafult value for enums)
icon5.gif  Deafult value for enums [message #1722028] Tue, 02 February 2016 10:58 Go to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi All,
I have a clarification related to enums.
Always first enum value is set by default. For E.g.

enum MyEnum :
val1 | val2 ;

If some value is not set in the editor, by default it takes as val1. How do we avoid this ? Can we do something in the grammar?


Thanks in advance Smile


Regards,
Arshad


Arshad
Re: Deafult value for enums [message #1722029 is a reply to message #1722028] Tue, 02 February 2016 11:00 Go to previous messageGo to next message
Miro Spönemann is currently offline Miro SpönemannFriend
Messages: 74
Registered: March 2015
Location: Kiel, Germany
Member

You have to define the enum type in an ecore model and import that in your language. In that external model you can declare a default enum literal and omit that one in the grammar rule for the enum type so it's not part of the syntax.
icon5.gif  Re: Deafult value for enums [message #1722034 is a reply to message #1722029] Tue, 02 February 2016 11:40 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi Miro,

Thanks for the reply.

But now say that, if that enum field is optional in my grammar then it will still consider the first element .. So we will have to check explicitly if it's set or not..


Regards,
Arshad


Arshad
Re: Deafult value for enums [message #1722040 is a reply to message #1722034] Tue, 02 February 2016 12:10 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14079
Registered: July 2009
Senior Member
yes you can use ecore unsettable eIsSet/eIsAttributeSet for that

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Changing the port for web DSL module
Next Topic:Loading XMI fails due to unresolved references that are provided by the LazyLinker when using DSL
Goto Forum:
  


Current Time: Tue Oct 26 03:38:44 GMT 2021

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

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

Back to the top