0
votes

I am implementing my own DSL and using Xtend to generate C code. I have developed small prototype using XPand/Xtend but now I need to convert prototype into XTend.

In Xpand, I used to define "Generate" function to generate C file but I don't know how can I do similar thing using XTend. Any help in this regard would be highly appreciated.

«DEFINE Generate FOR dsl::defs::module»
«FILE "Com.c" -»
/* DATE «dateString()» */
«EXPAND COM_C::COM_Def_C »
«ENDFILE»
«ENDDEFINE»

Thanks and Regards, Hemal Bavishi

1
I got some hint on this - Unlike XPand where you define the type of the file, you get data in buffer and then you need to dump the data in the file. This is how other engine like JET works. I will try to document the difference between XPand and XTend and upload the same. I love this technology and will upload the example soon. Enjoy:) - Hemal Bavishi

1 Answers

0
votes

You could do something like this:

def xtendFunc() '''
/* DATE «dateString()» */
'''

or

def xtendFunc() {
var = '''/* DATE «dateString()» */'''
return var
}

(Assuming the 'dateString()' function is in the same class) This in Xtend is called using template expressions(Enclosed within three quotes '''...'''). You can contain the result of the function in a val (final variable in Xtend) for the first case. Then use another function for the other template COM_C:COM_Def_C. Append the result into a variable and write into a file using simple java.