1
我想在XText的帮助下为jape language from gate构建工具支持。 Jape基本上是注释上的模式语言;你声明当你遇到这些注释时要采取的行动。问题是这些操作可以用java编写。在与jdt挣扎了一段时间之后,我无法使其处理解析内容的某些部分。所以我放弃了,并决定使用XBlockExpression的xbase支持。XText注册全局变量
问题是可以在操作中使用一些变量 - 例如,有一个变量绑定它允许您绑定,然后从模式中获取注释。所以我的问题是如何在xblock范围内注册这些变量。在阅读了3个小时的文档后,我仍然没有接近。
这里是我的问题最小语法
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
greetings=Greeting;
Greeting:
block=XBlockExpression;
我想这样的内容解析文件:
{
val testAS = bindings.get("test") as AnnotationSet
}
我开始在自己的范围内提供堵塞,但没有帮助我很多。下面是提供的实现:
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);
}
}
任何帮助将不胜感激