Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Referring to user-defined variables from Xbase expressions
Referring to user-defined variables from Xbase expressions [message #1038150] Wed, 10 April 2013 09:17 Go to next message
Oren Mishali is currently offline Oren Mishali
Messages: 15
Registered: March 2013
Junior Member
Hi all,
In my DSL I use Xbase expressions, and I would like to refer from within the expressions to other variables defined in the DSL. For example:

mydsl {
  condition c1 = false, c2 = true;
  requires c1 && c2;
}


Note that c1 and c2 are NOT Xbase variables, they are defined using a native grammar. The grammar of the requires clause is defined as follows:

Requires:
	'requires' expression = XOrExpression ';'
;


I tried to to somehow modify MyDslScopeProvider but without success -- I still get
"Couldn't resolve reference to JvmIdentifiableElement 'c1'" errors.

Thanks in advance,
Oren
Re: Referring to user-defined variables from Xbase expressions [message #1038293 is a reply to message #1038150] Wed, 10 April 2013 13:31 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6137
Registered: July 2009
Senior Member
Hi,

this is usually done via JvmModelInferrer.
here an example

Model:
	vars+=Var*
	expression = XOrExpression
;

Var:
	"var" name=ID
;


class MyDslJvmModelInferrer extends AbstractModelInferrer {

    /**
     * convenience API to build and initialize JVM types and their members.
     */
	@Inject extension JvmTypesBuilder

   	def dispatch void infer(Model element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
   		acceptor.accept(element.toClass("my.company.greeting.MyGreetings"))
   			.initializeLater([
   				for (v : element.vars) {
   					members += v.toField(v.name, v.newTypeRef(Boolean::TYPE))
   				}
   				members += element.toMethod("xxxx", element.newTypeRef(Boolean::TYPE)) [
   						body = element.expression
   					]
   			])
   	}
}

Previous Topic:Creating an Outline
Next Topic:Need a hint for dynamic imports
Goto Forum:
  


Current Time: Mon Jul 28 14:41:11 EDT 2014

Powered by FUDForum. Page generated in 0.01771 seconds