這裏可能是一個起點
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types
Model:
imports=XImportSection?
elements+=Element*
;
Element:
"element" "{"
"modelname" "=" type=JvmTypeReference
"variable" "names" "=" memberReferences+=MemberReference ("," memberReferences+=MemberReference)*
"}"
;
MemberReference:
member=[types::JvmField|ID]
;
並按照適應範圍提供商
package org.xtext.example.mydsl.scoping
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EReference
import org.eclipse.xtext.EcoreUtil2
import org.xtext.example.mydsl.myDsl.Element
import org.xtext.example.mydsl.myDsl.MyDslPackage
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.Scopes
import org.eclipse.xtext.common.types.JvmDeclaredType
import org.eclipse.xtext.naming.QualifiedName
class MyDslScopeProvider extends AbstractMyDslScopeProvider {
override getScope(EObject context, EReference reference) {
if (reference == MyDslPackage.Literals.MEMBER_REFERENCE__MEMBER) {
val element = EcoreUtil2.getContainerOfType(context, Element)
if (element != null) {
val type = element.type.type
if (type instanceof JvmDeclaredType) {
return Scopes.scopeFor(type.declaredFields, [QualifiedName.create(simpleName)], IScope.NULLSCOPE)
}
}
return IScope.NULLSCOPE
}
super.getScope(context, reference)
}
}
方案提供商
class MyDslProposalProvider extends AbstractMyDslProposalProvider {
override protected isKeywordWorthyToPropose(Keyword keyword) {
true
}
}
Sry基因,我不能跟着你的。你能給更多的上下文嗎? EG是一個語法和一個完整的模型 –