Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Generating more than one files
Generating more than one files [message #797242] Mon, 13 February 2012 03:17 Go to next message
sbl Missing name is currently offline sbl Missing name
Messages: 32
Registered: March 2011
Member
Hi,
I am new in Xpand. Although I read all related documentations and watched videos about Xpand, I still have problems. Sad

I defined an Xtext grammer. It is like this:

main:
input+=Input|output+=Output
Input:
'Input' name=ID ';' ;
Output:
'Output' name=ID ';';

Than I created an instance model like this:

Input input2;
Output output2;

Now I want to generate a file for each "input" and "output" elements. (For example one file for input1 and one file for output1)

I wrote this template:

«DEFINE input FOR Input»
«FILE this.name + ".xml"»

«DEFINE output FOR Output»
«FILE this.name + ".xml"»

But it does not work Crying or Very Sad Do I need to start with "main" element? I will be very happy if somebody can help me. Thank you very much
Re: Generating more than one files [message #797249 is a reply to message #797242] Mon, 13 February 2012 03:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6126
Registered: July 2009
Senior Member
Yes you have to start with a main define or call both templates from
the workflow
Re: Generating more than one files [message #797268 is a reply to message #797249] Mon, 13 February 2012 03:58 Go to previous message
sbl Missing name is currently offline sbl Missing name
Messages: 32
Registered: March 2011
Member
Thank you very much,

My template is exactly 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-»

«DEFINE outputfile FOR Output»
«ENDDEFINE»

It is Ok or am I have to define a main ?

My mw2 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
}
}

But it gives errors:
Multiple markers at this line
- Couldn't resolve reference to Referrable 'slot1'.
- Couldn't resolve reference to Referrable 'slot2'.
Previous Topic:3rd Biannual Eclipse/OMG Workshop on March 25
Next Topic:Problems with Xpand
Goto Forum:
  


Current Time: Wed Jul 23 18:12:13 EDT 2014

Powered by FUDForum. Page generated in 0.01704 seconds