Skip to main content



      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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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» ;


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

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


Current Time: Wed Jul 23 18:22:08 EDT 2025

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

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

Back to the top