Problems with Xpand [message #794552] |
Thu, 09 February 2012 07:36  |
sbl Missing name Messages: 32 Registered: March 2011 |
Member |
|
|
Hi,
I have some problems with code generation with Xpand.
I defined a grammer and created an instance model. Then I like some templates in Xpand. The first problem is: My template codes do not see my keywords that I defined in Xtext part. For example, I have a plan rule in Xtext:
Plan:
'Plan' name=ID type=STRING description=STRING priority=INT ';';
and I use Plan keyword in Xpand like this:
«EXPAND plans FOREACH plan» But it gives "collection types expected" errors.
The second problem is: I defined a simpe gramer in Xtext and a simple template in XPand. Then, I created an instance model with defined grammer. While I run .xpt file(xpand file) It gives "no plan element found "errors although I have plan element in my instance model.
My last question is: There are many versions of Xtext, Xpand and Xtend tools. And tutorials are generally specific for these versions. For example in mine, I have a workflow package and "MyDslGenerator" which is not an .xml file. I do not know how can I modifiy this file.
If somebody could help me, I would be very happy. Thank you very much.
[Updated on: Thu, 09 February 2012 07:45] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Problems with Xpand [message #797471 is a reply to message #797465] |
Mon, 13 February 2012 09:33   |
sbl Missing name Messages: 32 Registered: March 2011 |
Member |
|
|
Thank you very much for all your replies. Lastly, I want to ask something else.
It seems like simple but I can not fix the problems.
My Xtext File is this:
main:
input+=Input|output+=Output
Input:
'Input' name=ID ';' ;
Output:
'Output' name=ID ';';
My instance Model is this:
Input input2;
Output output2;
It seems too simple. But I couldn't understand where the problem is. I only want to generate two files for each "input" and "output" elements. (For example one file for input1 and one file for output1)
My template file is this:
«IMPORT org::xtext::example::mydsl2::myDsl»
«EXTENSION templates::Extensions»
«DEFINE inputfile FOR Input»
«FILE name+".txt"»
This is an example of a generated file.
«ENDFILE-»
«ENDDEFINE»
«DEFINE outputfile FOR Output»
«FILE name+".txt"»
This is an example of a generated file.
«ENDFILE-»
«ENDDEFINE»
My Generator file is this:
module workflow.MyDslGenerator
import org.eclipse.emf.mwe.utils.*
var targetDir = "src-gen"
var fileEncoding = "Cp1254"
var modelPath = "src/model"
Workflow {
component = org.eclipse.xtext.mwe.Reader {
// lookup all resources on the classpath
// useJavaClassPath = true
// or define search scope explicitly
path = modelPath
// this class will be generated by the xtext generator
register = org.xtext.example.mydsl2.MyDslStandaloneSetup {}
load = {
slot = "slot1"
type = "Input"
}
load = {
slot = "slot2"
type = "Output"
}
}
component = org.eclipse.xpand2.Generator {
expand = "templates::Template::main FOREACH {{slot1},{slot2}}"
outlet = {
path = targetDir
}
fileEncoding = fileEncoding
}
}
When I run generator file, I got many errors.
[Updated on: Mon, 13 February 2012 09:34] Report message to a moderator
|
|
|
| Re: Problems with Xpand [message #797476 is a reply to message #797471] |
Mon, 13 February 2012 09:40   |
Christian Dietrich Messages: 4387 Registered: July 2009 |
Senior Member |
|
|
hi,
templates::Template::main FOREACH {slot1,slot2}.flatten()
with
«IMPORT org::xtext::example::mydsl2::myDsl»
«EXTENSION templates::Extensions»
«DEFINE main FOR Input»
«FILE name+".txt"»
This is an example of a generated file.
«ENDFILE-»
«ENDDEFINE»
«DEFINE main FOR Output»
«FILE name+".txt"»
This is an example of a generated file.
«ENDFILE-»
«ENDDEFINE»
or having two generator components schould do the trick
[Updated on: Mon, 13 February 2012 09:41] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.01963 seconds