твой обзор не имеет смысла.можно было бы ожидать что-то вроде
class MyDslScopeProvider extends AbstractMyDslScopeProvider {
override getScope(EObject context, EReference reference) {
if (reference == MyDslPackage.Literals.FIELD_SELECTION__FIELD) {
if (context instanceof FieldSelection) {
val rec = context.receiver
val fields = <Field>newArrayList
// TODO have a look at rec and calculate the visible fields from that
return Scopes.scopeFor(fields)
}
}
// TODO more else ifs for other places
super.getScope(context, reference)
}
}
, когда вы выбрасываете свою грамматику в мусорную корзину и начинаете с этого:
Model:
declarations+=Declaration*
assignments+=Assignment*;
Declaration:
"def" name=ID "{"
(fields+=Feature ("," fields+=Feature)*)?
"}"
;
Feature: type=Type name=ID;
Type: SimpleTypeDecl | DeclarationRef;
SimpleTypeDecl: type=SimpleType;
enum SimpleType:
int | string | boolean
;
Assignment:
assignee=DotExpression "=" value=Literal
;
DotExpression returns Ref:
DeclarationRef ({DotExpression.ref=current} "." tail=[Feature])*
;
DeclarationRef returns Ref:
{DeclarationRef} declaration=[Declaration]
;
Literal: StringLiteral | IntLiteral | BooleanLiteral;
BooleanLiteral: value?="true" | {BooleanLiteral}"false";
IntLiteral: value=INT;
StringLiteral: value=ID | value=STRING;
область видимости может выглядеть как
class MyDslScopeProvider extends AbstractMyDslScopeProvider {
override getScope(EObject context, EReference reference) {
if (reference == MyDslPackage.Literals.DOT_EXPRESSION__TAIL) {
if (context instanceof DotExpression) {
val ref = context.ref
if (ref instanceof DeclarationRef) {
return Scopes.scopeFor(ref.declaration.fields)
} else if (ref instanceof DotExpression) {
val feature = ref.tail
if (feature.type instanceof DeclarationRef) {
return Scopes.scopeFor((feature.type as DeclarationRef).declaration.fields)
}
}
}
return IScope.NULLSCOPE
}
super.getScope(context, reference)
}
}
и разбирать + прицельные модели как
def alpha { int a, int b}
def beta {alpha ax}
alpha.a = something
alpha.b = something
beta.ax.a = something