Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Take an integer typed in the DSL and generate a java variable with it
Take an integer typed in the DSL and generate a java variable with it [message #1052902] Wed, 01 May 2013 03:55 Go to next message
Dan Barr is currently offline Dan Barr
Messages: 10
Registered: April 2013
Junior Member
Hi,

So I have my DSL setup
Game:
	{Game}('speed' speed+=Time+ 'end')?('size' sizes+=Size+ 'end')?;
	

Time:
	 value=INT;
	
Size:
	 value=INT;



so when the user types speed 1000 size 20 I want my generated Java s src to atore these values in a variable but I cant get it to work.

Im using xTend to generaet my code and ive tried a number of different ways but I dont know how to grab the value in xTend and then pass it into my java block.

I wrote a method
		def gameSpeed(Time speed) '''
		 var speed = «speed.value»(){}
		 return speed)
	'''

that seemed to get the value, but when i tried to use it, the generated code would literally display
'temp = car speed = 1000()[]' in the source file rather than
temp = 1000;
Re: Take an integer typed in the DSL and generate a java variable with it [message #1052903 is a reply to message #1052902] Wed, 01 May 2013 04:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5848
Registered: July 2009
Senior Member
Hi,

in your DSL Speed is a list. (speed+=Time+)
Re: Take an integer typed in the DSL and generate a java variable with it [message #1052904 is a reply to message #1052903] Wed, 01 May 2013 05:09 Go to previous messageGo to next message
Dan Barr is currently offline Dan Barr
Messages: 10
Registered: April 2013
Junior Member
Ah that makes sense, I got it to work using a for loop which calls the method
«FOR c : g.speed»
				«c.gameSpeed»
			«ENDFOR»


	def gameSpeed(Time speed) '''
		 int gameSpeed = «speed.value» ;


Re: Take an integer typed in the DSL and generate a java variable with it [message #1053477 is a reply to message #1052902] Mon, 06 May 2013 04:28 Go to previous message
Karsten Thoms is currently offline Karsten Thoms
Messages: 353
Registered: July 2009
Location: Dortmund
Senior Member

What Christian meant is that you might not want a list, and just a single value. And your code confirms that for me, since you unlikely want to declare mutiple variables "gameSpeed".

So change to:

Game:
	{Game}('speed' speed=Time 'end')?('size' sizes+=Size+ 'end')?;
	

Time:
	 value=INT;
	
Size:
	 value=INT;

-----------------------------------------
int gameSpeed = «g.speed.value» ;




Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de

[Updated on: Mon, 06 May 2013 04:31]

Report message to a moderator

Previous Topic:JavaIoFileSystemAccess - null pointer
Next Topic:ambiguity in the grammar
Goto Forum:
  


Current Time: Fri Apr 18 22:07:56 EDT 2014

Powered by FUDForum. Page generated in 0.09176 seconds