Escape new line in Xtend [message #989115] |
Tue, 04 December 2012 16:44 |
|
Hi guys!
I've got this code in my generator:
def compileArray(ArrayDefinition ad)
'''
«IF ad.type instanceof IntType»
int «ad.name»[«ad.final.index.compileExpression»];
«ENDIF»
'''
def compileExpression(GenericExpression e)
'''«IF e instanceof Literal»
«val literal=e as Literal»
«literal.compileLiteral»
«ENDIF»'''
def compileLiteral(Literal l)
'''«IF l.constant!=null»
«l.constant.compileConstant»
«ENDIF»'''
def compileConstant(Constant c)
'''«IF c.intValue!=null»
«c.intValue.intValue»
«ENDIF»'''
but as result I got this:
How can I delete that newline?
Very thank you!
|
|
|
|
Re: Escape new line in Xtend [message #989203 is a reply to message #989139] |
Wed, 05 December 2012 08:44 |
|
Christian Dietrich wrote on Tue, 04 December 2012 19:58Hi,
what about not putting them in
def compileConstant(Constant c)
'''«IF c.intValue!=null»«c.intValue.intValue»«ENDIF»'''
or
def compileConstant(Constant c)
if (c.intValue!=null)
'''c.intValue.intValue»'''
else
''''''
--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
The second solution works! Very thank you, but I've got another doubt:
why something like this works perfectly:
def compileLiteral(Literal l){
if (l.constant!=null){
'''«l.constant.compileConstant»'''
}
}
and for this I've got "This expression is not allowed in this context, since it doesn't cause any effect"
def compileVariableDefinition(Program p){
val listOfDeclarations=p.declarations
for (declaration:listOfDeclarations){
val listOfVariables=declaration.variables
for (variable : listOfVariables){
if (variable.variable!=null){
'''«variable.variable.compileVariable»'''
}
else if (variable.array!=null){
'''«variable.array.compileArray»'''
}
}
}
}
[Updated on: Wed, 05 December 2012 08:45] Report message to a moderator
|
|
|
Re: Escape new line in Xtend [message #989215 is a reply to message #989203] |
Wed, 05 December 2012 09:12 |
|
Hi,
this is cause you do nothing with the richt strings. you throw them away
=> you may do something like
listOfVariables.map[variable |
if (variable.variable!=null){
'''«variable.variable.compileVariable»'''
}
else if (variable.array!=null){
'''«variable.array.compileArray»'''
}
].join(",")
(i dont know your semantics)
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.03745 seconds