Generic Attribute rule [message #1765118] |
Tue, 06 June 2017 16:12  |
Eclipse User |
|
|
|
I am trying to formulate a rule for defining a generic attribute rule (URDFAttr below).
Attribute should be generic in this sense:
Within the context of an Inertia definition, the suggestions for var assignment i URDFAttr should be fetched from InertiaVars enums (wrapped in InertiaVarType to make alternative work)
In the context of an Origin definition, suggestions for var assignment should be fetched from OriginVars...
I can see the Literals from Inertia enum in debugger when getting to the scope def in scope file - but nothing is suggested in editor. I have a hunch it is because I am not forcing instantiation of the OriginVars and InertiaVars objects but xtext only allows me to do that for the Var ref in URDFAttr, and that gives me an error at runtime...
GRAMMAR
grammar org.xtext.example.enumm.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/enumm/MyDsl"
Model:
links+=Link*;
Link:
'Link' name=ID
inert+=Inertia*
origin+=Origin*
;
Origin:
'Origin'
attr+=URDFAttr
;
Inertia:
'Inertia' (name=ID)?
attr+=URDFAttr
;
URDFAttr:
var=[Var]
value=MyValueType
;
Var:
OriginVarType | InertiaVarType
;
enum OriginVars:
x='x' | y='y' | z='z' | roll='roll' | pitch='pitch' | yaw='yaw'
;
enum InertiaVars:
ixx='ixx' | ixy='ixy' | ixz='ixz' | iyy='iyy' | iyz='iyz' | izz='izz'
;
MyValueType:
INT | STRING
;
//Wrapping enum in type for alternative to work...
InertiaVarType:type=InertiaVars;
OriginVarType:type=OriginVars;
SCOPE:
class MyDslScopeProvider extends AbstractMyDslScopeProvider {
override IScope getScope(EObject exp, EReference ref) {
if (exp instanceof URDFAttr) {
//Generic Attribute: How to make sure only Inertia vars suggested in Inertia context? Origin in Origin, etc
val myscope = exp.eContainer
if (myscope instanceof Inertia) {
val test = MyDslPackage.Literals.INERTIA_VARS.ELiterals
Scopes::scopeFor(MyDslPackage.Literals.INERTIA_VARS.ELiterals as Iterable <? extends EObject>)
}
}
}
}
MODEL:
Link ll Inertia iii //here i would expect suggestions from the InertiaVars enum (ixx, ixy etc), but nothing...
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04626 seconds