Problems with Xpand [message #794552] |
Thu, 09 February 2012 12: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 12:45] Report message to a moderator
|
|
|
Re: Problems with Xpand [message #794589 is a reply to message #794552] |
Thu, 09 February 2012 13:27 |
|
Xpand evaluates the metamodel. Xtext derived such metamodel from the grammar. But Xpand does not evaluate on an Xtext grammar!
This means: From the grammar you posted you get derived an EClass named "Plan" with this structure:
Plan [EClass]
+-- name: EString
+-- type: EString
+-- description: EString
+-- priority: EInt
There is no multi reference called "plans" here, thus you get the error "collection types expected".
When you read models in the workflow using the org.eclipse.xtext.mwe.Reader component you should get Plan elements loaded into the slot when specifying that you want to select the type "Plan".
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 = MyDslStandaloneSetup {}
load = {
type="Plan"
}
The workflow file that you are referring to having the MyDslGenerator component is likely an MWE2 file (.mwe2 extension). The XML file format is MWE1 (.mwe file extension). A reference to MWE2 is part of the Xtext documentation, please read this one.
Also, you will have content assist on these files, which MWE1 did not have. It is easier to implement MWE2 files. However, a basic understanding of MWE can help here.
Kind regards,
~Karsten
Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
|
|
|
|
Re: Problems with Xpand [message #794686 is a reply to message #794640] |
Thu, 09 February 2012 15:22 |
|
Add multiple "load" entries and put them into different slot names, then invoke the generator with
Generator {
expand = "my::template FOREACH {${slot1},${slot2}}"
Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
|
|
|
|
|
|
Re: Problems with Xpand [message #797220 is a reply to message #797204] |
Mon, 13 February 2012 07:37 |
|
It must be something like this:
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 = "Plan"
}
load = {
slot = "slot2"
type = "OtherType"
}
}
Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
|
|
|
|
|
|
|
|
Re: Problems with Xpand [message #797471 is a reply to message #797465] |
Mon, 13 February 2012 14: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 14:34] Report message to a moderator
|
|
|
Re: Problems with Xpand [message #797476 is a reply to message #797471] |
Mon, 13 February 2012 14:40 |
|
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
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Mon, 13 February 2012 14:41] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.06262 seconds