Skip to main content


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: 762
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: 14665
Registered: July 2009
Senior Member
simply escaping does not work?

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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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: 14665
Registered: July 2009
Senior Member
Can you open a ticket for that

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:news.eclipse.org is shutting down.
Next Topic:Indenting multiline values on serialization
Goto Forum:
  


Current Time: Thu Apr 25 02:33:09 GMT 2024

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

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

Back to the top