Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext] Referring to an enum member
[Xtext] Referring to an enum member [message #1735952] Fri, 24 June 2016 02:23 Go to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I have two different grammars returning the same type. I want to differentiate the two grammars by enum.

Grammar1 returns Book:
'Type'  classification=ID 'Author' name=ID 'Title' title=ID';'
;

Grammar2 returns Book:
'Reference' classification=ID 'Author' name=ID 'Publish' date=ID 'Title' title=ID ';'
;


My xcore model has a class Book.
class Book {
String classification
String name
String title
String date
}


This requires me to do a string compare for the classification variable. I want to differentiate Grammar1 with Grammar2 by using an enum.
enum eType :
fiction = 'FICTION' |
classic = 'CLASSIC' ;

Grammar1 returns Book:
'Type'  classification=eType::FICTION 'Author' name=ID 'Title' title=ID';'
;

Grammar2 returns Book:
'Reference' classification=eType::CLASSIC 'Author' name=ID 'Publish' date=ID 'Title' title=ID ';'
;


How can I set the literal value of an enum to a variable? Do I need to create a value converter?

Re: [Xtext] Referring to an enum member [message #1735955 is a reply to message #1735952] Fri, 24 June 2016 03:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
if it is a String in the core why not classification="CLASSIC"

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
Re: [Xtext] Referring to an enum member [message #1735957 is a reply to message #1735955] Fri, 24 June 2016 03:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
Or you do a enum in xcore and

enum Myenum1 returns xxx::MyEnum:
Classsic = 'classic';

Enum Myenum2 returns xxx::MyEnum:
Fiction='fiction'


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
Re: [Xtext] Referring to an enum member [message #1735965 is a reply to message #1735957] Fri, 24 June 2016 06:13 Go to previous message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I am also planning to change my xcore to:
enum eType {
classic as 'CLASSIC'
fiction as 'FICTION'
}

class Book {
eType classification
String name
String title
String date
}
Previous Topic:Autocomplete inconsistent with syntactic sugar
Next Topic:error clearing misuderstanding
Goto Forum:
  


Current Time: Mon Apr 12 23:21:27 GMT 2021

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

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

Back to the top