|
|
Re: Boolean expressions grammar [message #653746 is a reply to message #653739] |
Thu, 10 February 2011 22:55 |
|
Hi,
what about using xpand polymorphism support
«IMPORT org::xtext::example::mydsl::myDsl»
«DEFINE main FOR Model-»
«FILE "test.txt"-»
«EXPAND expression FOREACH boolexprs»
«ENDFILE-»
«ENDDEFINE»
«DEFINE expression FOR BoolExpr»«name»«ENDDEFINE»
«DEFINE expression FOR And»And(«EXPAND expression FOR left»,«EXPAND expression FOR right»)«ENDDEFINE»
«DEFINE expression FOR Or»Or(«EXPAND expression FOR left»,«EXPAND expression FOR right»))«ENDDEFINE»
another possibility is to ask an expression for its metaType and use isAssignableFrom or you use the isInstance check
«DEFINE main FOR Model-»
«FILE "test.txt"-»
«EXPAND expression FOREACH boolexprs»
«ENDFILE-»
«ENDDEFINE»
«DEFINE expression FOR BoolExpr-»
«IF Or.isAssignableFrom(this.metaType)»
Or(«EXPAND expression FOR left»,«EXPAND expression FOR right»)
«ELSEIF And.isInstance(this)»
And(«EXPAND expression FOR left»,«EXPAND expression FOR right»)
«ELSE»
«name»
«ENDIF»
«ENDDEFINE»
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
Re: Boolean expressions grammar [message #653973 is a reply to message #653931] |
Sat, 12 February 2011 08:25 |
|
Hi,
it seems to me that you stumbled into a common pitfall of Xtexts mwe reader Componentent. I guess your workflow looks like this.
module workflow.MyDslGenerator
import org.eclipse.emf.mwe.utils.*
var targetDir = "src-gen"
var fileEncoding = "Cp1252"
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.mydsl.MyDslStandaloneSetup {}
load = {
slot = "boolexprs"
type = "BoolExpr"
}
}
component = org.eclipse.xpand2.Generator {
expand = "templates::Template::main FOREACH boolexprs"
outlet = {
path = targetDir
}
fileEncoding = fileEncoding
}
}
That that does is basically: Take all BoolExpr (really all, not only the root ones) that have a (qualified)name != null (which are a b and c) and call the root main definition in the Template foreach of them.
your strategy makes no sense to me: why do you want to have a file foreach expression no matter where it is in the tree? more bad: if the reader adds all the stuff to inital for loop, why doing recursive calls in the template.
I simpley Introduced a IQualifiedNameProvider to give the model a name and used a workflow like follows
package org.xtext.example.mydsl;
import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;
import org.xtext.example.mydsl.myDsl.Model;
public class MyQNP extends DefaultDeclarativeQualifiedNameProvider {
public String qualifiedName(Model model) {
return model.eResource().getURI().toString();
}
}
public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {
@Override
public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
return MyQNP.class;
}
}
module workflow.MyDslGenerator
import org.eclipse.emf.mwe.utils.*
var targetDir = "src-gen"
var fileEncoding = "Cp1252"
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.mydsl.MyDslStandaloneSetup {}
load = {
slot = "model"
type = "Model"
}
}
component = org.eclipse.xpand2.Generator {
expand = "templates::Template::main FOREACH model"
outlet = {
path = targetDir
}
fileEncoding = fileEncoding
}
}
I hope this gives you an idea how i solved the problem.
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Sat, 12 February 2011 08:32] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03590 seconds