Skip to main content


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 16:44 Go to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
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 18:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Escape new line in Xtend [message #989203 is a reply to message #989139] Wed, 05 December 2012 08:44 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
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 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 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
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)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Using xtext as third party
Next Topic:[Xtext] Changing java package naming after project is created
Goto Forum:
  


Current Time: Thu Apr 25 23:54:39 GMT 2024

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

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

Back to the top