Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Escape new line in Xtend
Escape new line in Xtend [message #989115] Tue, 04 December 2012 11:44 Go to next message
Tommaso De Sica is currently offline Tommaso De Sica
Messages: 128
Registered: March 2012
Location: Italy
Senior Member

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:
int vi[10
	];


How can I delete that newline?

Very thank you!
Re: Escape new line in Xtend [message #989139 is a reply to message #989115] Tue, 04 December 2012 13:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6143
Registered: July 2009
Senior Member
Hi,

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
Re: Escape new line in Xtend [message #989203 is a reply to message #989139] Wed, 05 December 2012 03:44 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De Sica
Messages: 128
Registered: March 2012
Location: Italy
Senior Member

Christian Dietrich wrote on Tue, 04 December 2012 19:58
Hi,

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 03:45]

Report message to a moderator

Re: Escape new line in Xtend [message #989215 is a reply to message #989203] Wed, 05 December 2012 04:12 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6143
Registered: July 2009
Senior Member
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)
Previous Topic:Using xtext as third party
Next Topic:[Xtext] Changing java package naming after project is created
Goto Forum:
  


Current Time: Wed Jul 30 11:26:20 EDT 2014

Powered by FUDForum. Page generated in 0.03443 seconds