Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Enum as attribute value
Enum as attribute value [message #1829651] Wed, 08 July 2020 09:35 Go to next message
Alex Gor is currently offline Alex GorFriend
Messages: 151
Registered: November 2014
Location: Russia
Senior Member
Hello Gang

I try to implement small dsl. The part of grammar is

enum XEnum:
	XXX='XXXX' |
	YYY='YYYY; 

Attribute:
        name='A' '=' value=INT ';'
	name='wrong_something' '=' XEnum ';' 
       name='B' '=' value=INT ' ;'
	;


And I observe the error in message for attribute wrong_something : " Cannot call enum rule without assignment"

Where is my error?

Thnak you in advance
Re: Enum as attribute value [message #1829652 is a reply to message #1829651] Wed, 08 July 2020 09:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13637
Registered: July 2009
Senior Member
you use

XEnum ';'

and not

value=XEnum ';'


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: Enum as attribute value [message #1829653 is a reply to message #1829652] Wed, 08 July 2020 09:42 Go to previous messageGo to next message
Alex Gor is currently offline Alex GorFriend
Messages: 151
Registered: November 2014
Location: Russia
Senior Member
I tried to use this variant and

name='wrong_something'  '='  value=XEnum ';' 


and observe : "Cannot find compatible type for the feature 'value' (ErrorCode: NoCompatibleFeatureTypeAvailable)"

[Updated on: Wed, 08 July 2020 09:43]

Report message to a moderator

Re: Enum as attribute value [message #1829654 is a reply to message #1829653] Wed, 08 July 2020 09:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13637
Registered: July 2009
Senior Member
i assume this is cause there is no common type for enum and int so you would need enumValue=XEnum


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

[Updated on: Wed, 08 July 2020 09:48]

Report message to a moderator

Re: Enum as attribute value [message #1829656 is a reply to message #1829654] Wed, 08 July 2020 10:59 Go to previous messageGo to next message
Alex Gor is currently offline Alex GorFriend
Messages: 151
Registered: November 2014
Location: Russia
Senior Member
Thanks
Re: Enum as attribute value [message #1829659 is a reply to message #1829656] Wed, 08 July 2020 11:18 Go to previous messageGo to next message
Alex Gor is currently offline Alex GorFriend
Messages: 151
Registered: November 2014
Location: Russia
Senior Member
Another question I added one more enum in my grammar. I observe that the second enum is cause of error. Example
 
enum XEnum:
	XXX='XXXX' |
	YYY='YYYY; 
enum YEnum:
	XXX='XXXX' |
	YYY='YYYY; 

Attribute:
        name='A' '=' value=INT ';' |
	name='wrong_something' '=' enumValue=XEnum ';' |
        name='wrong_something2' '=' enumValue=YEnum ';' |
       name='B' '=' value=INT ' ;'
	;


Build failed with message : "Cannot find compatible type for the feature 'enumValue'" for the second enum

The next stupid code is built ok
enum XEnum:
	XXX='XXXX' |
	YYY='YYYY; 
enum YEnum:
	XXX='XXXX' |
	YYY='YYYY; 

Attribute:
        name='A' '=' value=INT ';' |
	name='wrong_something' '=' enumValue=XEnum ';'  |
        name='wrong_something2' '=' enumValue=XEnum ';' |
       name='B' '=' value=INT ' ;'
	;


[Updated on: Wed, 08 July 2020 11:20]

Report message to a moderator

Re: Enum as attribute value [message #1829666 is a reply to message #1829659] Wed, 08 July 2020 12:45 Go to previous message
Alex Gor is currently offline Alex GorFriend
Messages: 151
Registered: November 2014
Location: Russia
Senior Member
I've added return statement into both enum definitions then grammar start to work
Previous Topic:Exporting LSP from a DSL written in Xtext
Next Topic:How to use FileResourceHandler in xtext web for importUri resolution
Goto Forum:
  


Current Time: Sat Oct 24 18:37:25 GMT 2020

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

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

Back to the top