Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Problems with Xpand(I have some problems with Xpand)
icon9.gif  Problems with Xpand [message #794552] Thu, 09 February 2012 12:36 Go to next message
sbl Missing name is currently offline 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 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 354
Registered: July 2009
Location: Dortmund
Senior Member

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, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Problems with Xpand [message #794640 is a reply to message #794589] Thu, 09 February 2012 14:31 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing name
Messages: 32
Registered: March 2011
Member

Thank you very much for your reply.

I modified mwe2 file as you mentioned. But I have more than one Eclasses. How can I assign more then one Eclass to "type" variable?

I am reading Xtext documentaion now, thank you very much.
Re: Problems with Xpand [message #794686 is a reply to message #794640] Thu, 09 February 2012 15:22 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 354
Registered: July 2009
Location: Dortmund
Senior Member

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, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Problems with Xpand [message #795359 is a reply to message #794686] Fri, 10 February 2012 11:32 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing name
Messages: 32
Registered: March 2011
Member
Thank you very much for your reply,

When I put assign elements to different slots, I got " Couldn't resolve reference to JvmFeature 'slot2'" error.

I am realy confused:(

Thank you very much for your replies.

[Updated on: Fri, 10 February 2012 12:41]

Report message to a moderator

Re: Problems with Xpand [message #795594 is a reply to message #795359] Fri, 10 February 2012 16:52 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 354
Registered: July 2009
Location: Dortmund
Senior Member

Does the Reader component write to different slots? How does your MWE2 workflow now look like?

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Problems with Xpand [message #797204 is a reply to message #795594] Mon, 13 February 2012 07:05 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing name
Messages: 32
Registered: March 2011
Member
When I assign plan to slot1 and type it gives two errors. My .mw2 file is like 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 = {
slot1 = "plan"
type1 = "Plan"
}
}

component = org.eclipse.xpand2.Generator {
expand = "templates::Template::main FOREACH plan"
outlet = {
path = targetDir
}
fileEncoding = fileEncoding
}
}


I could not add the other Eclasses becaouse of errors.

P.S: Sorry for the late reply I was in another country for a conference.
Re: Problems with Xpand [message #797220 is a reply to message #797204] Mon, 13 February 2012 07:37 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 354
Registered: July 2009
Location: Dortmund
Senior Member

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, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Problems with Xpand [message #797233 is a reply to message #797220] Mon, 13 February 2012 08:03 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing name
Messages: 32
Registered: March 2011
Member
Thank you very much. I changed slots and added : expand = "my::template FOREACH {${slot1},${slot2}}"
My new mw2 file is like 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 = "Plan"
}
load = {
slot = "slot2"
type = "Goal"
}
}

component = org.eclipse.xpand2.Generator {
expand = "templates::Template::main FOREACH {${slot1},${slot2}}"
outlet = {
path = targetDir
}
fileEncoding = fileEncoding
}
}

This time new errors are occured.

Multiple markers at this line
- Couldn't resolve reference to Referrable 'slot2'.
- Couldn't resolve reference to Referrable 'slot1'.

Thank you very much for your helps, I read the documentations but I can not solve the problems:(
Re: Problems with Xpand [message #797332 is a reply to message #797233] Mon, 13 February 2012 10:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6395
Registered: July 2009
Senior Member
Hi this ${slot} makes no sense to me. Guess you mean just slot
without the dollar thing
Re: Problems with Xpand [message #797454 is a reply to message #797332] Mon, 13 February 2012 14:06 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing name
Messages: 32
Registered: March 2011
Member
Thank you very much,
I think the problem occurs because of expand = "templates::Template::main FOREACH {${slot1},${slot2}}" line because I got this error:

0 [main] ERROR org.eclipse.xpand2.Generator - Error in Component of type org.eclipse.xpand2.Generator:
EvaluationException : No Definition 'templates::Template::main for List' found!
[23,58] on line 1 'EXPAND templates::Template::main FOREACH {{slot1},{slot2}}'

Re: Problems with Xpand [message #797465 is a reply to message #797454] Mon, 13 February 2012 14:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6395
Registered: July 2009
Senior Member
So id expect something like

'EXPAND templates::Template::main FOREACH {slot1,slot2}.flatten'
Re: Problems with Xpand [message #797468 is a reply to message #797454] Mon, 13 February 2012 14:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6395
Registered: July 2009
Senior Member
Hi can you once more post your complete workflow and template and
what you want to achieve
Re: Problems with Xpand [message #797471 is a reply to message #797465] Mon, 13 February 2012 14:33 Go to previous messageGo to next message
sbl Missing name is currently offline 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 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6395
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 14:41]

Report message to a moderator

Re: Problems with Xpand [message #797485 is a reply to message #797476] Mon, 13 February 2012 14:53 Go to previous message
sbl Missing name is currently offline sbl Missing name
Messages: 32
Registered: March 2011
Member
It works now!!! Thank you very much!!! Smile
Previous Topic:Generating more than one files
Next Topic:Xpand and Xtend2/Xtext
Goto Forum:
  


Current Time: Thu Oct 30 18:35:09 GMT 2014

Powered by FUDForum. Page generated in 0.05670 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software