Skip to main content


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 07:55 Go to next message
Dan Barr is currently offline Dan BarrFriend
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 08:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

in your DSL Speed is a list. (speed+=Time+)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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 09:09 Go to previous messageGo to next message
Dan Barr is currently offline Dan BarrFriend
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 08:28 Go to previous message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
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, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de

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

Report message to a moderator

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


Current Time: Fri Apr 19 02:23:40 GMT 2024

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

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

Back to the top