Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Enumeration Element Cross Reference
Enumeration Element Cross Reference [message #1749222] Sat, 03 December 2016 16:41 Go to next message
Lukas Schaus is currently offline Lukas SchausFriend
Messages: 37
Registered: October 2016
Member
Hello,

I am trying to implement a small DSL. it shall be possible to specify a enumeration with a name and elements

I want to cross reference them like this: enumerationName.element.

I managed that the cross reference works but i have the following problem:

In the AST is only the EnumerationElement and not the enumeration type. But i need both.

Here the grammar
Root:
	(elements+=Element)*
;

Element
	: Enum
	| Expression
;

Enum:
	'enum' name=ID '{'
		(element+=EnumElement)*
	'}'	
;

	EnumElement:
		name = ID
	;

Expression:
	a=[Attribute| ENUMTERMINALRULE]
;

Attribute:
	Enum | EnumElement
;

ENUMTERMINALRULE: ID"."ID;


And here an Example

enum greeting{
	hello
	goodMorning
}

enum who {
	you
	me
	i
}

greeting.goodMorning

who.me

who.hello //error


Everything is working as i want it to. But a contains only the EnumerationElement and not the Enum name. Is there a possibility to get both values?
Re: Enumeration Element Cross Reference [message #1749225 is a reply to message #1749222] Sat, 03 December 2016 16:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
you can change the grammar and implement the scope provider

Expression:
enum=[Enum] "." a=[Attribute]
;

or you simply ask the attribute for its eCOntainer and downcast it to enum


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 03 December 2016 18:14]

Report message to a moderator

Re: Enumeration Element Cross Reference [message #1749227 is a reply to message #1749225] Sat, 03 December 2016 17:28 Go to previous message
Lukas Schaus is currently offline Lukas SchausFriend
Messages: 37
Registered: October 2016
Member
Thanks! the downcast of the parent works perfectly for me. great answer!!
Previous Topic:Variable/String Substitution Grammar with ${var} Style
Next Topic:Single Ecore domain model, two conflicting serializations, now what?
Goto Forum:
  


Current Time: Fri Apr 26 23:35:24 GMT 2024

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

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

Back to the top