[Xpand] assignement in Xpand [message #521440] |
Wed, 17 March 2010 15:40 |
MasterBoy 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 #521476 is a reply to message #521452] |
Wed, 17 March 2010 17:24 |
|
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 |
MasterBoy 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 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03464 seconds