Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Enum as attribute value
Enum as attribute value [message #1829651] Wed, 08 July 2020 05:35 Go to next message
Eclipse UserFriend
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 05:37 Go to previous messageGo to next message
Eclipse UserFriend
you use

XEnum ';'

and not

value=XEnum ';'
Re: Enum as attribute value [message #1829653 is a reply to message #1829652] Wed, 08 July 2020 05:42 Go to previous messageGo to next message
Eclipse UserFriend
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 05:43] by Moderator

Re: Enum as attribute value [message #1829654 is a reply to message #1829653] Wed, 08 July 2020 05:48 Go to previous messageGo to next message
Eclipse UserFriend
i assume this is cause there is no common type for enum and int so you would need enumValue=XEnum

[Updated on: Wed, 08 July 2020 05:48] by Moderator

Re: Enum as attribute value [message #1829656 is a reply to message #1829654] Wed, 08 July 2020 06:59 Go to previous messageGo to next message
Eclipse UserFriend
Thanks
Re: Enum as attribute value [message #1829659 is a reply to message #1829656] Wed, 08 July 2020 07:18 Go to previous messageGo to next message
Eclipse UserFriend
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 07:20] by Moderator

Re: Enum as attribute value [message #1829666 is a reply to message #1829659] Wed, 08 July 2020 08:45 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 14:21:23 EDT 2025

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

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

Back to the top