Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » scope problem
scope problem [message #634617] Fri, 22 October 2010 12:57 Go to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
my grammar:

Class returns ecore::EClass:newClass|exClass|CP;

exClass :'eclass" name=ID ":" (exref=[ecore::EClass]);

CP :"class" name=ID;

Fun:
"def" name=ID
('(' (params+=(CP))? (',' params+=(CP))* ')') "{"
....
"}"
;

...in my model when i define a Fun and i declare a class in params,if i define an exclass , exref scope doesn't contains references to eclasses in ecore model... if i delete the Fun definition works... i defined a QNF but i have the same problem...
Re: scope problem [message #634663 is a reply to message #634617] Fri, 22 October 2010 16:05 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Where would the Ecore model have to come from?

Re: scope problem [message #634665 is a reply to message #634663] Fri, 22 October 2010 16:11 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
if i put an ecore model in the workspace i can refer to metaelements... i'm right?
Re: scope problem [message #634680 is a reply to message #634665] Fri, 22 October 2010 17:42 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Not automagically...

You'll have to refer somehow to the existing Ecore model. Also, the moment you do that the elements of that Ecore model are "mere model elements", not meta elements. And most important of all: using scoping you'll have to make those imported Ecore model elements available as suitable targets of the cross-reference.


Re: scope problem [message #634684 is a reply to message #634680] Fri, 22 October 2010 17:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hello chuck,

using a grammar like this

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

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	classes+=Class*
	funs+=Fun*
	;
	
Class returns ecore::EClass: exClass|CP;

exClass :"eclass" name=ID ":" (exref=[ecore::EClass]);

CP :"class" name=ID;

Fun:
"def" name=ID
('(' (params+=(CP))? (',' params+=(CP))* ')') "{"

"}"
;



and a IQNP like this

public String qualifiedName(CP cp) {
		return cp.getName();
	}


works for me with the sample model

class a
eclass Name : X
eclass Name2 : Z 
class b

def fun (class X){
	
}


Z comes from the external .ecore file

@Meinte: Xtext automatically adds all EClasses to the global scope using the plugins org.eclipse.xtext.ecore, org.eclipse.xtext.ui.ecore

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 22 October 2010 18:06]

Report message to a moderator

Re: scope problem [message #634718 is a reply to message #634684] Fri, 22 October 2010 20:13 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Christian Dietrich wrote on Fri, 22 October 2010 19:58
@Meinte: Xtext automatically adds all EClasses to the global scope using the plugins org.eclipse.xtext.ecore, org.eclipse.xtext.ui.ecore


OK, good to know! Smile One learns something new everyday here Wink


Re: scope problem [message #739349 is a reply to message #634718] Mon, 17 October 2011 11:25 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
Ok... I'm using the last indigo distribution and I have problems with scoping and ecore...using the last grammar i read in this post ,.. it seems to have problems... if i put some core models in my workspace ...for example families.ecore... the complition is not working...and if I write "Family" error fix suggests to me to change to "Families.Family"... but I overrided the FQN... Sad
Re: scope problem [message #739353 is a reply to message #739349] Mon, 17 October 2011 11:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

once more: we need more information to help:
which is the grammar you use?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 17 October 2011 11:32]

Report message to a moderator

Re: scope problem [message #739364 is a reply to message #739353] Mon, 17 October 2011 11:49 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
Christian..."using the last grammar i read in this post"(as you can read in my post ...
Re: scope problem [message #739367 is a reply to message #739364] Mon, 17 October 2011 11:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

if in Xtext the damn name of class if packagename.classname you of course have to change the grammar to exref=[ecore::EClass|FQN]. i thought by telling "... but I overrided the FQN... you would already have dones this or fixed it in the scopeprovider. changing your dsls QualifiedNameProvider does not help at all.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #739374 is a reply to message #739367] Mon, 17 October 2011 12:01 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
thx for the reply... I tried to override it reading the fix suggestion... but Also deleting the QN definition I receive this error... I simply need to refere to eclasses in my scope...
Re: scope problem [message #739379 is a reply to message #739374] Mon, 17 October 2011 12:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
without an error description i cannot help,
you have to (1) change the grammar to use a FQN
or (2) use local scoping to alias the FQNed stuff to their simple names


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #749602 is a reply to message #739379] Tue, 25 October 2011 10:17 Go to previous message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
Hi Christian... I found a very simple example of my problem...maybe a workaround could solve it...

grammar:
Model:'package' Class=[ecore::EPackage]"{"
feature+=MyFeature*
"}"
;

MyFeature returns ecore::EStructuralFeature:{MyFeature} feature=[ecore::EStructuralFeature];

scope:

public IScope scope_MyFeature_feature(MyFeature f, EReference r) {
List union=new ArrayList();
EPackage p=EcorePackage.eINSTANCE;
EClass c= (EClass) p.getEClassifier("EPackage");
for (EStructuralFeature feature : c.getEAllAttributes()) {

union.add(feature);
}

for (EClass supertype : c.getESuperTypes()) {
for (EStructuralFeature feature : supertype.getEAllAttributes()) {
union.add(feature);
}
}

return Scopes.scopeFor(union);
}

model:

package p1{
ctrl+space //i don't receive code completion...
}

if i change the rule:
MyFeature returns ecore::EStructuralFeature:{MyFeature} 'feature' feature=[ecore::EStructuralFeature]; //added a simple string


i receive code completion...

so... i hope to be clear Smile

(solved the other problem)

[Updated on: Thu, 27 October 2011 08:23]

Report message to a moderator

Previous Topic: working directory
Next Topic:Error first example of MWE2
Goto Forum:
  


Current Time: Thu Apr 25 12:21:58 GMT 2024

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

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

Back to the top