Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Making change to DotExpression example
Making change to DotExpression example [message #1763439] Tue, 16 May 2017 04:00 Go to next message
Eclipse UserFriend
Hi Christian :)

I am are working on a solution inspired by your blog post:
https://christiandietrich.wordpress.com/2013/05/18/xtext-and-dot-expressions/

I have to make a significant change in our implementation though. I do not - at present at least - have an equivalent to the Feature interface from your example (se egrammar below - I have adjusted your example to my scenario), so I cannot reference attributes and references of the entity through this handle - we have to access it as EAttributes and ERefs of the Containing entity.

Our question is: Is it possible to reference EAttributes and EReferences on the Entity object from the DotExpression?

I am thinking in lines of something like EStructuralFeature from ecore lib to get list of EReference and EAttribute- if that can give me access to instances, and not only info on class 'blueprint'? I have tried to update grammar and scope files in different ways, but with no luck...

I hope the question is detailed enough to make sense...otherwise let me know :)


GRAMMAR:
Model:
    entities+=Entity*
    usages+=Usage*
;

//No Feature interface. Attribute and reference are defined as EAttr and ERefs directly on Entity ...
 
Entity:
    "entity" name=ID "{"
	"attr" name=ID ":" type=DataType
	"ref" name=ID ":" type=[Entity]
    "}"
;

enum DataType:
    string | int
;

//No Feature, Attribute or Ref available
/*Feature:
    Attribute | Reference
;
 
Attribute:
    "attr" name=ID ":" type=DataType
;
 
Reference:
    "ref" name=ID ":" type=[Entity]
;*/

 
Usage:
    "use" ref=DotExpression
;
 
DotExpression returns Ref:
    EntityRef ({DotExpression.ref=current}  "." tail=[How to reference att and ref from entity??])*
;
 
EntityRef returns Ref:
    {EntityRef} entity=[Entity]
; 

SCOPE PROVIDER:

