Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtend2] Code Reference
[Xtend2] Code Reference [message #696542] Thu, 14 July 2011 08:57 Go to next message
Marcel   is currently offline Marcel Friend
Messages: 5
Registered: July 2011
Junior Member
Hello,

i have some questions with regard to Xtend2.
Iam working with xtend2 since 2 weeks and there are some syntax problems for me.

First of all is there any kind of Code Reference oder complete Syntax explanation for Xtend2? I haven't found something yet.

I try to write an *.xtend file for my DSL.
In the DSL i have defined an enum Type, which i want to use in the Generator.xtend file. I just want to use a switch case statement or IF statements to check the different alternatives of my enum type.

What is the right syntax for importing my enum type into the Generator.xtend file?
What is the right syntax for a switch case statement over my enum type in xtend2?

...

«FOR x : model.elements»
«switch (x.type){
case enumtype1 : { printenum1(x) }
case enumtype2 : { printenum2(x) }
}


printenum*(x) are methods i want to invoke, when the specific enumtype is given.
The syntax posted above is absolut false, but where are the mistakes?

thanks,
greetings Marcel


Re: [Xtend2] Code Reference [message #696745 is a reply to message #696542] Thu, 14 July 2011 18:38 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this works for me

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID land=LND '!';
	
enum LND:
	BW | BY | NRW
;


	def generate(Model m) 
		'''
			«FOR g : m.greetings»
				«g.name» = «switch (g.land) {
						case LND::BW : "Baden-Wuerttemberg"
						case LND::BY : "Bayern"
						
					}»
			«ENDFOR»
		'''


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Quick Fix - Access Specific Token
Next Topic:Does Xtext have limitation on the size of the grammar?
Goto Forum:
  


Current Time: Wed Apr 24 15:39:35 GMT 2024

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

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

Back to the top