| [XPAND] Generating More Than One Instance [message #808859] |
Tue, 28 February 2012 03:23  |
sbl Missing name 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 #810918 is a reply to message #810551] |
Thu, 01 March 2012 12:28   |
Christian Dietrich Messages: 4419 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
}
[Updated on: Thu, 01 March 2012 12:29] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06948 seconds