class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
	def IScope scope_DotExpression_tail(DotExpression exp, EReference ref) {
        val head = exp.ref;
        switch (head) {
            //EntityRef : Scopes::scopeFor(head.entity.features)
            EntityRef : Scopes::scopeFor(head.entity.eCrossReferences)
            DotExpression : {
                val tail = head.tail
                switch (tail) {
                    EAttribute : IScope::NULLSCOPE
                    EReference : Scopes::scopeFor(tail.eCrossReferences)
                    //Reference : Scopes::scopeFor(tail.type.features)
                    default: IScope::NULLSCOPE
                }
            }
             
            default: IScope::NULLSCOPE
        }
    }
}
Re: Making change to DotExpression example [message #1763441 is a reply to message #1763439] Tue, 16 May 2017 04:10 Go to previous messageGo to next message
Eclipse UserFriend
No you can reference objects only. of course you can give the object the name of a value of a attribute or reference (for this one use NodeModelUtils to retrieve the text)

maybe i did not get what you actually want to do. can you give an example of "what" you want to reference ?!?
Re: Making change to DotExpression example [message #1763445 is a reply to message #1763441] Tue, 16 May 2017 05:13 Go to previous messageGo to next message
Eclipse UserFriend
We would like to be able to access the refs and attributes of the current entity object via the dot expression like and with the use keyword in your example - see below. But our metamodel is already very fragmented as it is, so we fear it will be a change for the worse to move all the attr and ref out of the entity into objects and fragment it further...that is why we would like to investigate if we can leave them there and still find a way to reference in DotExpression. Hope it makes sense :)

entity A { 
	attr hello : string
}

use A.hello

Re: Making change to DotExpression example [message #1763446 is a reply to message #1763445] Tue, 16 May 2017 05:19 Go to previous messageGo to next message
Eclipse UserFriend
but this means you reference a Attribute not a EAttribute.
this is what my blog does
Re: Making change to DotExpression example [message #1763467 is a reply to message #1763446] Tue, 16 May 2017 08:59 Go to previous messageGo to next message
Eclipse UserFriend
yes we understand :) but we are trying to modify your example to 'use' or 'dot our way' through EReferences and EAttrbutes of Entity - instead of Attribute and Reference made from EClass as in your example. But if it cannot be done we will have to find another way...
Re: Making change to DotExpression example [message #1763473 is a reply to message #1763467] Tue, 16 May 2017 09:46 Go to previous messageGo to next message
Eclipse UserFriend
yes but this i dont understand. please explain

EReferences and EAttrbutes of Entity
Re: Making change to DotExpression example [message #1763749 is a reply to message #1763473] Fri, 19 May 2017 05:42 Go to previous messageGo to next message
Eclipse UserFriend
ok - basically I can boil my question down to: Is it possible to adjust your DotExpression example, so it's not Attribute and Reference EClasses with supertype Feature. that is 'traversed' (like in your example) - but instead atttribute and references are defined 'directly on Entity class' like seen below. I guess we are trying to move the example down one level of abstraction in the modeling hierarchy if that makes sense?

The types to traverse in DotExpression in this case will be EAttribute and EReference of the Entity but not trivial to make this change in grammar I guess :)

Entity:
    "entity" name=ID "{"
    	"attribute" type=INT
    	"reference" ref=[Entity|ID]
    "}"
; 
Re: Making change to DotExpression example [message #1763751 is a reply to message #1763749] Fri, 19 May 2017 06:01 Go to previous messageGo to next message
Eclipse UserFriend
sorry i still dont understand. what is what my example is all about ?!?!?!?!?

use A.a1



entity A {
    attr a1 : int
    attr a2 : string
    ref b : B
    ref c : C
}


a1 is a attribute of entity A
Re: Making change to DotExpression example [message #1763752 is a reply to message #1763751] Fri, 19 May 2017 06:02 Go to previous messageGo to next message
Eclipse UserFriend
so please give an example model and an example dot expression
Re: Making change to DotExpression example [message #1763762 is a reply to message #1763752] Fri, 19 May 2017 07:14 Go to previous messageGo to next message
Eclipse UserFriend
ok - grammar would look as seen below. I have put EStructuralFeature in DotExpression tail as a handle to access attribute and reference in Entity, but this will not work - but it is the best substitute for Feature in your example, I can think of at this level of abstraction...

grammar org.xtext.example.mydot.MyDot with org.eclipse.xtext.common.Terminals

generate myDot "http://www.xtext.org/example/mydot/MyDot"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Model:
    entities+=Entity*
    usages+=Usage*
;
 
Entity:
    "entity" name=ID "{"
    	"attribute" type=INT
    	("reference" ref=[Entity|ID])?
    "}"
;
 
Usage:
    "use" ref=DotExpression
;
 
DotExpression returns Ref:
    EntityRef ({DotExpression.ref=current}  "." tail=[ecore::EStructuralFeature])*
;
 
EntityRef returns Ref:
    {EntityRef} entity=[Entity]
; 


example:

entity test1 { 
	attribute 9
}

entity test2 { 
	attribute 8 
	reference test1
}

use test1.attribute
use test2.reference	 
	 
Re: Making change to DotExpression example [message #1763764 is a reply to message #1763762] Fri, 19 May 2017 07:36 Go to previous messageGo to next message
Eclipse UserFriend
but you have zero ecore::EStructuralFeatures in your model?!?

maybe you mean

tail=[ecore::EObject])
Re: Making change to DotExpression example [message #1763766 is a reply to message #1763764] Fri, 19 May 2017 07:38 Go to previous messageGo to next message
Eclipse UserFriend
or do you mean the estrucuturalfeatures of the Entity Eclass?
Re: Making change to DotExpression example [message #1763770 is a reply to message #1763766] Fri, 19 May 2017 08:43 Go to previous messageGo to next message
Eclipse UserFriend
yes to the latter! I would think that "attribute" and "reference" in the Entity eclass are of type EAttribute and EReference respectively and as such members of EStructuralFeatures.
But I dont know if it is possible to access instances this way...
Re: Making change to DotExpression example [message #1763772 is a reply to message #1763770] Fri, 19 May 2017 09:10 Go to previous messageGo to next message
Eclipse UserFriend
in scoping:

entity.eClass().getEstructuralFeatures() or something like that
Re: Making change to DotExpression example [message #1763843 is a reply to message #1763772] Mon, 22 May 2017 03:29 Go to previous messageGo to next message
Eclipse UserFriend
yes - this is also our idea for the scoping part:) But we are trying to figure out how to adjust the grammar part - especially the DotExpression rule - to our example...
Is there any way of specifying, that tail should be EStructuralFeature of current? Example below does not seem to be working...

DotExpression returns Ref:
    EntityRef ({DotExpression.ref=current}  "." tail=[ecore::EStructuralFeature])*
;
Re: Making change to DotExpression example [message #1763844 is a reply to message #1763843] Mon, 22 May 2017 03:33 Go to previous messageGo to next message
Eclipse UserFriend
no in the grammar you just specify the the type
the "of current" is part of the scoping you have to implement

=> tail=[ecore::EStructuralFeature] looks good
Re: Making change to DotExpression example [message #1763845 is a reply to message #1763844] Mon, 22 May 2017 03:43 Go to previous messageGo to next message
Eclipse UserFriend
Ok- thank you! We will give it a try :)
Re: Making change to DotExpression example [message #1764125 is a reply to message #1763845] Thu, 25 May 2017 07:16 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian :)

We are working on the modification of your DotExpression example for our project. We are almost there - only when we try to get to the values of the EReferences to traverse further down the dot expr, instead we get the variable name...we have tried a lot of different stuff but cannot seem to get it quite right...

At the moment, we get:
use myJoint.^Type = EAttribute is end of line => OK to get variable name
use myLink2.inert = EReference should return value 'instance_inert' to access attributes of this instance, not variable name 'inert'

Our target is:
use myJoint.^Type
use myLink2.instance_inert

//---------------------------------------------------------------------------------

MODEL:
Robot robo 

Link mylink1
Link myLink2 
	isReuseOf mylink1 
	Inertia instance_inert 
		ixx 6 
		ixy 88 
		ixz 00 
		iyy 1 
		iyz 22 
		izz 55 

Joint myJoint 
	ChildOf ccc 
	ParentOf pppp 
	Type Fixed


GRAMMAR:

grammar org.xtext.example.mydot1.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydot1/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Robot returns Robot:
	'Robot' name=ID
	(link+=Link | joint+=Joint)* 
	 usage+=Usage*
;

ReUseAble:
	Link | Joint | LinkDecorator
;

Usage returns Usage:
    "use" ref=DotExpression
;

DotExpression returns Ref:
    EntityRef ({DotExpression.ref=current}  "." tail=[ecore::EStructuralFeature])*       
    
;

EntityRef returns Ref:
    {EntityRef} entity=[ReUseAble]
;

Link:
	'Link' name=ID
	('isReuseOf' isReuseOf=[Link])?
	inert+=Inertia*	
	//decorator=LinkDecorator
;

LinkDecorator:
	{LinkDecorator} 
		inert+=Inertia*		
;

LinkRef:
	'add_to' ref=[Link|ID] 
	    decorator=[LinkDecorator|ID]
;

Joint:
	'Joint' name=ID
  	('isReuseOf' isReuseOf=[Joint])?
	'ChildOf' ChildOf=[Link|ID]
	'ParentOf' ParentOf=[Link|ID]
	'Type' Type=JointType
;

enum JointType returns JointType:
		fixed = 'Fixed' |revolute = 'Revolute' |  prismatic = 'Prismatic' | continuous = 'Continuous';
		
JointRef returns JointRef:
	 fix = '->' | rev = 'r->' | pris = 'p->' | cont = 'c->'  
;		

Inertia returns Inertia:
	'Inertia' (name=ID)?
	'ixx' ixx=INT 'ixy' ixy=INT 'ixz' ixz=INT 'iyy' iyy=INT 'iyz' iyz=INT 'izz' izz=INT
;


SCOPE:
class MyDslScopeProvider extends AbstractMyDslScopeProvider {
	
     override IScope getScope(EObject exp, EReference ref) {
     	if (exp instanceof DotExpression) {
        val head = exp.ref;
        switch (head) {
            EntityRef : Scopes::scopeFor(head.entity.eClass.getEStructuralFeatures())
            DotExpression : {
                val tail = head.tail
                switch (tail.getEType()) {
                //switch (tail) {	
                    EAttribute : IScope::NULLSCOPE
                    EReference : Scopes::scopeFor(tail.eClass.getEStructuralFeatures())
                    default: IScope::NULLSCOPE
                }
            }
             
            default: IScope::NULLSCOPE
        }
    } else super.getScope(exp, ref)
    
    
    }
}



Re: Making change to DotExpression example [message #1764136 is a reply to message #1764125] Thu, 25 May 2017 14:43 Go to previous message
Eclipse UserFriend
This makes no sense
Zero

Instane_inert is not a eattrubte or ereference

It is a inertia.

So I still don't understand what this is all about
I really don't

So what should the ^type
And the instance_inert point to
?????

Why point at all to attributes and references

Maybe you should provide a unit test as well to understand this

Maybe you want to reference
To a ecore::EObject

And do inside the scope whatever you want and my broken brain does not
Previous Topic:Format on Save in Editor
Next Topic:resolution of uriFragment '|0' failed.
Goto Forum:
  


Current Time: Sun Jul 13 00:40:05 EDT 2025

Powered by FUDForum. Page generated in 0.52142 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top