Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [XPAND] Generating More Than One Instance
[XPAND] Generating More Than One Instance [message #808859] Tue, 28 February 2012 08:23 Go to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
Hi,

I have some problems about generating more than one instance elements.
I have 3 distinct instance "input" elements in my model. I want to generate a file and put all instance element's name in it. For example:

Sample.txt:

input1
input2
input3

Unfortunally I see only one of them in my generated files with these codes:

Xtext file:
main:
(input+=Input|output+=Output)*
Input:
'Input' name=ID ';' ;
Output:
'Output' name=ID ';';

Template file:

«IMPORT org::xtext::example::mydsl2::myDsl»
«EXTENSION templates::Extensions»
«DEFINE main FOR Input»
«FOREACH ((main)eContainer()).input AS in»
«FOREACH ((main)eContainer()).output AS out»
«FILE name+".txt"»
This is an example of a generated file.
«in.name»
«out.name»
«ENDFILE-»
«ENDDEFINE»
Re: [XPAND] Generating More Than One Instance [message #808915 is a reply to message #808859] Tue, 28 February 2012 09:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi either the file statement is at the wrong place or you have to
configure your outlet to work in append mode


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Generating More Than One Instance [message #808936 is a reply to message #808915] Tue, 28 February 2012 09:59 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
Hi,

I replaced the file statement, the program does not give errors but it only gives one instance's name.
Re: [XPAND] Generating More Than One Instance [message #808967 is a reply to message #808936] Tue, 28 February 2012 10:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
How do workflow and template look like

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Generating More Than One Instance [message #808975 is a reply to message #808967] Tue, 28 February 2012 10:41 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
template is :

Template file:

«IMPORT org::xtext::example::mydsl2::myDsl»
«EXTENSION templates::Extensions»
«DEFINE main FOR Input»
«FOREACH ((main)eContainer()).input AS in»
«FOREACH ((main)eContainer()).output AS out»
«FILE name+".txt"»
This is an example of a generated file.
«in.name»
«out.name»
«ENDFILE-»
«ENDDEFINE»


workflow is:

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 = "main"
}




}

component = org.eclipse.xpand2.Generator {
expand = "templates::Template::main FOREACH slot1"
outlet = {
path = targetDir
}
fileEncoding = fileEncoding
}
}
Re: [XPAND] Generating More Than One Instance [message #809033 is a reply to message #808975] Tue, 28 February 2012 12:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you call your workflow for inputs
=> it will be called foreach input

you have the file within the foreachs (the partial template you posted indicates that)
=>
you will call the file foreach output

=> it will not work

you have as i said (3) options

(1) restructure the templates to take a main (root of your dsl) as generation root
(you might have to trick cause it does not have a name - but the solution for that is described 1000 times in the forum - you wíll see if you google for the errror message)

(2) restructure the template (but beeing inefficient)

«IMPORT org::xtext::example::mydsl2::myDsl»
«EXTENSION templates::Extensions»
«DEFINE main FOR Input»
«FILE name+".txt"»
«FOREACH ((main)eContainer()).input AS in»
«in.name»
«ENDFOREACH»
«FOREACH ((main)eContainer()).output AS out»
«out.name»
«ENDFOREACH»
«ENDFILE-»
«ENDDEFINE»

(3) or you configure the outlet with append=true in the workflow


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Generating More Than One Instance [message #810551 is a reply to message #809033] Thu, 01 March 2012 08:37 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
Hi,

Thank you for yor replies.

1. main is root of my DSL? Unfortunally I could not understand the solution.

2. I tried the second solution but it didn't help me because I want to invoke «in.name» in several places and several times.

3. How can I add append=true in my workflow?
Do I need add this statement for both input and output?

Thank you very much.
Re: [XPAND] Generating More Than One Instance [message #810918 is a reply to message #810551] Thu, 01 March 2012 17:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

it is quite easy

(1) if you change the template to

«DEFINE main FOR main-»
«FILE "test.txt"-»
«FOREACH input AS i»
«i.name»
«ENDFOREACH»
«FOREACH output AS o»
«o.name»
«ENDFOREACH»
«ENDFILE-»
«ENDDEFINE»


and the workflow to

	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.mydsl1.MyDslStandaloneSetup {}
		load = {
			slot = "main"
			type = "main"
		}
	}

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


you will get the error message

0    [main] DEBUG        org.eclipse.xtext.mwe.Reader  - Resource Pathes : [src/model]
0    [main] INFO         org.eclipse.xpand2.Generator  - No meta models configured, using JavaBeans as default.
141  [main] DEBUG xt.validation.ResourceValidatorImpl  - Syntax check OK! Resource: file:/C:/work/xtext/Xtext102/ws_xxxxx/org.xtext.example.mydsl1.generator/src/model/Example.mydsl1
219  [main] WARN      org.eclipse.xtext.mwe.SlotEntry  - Could not find any exported element of type 'main' -> Slot 'main' is empty.
251  [main] INFO  .emf.mwe2.runtime.workflow.Workflow  - Done.


you can work arround this (this is the place where i asked you to google)
e.g. using a IQualifiedNameProvider that gives the main a name

btw you should have go this error message anyway. at least with the workflow you posted

(2) since you example is very very simple and you did not say anything regarding your problem i still do not understand why you cannot do something like

«IMPORT org::xtext::example::mydsl2::myDsl»
«EXTENSION templates::Extensions»
«DEFINE main FOR Input»
«FILE name+".txt"»
«FOREACH ((main)eContainer()).input AS in»
«in.name»
«ENDFOREACH»
«FOREACH ((main)eContainer()).output AS out»
«out.name»
«ENDFOREACH»
«FOREACH ((main)eContainer()).input AS in»
«in.name»
«ENDFOREACH»
«FOREACH ((main)eContainer()).output AS out»
«out.name»
«ENDFOREACH»
«FOREACH ((main)eContainer()).input AS in»
«in.name»
«ENDFOREACH»
«FOREACH ((main)eContainer()).output AS out»
«out.name»
«ENDFOREACH»
«ENDFILE-»
«ENDDEFINE»


(3)

what about simple

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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 01 March 2012 17:29]

Report message to a moderator

Re: [XPAND] Generating More Than One Instance [message #813418 is a reply to message #810918] Mon, 05 March 2012 08:38 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
Hi,

Thanks for replies. My essential problem is I do not know how many instance "input" or "output" elements in the instance model. I mean, I can not use

«FOREACH ((main)eContainer()).input AS in»
«in.name»
«ENDFOREACH»

because I do not know how many times do I have to use it. There may be one input1 or 5 inputs(input1, input2, ... , input5)
Re: [XPAND] Generating More Than One Instance [message #813425 is a reply to message #813418] Mon, 05 March 2012 08:44 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
I still do not see why this is a problem

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:[Acceleo] quick question on acceleo
Next Topic:[Acceleo] How to generate a sequence (bag) of consecutive integers starting at 1
Goto Forum:
  


Current Time: Thu Apr 25 12:53:18 GMT 2024

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

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

Back to the top