Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » scope problem
scope problem [message #558562] Mon, 13 September 2010 13:59 Go to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
sorry for the next questions! Embarrassed

My grammar rules are these:

Model:
i=Import*
classes+=(
EClassO
)*
|
("Library" "{"
functions+=functionDecl*
"}")
;
EClassO:
(aEClass|
DS='like' eClass=[ecore::EClass]
);

aEClass: "a" a=_EClass;
_EClass returns ecore::EClass:"EClass" name=ID;

functionDecl: "def" "Operation" name=ID
('(' ((params+=EClassParameter (',' params+=EClassParameter)*)? ')') )? "{"
...
"}"
;

EClassParameter returns ecore::EClass: "EClass" name=ID ;
=======================================
i don't know what happens but if i declare in model some functionDecl with some parameters like :

def operation o1(EClass c1){}
in other file with .dsl extension...(i tried to modify grammar to have in the same but the error is the same...)

and when i type in model ctrl+space i receive only _EClass instances declarated in model and not existing one in workspace ecore models...

if i delete the parameters in functionDecl i receive in suggestions the union of _Eclass and ecore::Eclass instances...correctly...
have you any ideas?


Re: scope problem [message #558580 is a reply to message #558562] Mon, 13 September 2010 14:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

there is something stange with the braces in your funtion rule.
changing it to

functionDecl: "def" "Operation" name=ID
('(' (params+=EClassParameter (',' params+=EClassParameter)*)? ')' )? "{"

"}"
;


makes it working.

But why to you want to define an EClass inline for a parameter?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #558583 is a reply to message #558580] Mon, 13 September 2010 15:16 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
the problem is still there...

i know the problem there is when EClassParameter returns ecore::EClass... if i delete the "returns" statement...the suggestions are ok...but my goal is to define a functionDeclaration with eclass parameters...this list should contain the eclass of external ecore model and the _EClass that i defined in my model...

i don't know if i was clear... Embarrassed

[Updated on: Mon, 13 September 2010 15:29]

Report message to a moderator

Re: scope problem [message #558589 is a reply to message #558583] Mon, 13 September 2010 15:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hey,

i still don't know if you want to instantiate or to reference an EClass Test when writing

def operation o1(EClass Test){}


using this grammar:

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

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

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

Model:{Model}
classes+=(
EClassO
)*
|
("Library" "{"
functions+=functionDecl*
"}")
;
EClassO:
(aEClass|
DS='like' eClass=[ecore::EClass]
);

aEClass: "a" a=_EClass;
_EClass returns ecore::EClass:"EClass" name=ID;

functionDecl: "def" "Operation" name=ID
('(' (params+=EClassParameter (',' params+=EClassParameter)*)? ')' )? "{"

"}"
;

EClassParameter returns ecore::EClass: "EClass" name=ID ;


and these models

Library {
	def Operation xxx (EClass A){
	}
}


like A


i get the completion i want at the second model

~Christian

P.S: of course i had to use a custom QualifiedNameProvider

public class MyDslQNP extends DefaultDeclarativeQualifiedNameProvider {
	
	public String qualifiedName(EClass c) {
		return c.getName();
	}

}


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

[Updated on: Mon, 13 September 2010 15:35]

Report message to a moderator

Re: scope problem [message #558725 is a reply to message #558589] Tue, 14 September 2010 08:46 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
i tried to copy your sample grammar without QualifiedNameProvider and when i add some parameter in function declaration like def Operation xxx (EClass A)... coming back to my my model...i type :
like (ctr+space) and i don't receive the eclass in ecore model but only new added class in model... if i define a function without parameters the completion it's ok...

this depends on QualifiedNameProvider?
Re: scope problem [message #558737 is a reply to message #558725] Tue, 14 September 2010 09:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

seems so that it works only with the name provider.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #558746 is a reply to message #558737] Tue, 14 September 2010 09:53 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
i defined MyDslQNP class in my package... and i have to link this with other declaration of the ide?
Re: scope problem [message #558752 is a reply to message #558746] Tue, 14 September 2010 10:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

as always: bind it in the runtime module.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #558753 is a reply to message #558562] Tue, 14 September 2010 10:22 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
ok...i linked it in runtime module and it works...but only a suggestions from you... Very Happy
now i receive in suggestions all eclasses ...and also the "parameters..." in eclass function declarations... do you mean i can fix this problem of my grammar? i think you understood what i wanna do Very Happy
Re: scope problem [message #558754 is a reply to message #558753] Tue, 14 September 2010 10:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

as i said before. i do not understand what you want to do.

Quote:

i still don't know if you want to instantiate or to reference an EClass Test when writing def operation o1(EClass Test){}



can you please post sample models and explanations.

~Christian


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

[Updated on: Tue, 14 September 2010 10:34]

Report message to a moderator

Re: scope problem [message #558756 is a reply to message #558754] Tue, 14 September 2010 10:42 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
yes...

For example i want to give the possibility to define functions(operation) on EClass ...i means....

I declare some MyEclass a
MyEclass b
etc
...in addiction i have some ecore models in workspace...(and i don't know why i get the completion without referencing with an import...)

in addition to define...

function XXX(Eclass c){

c.name="some prefix"+c.name;

}

this is my goal to define in grammar...
i know that in this way i declare an instance of eclass in parameter of functionDeclaration...but in the scope of this i wanna manipulate attribute of eclass ...


the final step is to give the model to a parser and so on...
Re: scope problem [message #558757 is a reply to message #558756] Tue, 14 September 2010 10:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you still did not say where your problem is! is it about the scope of c.name
both should be easly be solvable with the means of scoping you know.

~Christian


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

[Updated on: Tue, 14 September 2010 10:57]

Report message to a moderator

Re: scope problem [message #558760 is a reply to message #558757] Tue, 14 September 2010 11:12 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
the problem now is almost solved...adding your suggestions... but now i have a grammar problem... because the parameter declared as Eclass i don't want to seems to be showed in suggestions...

sorry for my eng Smile
Re: scope problem [message #558763 is a reply to message #558760] Tue, 14 September 2010 11:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

because the parameter declared as Eclass i don't want to seems to be showed in suggestions...


in the suggestions at which place?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #558769 is a reply to message #558763] Tue, 14 September 2010 11:37 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
when i declare classes....

classes+=Eclass* for example...

and in my model i have some crossreferences to Eclass....

[Updated on: Tue, 14 September 2010 11:37]

Report message to a moderator

Re: scope problem [message #558776 is a reply to message #558769] Tue, 14 September 2010 11:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
So in this places you do not want to have the parameter eclasses - so write scoping for the other places and filter out the stuff you do not want to have

public class FilteringScope implements IScope {

	private IScope delegate;
	private Predicate<IEObjectDescription> filter;

	public FilteringScope(IScope delegate, Predicate<IEObjectDescription> filter) {
		this.delegate = delegate;
		this.filter = filter;
	}

	public IScope getOuterScope() {
		return new FilteringScope(delegate.getOuterScope(), filter);
	}

	public Iterable<IEObjectDescription> getContents() {
		return filter(delegate.getContents());
	}

	public Iterable<IEObjectDescription> getAllContents() {
		return filter(delegate.getAllContents());
	}

	public IEObjectDescription getContentByName(String name) {
		return filter(delegate.getContentByName(name));
	}

	public IEObjectDescription getContentByEObject(EObject object) {
		return filter(delegate.getContentByEObject(object));
	}
	
	public Iterable<IEObjectDescription> getAllContentsByEObject(EObject object) {
		return filter(delegate.getAllContentsByEObject(object));
	}

	protected Iterable<IEObjectDescription> filter(
			Iterable<IEObjectDescription> unfiltered) {
		return Iterables.filter(unfiltered, filter);
	}

	protected IEObjectDescription filter(IEObjectDescription contentByEObject) {
		if (!filter.apply(contentByEObject))
			return null;
		return contentByEObject;
	}


	public IScope scope_Ref_theEClass(Ref ref, EReference eReference) {
		IScope delegateScope = delegateGetScope(ref,eReference);
		return new FilteringScope(delegateScope, new Predicate<IEObjectDescription>() {
			@Override
			public boolean apply(IEObjectDescription input) {
				if (...) {
					return false;
				}
				return true;
			}
		});
	}


the best would be to get all information you need out of the IEObjectDescription - you may have to adopt the creation of the IEObjectDescriptions too.

see here http://www.eclipse.org/forums/index.php?t=rview&goto=515 624&th=162954
and here http://www.eclipse.org/forums/index.php?t=msg&goto=55572 9
too

~Christian


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

[Updated on: Tue, 14 September 2010 11:59]

Report message to a moderator

Re: scope problem [message #558990 is a reply to message #558776] Wed, 15 September 2010 09:09 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
ok...i try...
dear christian have you a skype contact ? it would be a plasure talk with u.... Very Happy
Re: scope problem [message #558992 is a reply to message #558990] Wed, 15 September 2010 09:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi chuck,

i won't give support via skype cause this goes beyond what i want to give as free support here in the community.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #559082 is a reply to message #558992] Wed, 15 September 2010 14:38 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
ok!

i try to explain my last problem...

in my textual model i would to choice ecore metalements...

i mean ... defining :

myEattribute returns ecore::EAttribute: "attr" name=ID "type=" eType=??

i would obtain in model this:

attr a1 type=ecore::EAttribute

i don't know if is possible to be related to ecore elements ...

sorry for the questions...i'm a begginer Smile


Re: scope problem [message #559101 is a reply to message #559082] Wed, 15 September 2010 15:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

once more: when using ecore you have to gain knowledge on it.
so an EAttribute is of ecore::EDataType

but you have to add ecore.ecore to the (class)path of the project you model within.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #559107 is a reply to message #559101] Wed, 15 September 2010 15:47 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
yes i know it... i insert the crossreference to Edatatype and i receive only EString and EInteger... i know that adding the ecore file in workspace of eclipse application (UI ) i can use the ecore metamodel...there is another way to provide ecore elements without adding phisically the ecore file?
Re: scope problem [message #559127 is a reply to message #559107] Wed, 15 September 2010 16:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

everything is possible - so this would be once more a place for using scoping.

quick and (maybe) dirty:
	public IScope scope_ETypedElement_eType(EAttribute a, EReference r) {
		return Scopes.scopeFor(Iterables.filter(EcorePackage.eINSTANCE.getEClassifiers(),EDataType.class));
	}


~Christian


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

[Updated on: Wed, 15 September 2010 16:55]

Report message to a moderator

Re: scope problem [message #559330 is a reply to message #559127] Thu, 16 September 2010 12:05 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
good morning Christian...
i found this example and it's perfect for me...
http://zarnekow.blogspot.com/2009/01/xtext-corner-2-linking- and-scoping.html
have you a code sample for function declaration and scoping?
your solution at my preceding problem it's ok...but now i have to set the scope for the order of parameter...

i mean:

if i declare fun(int x, String y){
...
}

the call must be adapt to the declaration and parameters correspond to types...

call:

fun(3,"hello");

Re: scope problem [message #559334 is a reply to message #559330] Thu, 16 September 2010 12:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

first this is not trivial and you won't find a solution you can copy and paste
and might be very complex when your types support Inheritance or "Generics".

so this is something that goes into the direction of type-systems.
have a look at
http://voelterblog.blogspot.com/2010/08/xtext-typesystem-fra mework.html
http://code.google.com/a/eclipselabs.org/p/xtext-typesystem/

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #559406 is a reply to message #559334] Thu, 16 September 2010 14:39 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
ok Christian...you're very kind!
i installed the plugin and i'm studying the framework...have you any snippets of grammr to use parameters in a function like this?

declaration:
void foo(int x, myType c, ...){
...
}

call:
var myType h;
foo(1,h);
============
the problem i have is that declaring the same name of parameter in two different declaration receive an error...because a parameter use ID in grammar....i don't know how to define parameter in grammar ....


Re: scope problem [message #559440 is a reply to message #559406] Thu, 16 September 2010 15:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

no i have not - to solve the name problem use a custom qualified name provider.

~Christian


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

[Updated on: Thu, 16 September 2010 18:40]

Report message to a moderator

Re: scope problem [message #559956 is a reply to message #558562] Mon, 20 September 2010 14:26 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
hi ....

in my grammar i have:

CC:.... ('(' list+=[ecore::EClass]| ((',' list+=[ecore::EClass])* ')'));

and in scope definition:

public IScope scope_CC_list(CC a, EReference ref) ...

and it's ok...
but when i changed my grammar in :


CC:.... ('(' list+=A| ((',' list+=A)* ')'));

A: type=[ecore::EClass];

i dont' know how to change the scope definition ....

other question....

in the scope definition i would retrieve the position of the A element that i typing in "list"...
if i define the scope for element A I have the method call when i already choice the element...and i don't want that...

thx in advance for the help... yopu are an amazing support team. Smile
Re: scope problem [message #559962 is a reply to message #559956] Mon, 20 September 2010 14:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

A: type=[ecore::EClass];

here the problem might be that the A is not yet instantiated when the scoping is called - just debug the methodes in the scoping base class to get a hint what happens and how to write (the signature) of the scope_ method.


in the scope definition i would retrieve the position of the A element that i typing in "list"...
if i define the scope for element A I have the method call when i already choice the element...and i don't want that...

i do not understand this - sorry - as i said before a concrete model example and a descripion of what happens when you are doing what would be helpful.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #559965 is a reply to message #559962] Mon, 20 September 2010 14:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Update:

in the scope definition i would retrieve the position of the A element that i typing in "list"...
if i define the scope for element A I have the method call when i already choice the element...and i don't want that...

do you mean that the scoping method is called when you use autocompletion at the place you define the scoping?

this is wanted behaviour - scoping defines the possible allowed values for a referece. maybe the thing you need is validation and not scoping.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #559967 is a reply to message #559962] Mon, 20 September 2010 14:53 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
for the second question the grammar is :

CC: ref=[Operation] ('(' list+=A| ((',' list+=A)* ')'));

A: type=[ecore::EClass];

the scope i defined is:

public IScope scope_CC_list(CC a, EReference ref) {
System.out.println("testing");
return ...
=====================
//here i would to retrieve the position of the element wich I get the completion....i mean ...in the model i wrote:

operation ( first, second, (ctrl+space) ...., n)

i would get the int position in the list when i type ctrl+space...in this case 2...


================

}


i hope to be more clear...
thx

Re: scope problem [message #559974 is a reply to message #559967] Mon, 20 September 2010 15:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

as i mentioned before this won't be possible since Xtext instantiates the A lately - so you may have to change your grammar to solve this - or use something else than scoping for it.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #559976 is a reply to message #559974] Mon, 20 September 2010 15:17 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
how i can change my grammar Christian... i have no idea in this case...

in few words i'm trying to reproduce the completion of the code tools... like in java editor....

declaring some integer and string...when i define a function:

public hello( string a, int b){...}

the tool when i start to typing function arguments suggests me instances with right type...

hello(...,...);

what you think about?
Re: scope problem [message #559979 is a reply to message #559976] Mon, 20 September 2010 15:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Maybe i was not exact enhough in my answer

with a grammar like
CC: xxx=ID ('(' list+=A (',' list+=A)* ')');

A: {A} type=[ecore::EClass];


and scoping like
	public IScope scope_A_type(CC c, EReference r) {
		System.out.println(-1);
		return delegateGetScope(c, r);
	}
	
	public IScope scope_A_type(A a, EReference r) {
		System.out.println(((CC)a.eContainer()).getList().indexOf(a));
		return delegateGetScope(a, r);
	}


you will get it running but i cannot say how stable this will work.

~Christian



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #559985 is a reply to message #559979] Mon, 20 September 2010 15:52 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
unfortunately the delegate on attribute is called only when i already chosen the element... Sad
Re: scope problem [message #559987 is a reply to message #559985] Mon, 20 September 2010 15:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i cannot reproduce this?! i get a nice -1 at the first call.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: scope problem [message #559988 is a reply to message #559987] Mon, 20 September 2010 16:02 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
yes...the -1 is printed...but this not execute the delegation to the aìother scope...i mean...the position of A element with the second print is not showed until i choice an A element....

[Updated on: Mon, 20 September 2010 16:03]

Report message to a moderator

Re: scope problem [message #559990 is a reply to message #559988] Mon, 20 September 2010 16:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
right - but that is not the problem - as i said before this has to do with how xtext instatiates objects - so you may have to ask for the index (second case) or ask the list for its actual size.

Maybe you can find out a way to figure it out - this is all advice i can give you.

~Christian


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

[Updated on: Mon, 20 September 2010 16:07]

Report message to a moderator

Re: scope problem [message #560029 is a reply to message #559990] Mon, 20 September 2010 19:48 Go to previous message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
yes i understand... i would change my grammar for this...have you some suggestions? i tell you what i'm doing....with functions declarations...
Previous Topic:project wizard and launch configuration
Next Topic:C# Grammar & Parser
Goto Forum:
  


Current Time: Thu Apr 25 04:21:38 GMT 2024

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

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

Back to the top