Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [Xtend2] Code Reference
[Xtend2] Code Reference [message #696542] Thu, 14 July 2011 04:57 Go to next message
Eclipse UserFriend
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 14:38 Go to previous message
Eclipse UserFriend
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
Previous Topic:Quick Fix - Access Specific Token
Next Topic:Does Xtext have limitation on the size of the grammar?
Goto Forum:
  


Current Time: Tue Jul 08 05:02:51 EDT 2025

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

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

Back to the top