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: 19
Registered: October 2016
Junior 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: 11206
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


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com

[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: 19
Registered: October 2016
Junior Member
Thanks! the downcast of the parent works perfectly for me. great answer!!
Previous Topic:Variable/String Substitution Grammar with ${var} Style
Next Topic:Implementing java web editor
Goto Forum:
  


Current Time: Tue Sep 26 16:41:12 GMT 2017

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

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