A simple trick could be to have a $HOME string variable in your script whose value is... just... $HOME :-)
def $HOME = '$HOME' def done = "task complete" def script = ''' mv file_name $HOME echo $done ''' 2015-05-03 19:53 GMT+02:00 Paolo Di Tommaso <[email protected]>: > I think that AST cannot work here because the string has been already > parsed. > > > p > > > On Sun, May 3, 2015 at 7:30 PM, Dinko Srkoč <[email protected]> wrote: > >> On 3 May 2015 at 18:01, Paolo Di Tommaso <[email protected]> >> wrote: >> > Hi, >> > >> > I would need to implement a string literal in which the dollar char is >> not >> > interpreted as variable placeholder, indeed to use a custom character to >> > interpolate variables. >> > >> > For example I would like define a string like this: >> > >> > >> > def DONE = 'Task completed' >> > >> > >> > def script = /% >> > >> > mv file_name $HOME >> > echo %DONE >> > /% >> > >> > >> > >> > In which the $HOME string is ignored while %DONE is interpolated as a >> > groovy variable. >> > >> > Is there any way to do that ? >> >> Probably not ... although, I imagine it might be possible using AST >> transformations. >> >> On a related note, it would be interesting to have the ability to use >> a different GString implementation, instead of GStringImpl. >> >> Cheers, >> Dinko >> >> > >> > >> > Cheers, >> > Paolo >> > >> > >> > >> > > -- Guillaume Laforge Groovy Project Manager Product Ninja & Advocate at Restlet <http://restlet.com> Blog: http://glaforge.appspot.com/ Social: @glaforge <http://twitter.com/glaforge> / Google+ <https://plus.google.com/u/0/114130972232398734985/posts>
