Register variables in xtext block of code [message #900963] |
Thu, 09 August 2012 08:54 |
Nikola Petrov Messages: 4 Registered: August 2012 |
Junior Member |
|
|
Hi, I want to be able to register variables as if they were defined in the scope of an xbase block. The Idea is that I want to write tool support for a language that has implicit variables defined in a block of code. For example one of the variables bindings is just a HashMap<String, String>. I want to be able to use that in the block of code as if it was already defined. After reading the whole documentation I am not able to find a solution
Here is a minimal grammar for my problem
(Sorry but the forum recognizes the target namespace as a link and doesn't let me write as I don't have enough posts here)
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase
generate myDsl "www.xtext.org/example/mydsl/MyDsl"
Model:
greetings=Greeting;
Greeting:
block=XBlockExpression;
I want to parse files with content like this:
{
val testAS = bindings.get("test") as AnnotationSet
}
I started by plugging in my own scope provider but that didn't help me much. Here is the implementation for the provider:
package org.xtext.example.mydsl;
import java.util.List;
public class MyScopeProvider extends XbaseScopeProvider {
XbaseFactory factory = new XbaseFactoryImpl();
@Override
public IScope getScope(EObject context, EReference reference) {
//System.err.println(context);
//System.err.println(reference);
List<IValidatedEObjectDescription> descriptions = Lists.newArrayList();
XVariableDeclaration variableDeclaration = factory
.createXVariableDeclaration();
variableDeclaration.setName("bindings");
IValidatedEObjectDescription variableDescription = createLocalVarDescription(variableDeclaration);
System.err.println(variableDescription);
IScope scope = super.getScope(context, reference);
System.err.println(variableDeclaration);
return new JvmFeatureScope(scope, "test", descriptions);
}
}
Any help will be appreciated, thanks in advance!
[Updated on: Thu, 09 August 2012 08:55] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02404 seconds