Scoping for dot/path expressions [message #1084909] |
Mon, 12 August 2013 03:52  |
Eclipse User |
|
|
|
Hello
I have a grammar with types and members and I want to specify the members using dot/path expressions. Similar to this example.
Only the valid members should be available for choice, i.e. the scope needs to be restricted to those members which are children of the structure specified as type of the parent member.
Grammar and scoping code attached. It does not work unfortunately.
Any help for finding the problem would be appreciated.
Grammar
Model:
types+=Type*
members+=Member*
usages+=Usage*
;
Type:
Elementary | Structure
;
Elementary:
"elementary" name=ID
;
Structure:
"structure" name=ID "{"
members+=Member*
"}"
;
Member:
"member" name=ID ":" type=[Type]
;
Usage:
"use" ref=DotExpression
;
DotExpression returns Ref:
MemberRef ({DotExpression.ref=current} "." tail=[Member])*
;
MemberRef returns Ref:
{MemberRef} member=[Member]
;
Scoping code
def IScope scope_DotExpression_tail(DotExpression exp, EReference ref) {
val head = exp.ref;
switch (head) {
MemberRef : Scopes::scopeFor((exp.eContainer as Model).members)
DotExpression : {
val type = head.tail.type
switch (type) {
Elementary : IScope::NULLSCOPE
Structure : Scopes::scopeFor(type.members)
default: IScope::NULLSCOPE
}
}
default: IScope::NULLSCOPE
}
}
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06896 seconds