code generation with Xtend

佐手、 提交于 2019-12-11 16:46:24

问题


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:


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.



来源:https://stackoverflow.com/questions/26912227/code-generation-with-xtend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!