Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtend Template Expressions using ' at the end of '''
Xtend Template Expressions using ' at the end of ''' [message #1742103] Wed, 31 August 2016 12:37 Go to next message
Tobias L. is currently offline Tobias L.Friend
Messages: 24
Registered: July 2010
Junior Member
Hello,

we have some Extension-Methods like

def buildAName(p1, p2, p3) {
    '''p1.p2_p3'''
}


Some of these methods have to return a value encapsuled in '<value>' (single quote).

So... that is not valid in xtend.

def buildAName(p1, p2, p3) {
    ''''p1.p2_p3''''
}


The ' at the end makes an compiler error.

This helps, but... not so beautiful in the output.
def buildAName(p1, p2, p3) {
    ''''p1.p2_p3' '''
}


Is there a possibility to "mask" the second ' at the end or something like that?

Thank you for your support,
Tobias
Re: Xtend Template Expressions using ' at the end of ''' [message #1742104 is a reply to message #1742103] Wed, 31 August 2016 12:56 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 557
Registered: July 2009
Location: Dortmund, Germany
Senior Member

You could write an extension method that puts the result string in single quotes:
	def buildAName(String p1, String p2, String p3) {
		'''«p1».«p2»_«p3»'''.quote
	}
	
	def quote (CharSequence s) {
		"'"+s+"'"
	}
Re: Xtend Template Expressions using ' at the end of ''' [message #1742105 is a reply to message #1742103] Wed, 31 August 2016 12:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11502
Registered: July 2009
Senior Member
simply escaping does not work?

	def buildAName(String p1, String p2, String p3) {
    	return '''\'p1 p2 p3\'''
	}


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Xtend Template Expressions using ' at the end of ''' [message #1742224 is a reply to message #1742105] Wed, 31 August 2016 21:02 Go to previous messageGo to next message
Tobias L. is currently offline Tobias L.Friend
Messages: 24
Registered: July 2010
Junior Member
That not works.

class Main {
	def static void main(String[] args) {
		val x = '''\'blabla\'''
		println('''"«x»"''')
	}
}


will procude the output

"\'blabla\"



Re: Xtend Template Expressions using ' at the end of ''' [message #1742225 is a reply to message #1742104] Wed, 31 August 2016 21:05 Go to previous messageGo to next message
Tobias L. is currently offline Tobias L.Friend
Messages: 24
Registered: July 2010
Junior Member
I know the with the quotation in an extension method, but it's not so sexy as the Template Expression Language Wink

... but that is the only solution that i can imagine.

Thank you!
Re: Xtend Template Expressions using ' at the end of ''' [message #1742236 is a reply to message #1742225] Thu, 01 September 2016 04:56 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11502
Registered: July 2009
Senior Member
Can you open a ticket for that

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Previous Topic:news.eclipse.org is shutting down.
Next Topic:Indenting multiline values on serialization
Goto Forum:
  


Current Time: Sat Dec 16 20:38:18 GMT 2017

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

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