Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] assignement in Xpand
[Xpand] assignement in Xpand [message #521440] Wed, 17 March 2010 15:40 Go to next message
MasterBoy  is currently offline MasterBoy Friend
Messages: 18
Registered: March 2010
Junior Member
Hi all,

I'm working on a project with Xtext and Xpand ( OpenArchitectureWare) and I have a problem with the assignment in an Xpand. In my grammar, I have a rule
Table: (Column = columns +) +
and
Column: length = INT.

in my file Xpand, I have a statement "FOREACH" on Column, and I want to add at each iteration the length value of current column to a variable that I declare before the statement "FOREACH".

I think that i can use a GLOBALVAR but i want to know if there are an other ways to do it.

Best regards

[Updated on: Wed, 17 March 2010 16:20]

Report message to a moderator

Re: [Xpand] assignement in Xpand [message #521452 is a reply to message #521440] Wed, 17 March 2010 16:01 Go to previous messageGo to next message
MasterBoy  is currently offline MasterBoy Friend
Messages: 18
Registered: March 2010
Junior Member
PLZZZ, some one help me..
I have to resolve this problem to presente my exemple in a meeting tomorrow.
I don't know if working with Xpand, and Xtend was a good idea or i have to work with an other framwork ( ATL or OCL or something like that...)
Re: [Xpand] assignement in Xpand [message #521476 is a reply to message #521452] Wed, 17 March 2010 17:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hello - do you use this var within the foreach or just at the end e.g. for a sum. if you just want to summarize just write a little extension like this one

Integer getLengthSum(Table table) : table.columns.getLengthSum();

private Integer getLengthSum(List[Column] cols) :
	cols.size == 0 ? 0 : cols.first().length + (cols.withoutFirst()).getLengthSum();




Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xpand] assignement in Xpand [message #521483 is a reply to message #521476] Wed, 17 March 2010 18:00 Go to previous messageGo to next message
MasterBoy  is currently offline MasterBoy Friend
Messages: 18
Registered: March 2010
Junior Member
thank you for your answer,

well, what i have to do is to print the value of my variable after each iteration
this value is the somme of the other past columns length, and the actual column length.

here is the source code of my Xpand end Xtend file:


«LET 1 AS inter»

«FOREACH columns AS column»
the actual value is : sum(inter,column.length) «REM» value should be printed here.«ENDREM»
«ENDFOREACH»
«ENDLET»
«ENDDEFINE»


and for my extension :

sum(Integer inter,Integer length_col) : 
	inter<-inter+length_col;



So that didn't work

[Updated on: Wed, 17 March 2010 18:01]

Report message to a moderator

Re: [Xpand] assignement in Xpand [message #521487 is a reply to message #521440] Wed, 17 March 2010 18:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
what about this

«DEFINE main FOR Table»
«FILE "test.txt"»
«FOREACH columns AS c ITERATOR i»
«this.getLengthSum(i.counter1)»   
«ENDFOREACH»
«ENDFILE» 
«ENDDEFINE»


Integer getLengthSum(Table table, Integer upTo) : table.columns.getLengthSum(upTo);

private Integer getLengthSum(List[Column] cols, Integer upTo) :
	cols.size == 0 || upTo ==0 ? 0 : cols.first().length + (cols.withoutFirst()).getLengthSum(upTo-1);


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xpand] assignement in Xpand [message #521647 is a reply to message #521487] Thu, 18 March 2010 12:08 Go to previous message
MasterBoy  is currently offline MasterBoy Friend
Messages: 18
Registered: March 2010
Junior Member
thank you for your help, that's works!! you saved my life Smile
i didn't think that working with those frameworks gonna to be so abstract!! thnx
Previous Topic:[Xpand] Modular code generation?
Next Topic:[XTend] Importing *.ext files from Base Workspace fails when working in Runtime Workspace *solved*
Goto Forum:
  


Current Time: Fri Apr 19 19:53:50 GMT 2024

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

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

Back to the top