Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » (Fully)?QualifiedName
(Fully)?QualifiedName [message #898746] Fri, 27 July 2012 12:39 Go to next message
Quentin Boucher is currently offline Quentin BoucherFriend
Messages: 27
Registered: July 2012
Junior Member
Hello,

I am quite new to Xtext and trying to implement my language.

In this language users should be able to use partially and fully qualified names. For example, one could use foo.bar.xyz, bar.xyz or xyz to reference xyz. The user must use the name which uniquely identifies the element since elements might have the same names. For example, the user could define a second xyz in bar2. That one would have bar2.xyz as unique identifier. However, the user could also use foo.bar2.xyz to identify it. She can also use the fully qualified name even if xyz was unique. I have read a bit about "QualifiedNameValueConverter" but I don't know if this is the right way to go?

Additionally, the user can use shortcuts like "this", "parent",...

Thank you for your help!
Re: (Fully)?QualifiedName [message #898787 is a reply to message #898746] Fri, 27 July 2012 14:49 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
The QualifiedName is used to name things, and for expressing a reference
to a named item. It is the responsability of Scoping of presenting
eligible candidates for referencing existing elements, and the
responsibility of "Containers" to manage the overall visibility of
elements to scoping.

By default everything that has a "name" feature is exported and gets a
fully qualified name based on its containment. Containment comes in
different flavors - using OSGi/Java classpath, Eclipse project
depedencies, etc. (You configure how you want this to work in your
language - it is in the documentation).

Scoping has many possibilities, and documentation does not really
contain any recipes - but search this forum for pointers to blog posts
and examples on Scoping.

You also have to decide on if you want to use an import scheme (like
java) to prevent requirement on having a fully/semi qualified named
reference when there are ambiguities. I.e. if you reference using "a"
and when the code is written there is only one "a" but later there are
several "a" to chose from and none is closer to the other in scoping to
the current position. If your different "a"'s then have very long names,
you may not want to have to type "org.foo.bar.this.that.the.other.a"
whenever you want to use a specific "a". Hence, java import that
specifies an alias.

Using import naturally makes scoping simpler - every name has to be
found in the scope(s) defined in one resource. And you can resolve the
imports separately (also subject to ambiguities btw depending on which
container configuration you use).

Hope that helps.
Regards
- henrik


On 2012-27-07 14:39, Quentin Boucher wrote:
> Hello,
>
> I am quite new to Xtext and trying to implement my language.
> In this language users should be able to use partially and fully
> qualified names. For example, one could use foo.bar.xyz, bar.xyz or xyz
> to reference xyz. The user must use the name which uniquely identifies
> the element since elements might have the same names. For example, the
> user could define a second xyz in bar2. That one would have bar2.xyz as
> unique identifier. However, the user could also use foo.bar2.xyz to
> identify it. She can also use the fully qualified name even if xyz was
> unique. I have read a bit about "QualifiedNameValueConverter" but I
> don't know if this is the right way to go?
>
> Additionally, the user can use shortcuts like "this", "parent",...
>
> Thank you for your help!
Re: (Fully)?QualifiedName [message #901252 is a reply to message #898787] Fri, 10 August 2012 13:45 Go to previous messageGo to next message
Quentin Boucher is currently offline Quentin BoucherFriend
Messages: 27
Registered: July 2012
Junior Member
Thank you for your answer.

I have tried to solve my problems with your advices but, in one week of work, but no progress... I have tried the Mainte's DSL blog tutorial about path expressions and adapted it to Xtext2.
My first problem: allow partial/fully qualified named in the grammar. The editor does not support the path A.D even if D is a child of A. Reason: Could not resolve reference to D. I implemented the advices provided in a lot of posts: use FQN. But then, D will always have to be referenced as A.D. Consequently I won't be able to reference it as root.A.D, parent.d,... or simply D.

Any tip to get me out of there?

Thanks!

Quentin
Re: (Fully)?QualifiedName [message #901264 is a reply to message #901252] Fri, 10 August 2012 14:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13425
Registered: July 2009
Senior Member
Can you post an example grammar? Please simplyfy it as much as
possible. An try to solve your problems step by step (leave out the
root and parent stuff)

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: (Fully)?QualifiedName [message #901510 is a reply to message #898746] Mon, 13 August 2012 08:15 Go to previous messageGo to next message
Quentin Boucher is currently offline Quentin BoucherFriend
Messages: 27
Registered: July 2012
Junior Member
Here is a (very) simplified version of the elements of the grammar impacted by the Long_ID reference. I hope it is understandable like this!?

Long_ID: 
        (short='root' | short='this' | short='parent' | feature=[Hierarchical_Feature]) tail=(Long_IDTail)?;

Long_IDTail: 
	    '.' ((head=[Hierarchical_Feature] (tail=Long_IDTail)?)|attribute=[Attribute]);

Hierarchical_Feature:
	    optional?=('opt')? name=ID (body+=Feature_Content)?
	  | shared?='shared' ref=[Hierarchical_Feature];

Expression:
	...
	| ref=Long_ID;



Thank you for your help!
Re: (Fully)?QualifiedName [message #901513 is a reply to message #901510] Mon, 13 August 2012 08:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13425
Registered: July 2009
Senior Member
Hi this is still too complex for a start and not a complete grammar.
Try to solve one problem after another (maybe with another grammar)-
I cannot do this for you (way to much effort)
I'd first try to get simple imports running and then adding the
implicit imports for this and parent and root. Maybe doing the
scoping completely manual (instead of using explicit /implicit
imports via importednamespaceawarelocalscopeprovider is an option
too.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: (Fully)?QualifiedName [message #901572 is a reply to message #898746] Mon, 13 August 2012 13:22 Go to previous messageGo to next message
Quentin Boucher is currently offline Quentin BoucherFriend
Messages: 27
Registered: July 2012
Junior Member
Here is the simplified grammar:

Model: model+=ModelElement+;
	
ModelElement:
	feature=Feature
	| reference=Reference;
	
FQN: ID ('.' ID)*;

Long_ID: head=[Hierarchical_Feature] (tail=Long_IDTail)?;
	
Long_IDTail: '.' head=[Hierarchical_Feature] (tail=Long_IDTail)?;

Feature:
	name=ID '{' body=Feature_Group '}';	

Feature_Group:
	'group' '{' sub_features+=Hierarchical_Feature (',' sub_features+=Hierarchical_Feature)* '}';
	
Hierarchical_Feature:
	     name=ID (group=Feature_Group)?;

	
Reference:
	ref=Long_ID;


And the ScopeProvider:

public IScope scope_Long_IDTail_head(Long_IDTail context, EReference ref) {
		EObject parent= context.eContainer();
		if (parent instanceof Long_ID) {
			if (((Long_ID)parent).getHead().getGroup()!=null) {
				return Scopes.scopeFor(((Long_ID)parent).getHead().getGroup().getSub_features());
			}
			else return  IScope.NULLSCOPE;
		}
		else {			
			if (((Long_IDTail)parent).getHead().getGroup()!=null) {
				return Scopes.scopeFor(((Long_IDTail)parent).getHead().getGroup().getSub_features());
			}
			else return  IScope.NULLSCOPE;
		}
	}


This solution works. However, as you can see the code of the scope provider is duplicated since the Long_ID is divided in two parts: Long_ID and Long_IDTail (inspired by the tutorial mentioned in a previous post). I tried to modify the grammar as well as the scope provider but did not manage to reach my goal. Any tip to help me?

Another question: how can I prevent the auto-completion of the "." if the scope provider returns a NULLSCOPE?
Re: (Fully)?QualifiedName [message #901577 is a reply to message #901572] Mon, 13 August 2012 13:44 Go to previous messageGo to next message
Quentin Boucher is currently offline Quentin BoucherFriend
Messages: 27
Registered: July 2012
Junior Member
Forget about my first question: for more complex Long_IDs I will add in the future, splitting the Long_ID is required. I will thus have to duplicate code... Unless you have a better idea?

Thanks!
Re: (Fully)?QualifiedName [message #901583 is a reply to message #901572] Mon, 13 August 2012 14:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13425
Registered: July 2009
Senior Member
What about introducing an
Abstract_long_id: long_Id | Long_IDTail;

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 13 August 2012 17:47]

Report message to a moderator

Re: (Fully)?QualifiedName [message #901766 is a reply to message #901583] Tue, 14 August 2012 13:44 Go to previous messageGo to next message
Quentin Boucher is currently offline Quentin BoucherFriend
Messages: 27
Registered: July 2012
Junior Member
Thanks for the tip, it works!

Next step: adding an element to the Long_ID head. I try to solve this problem since this morning but I am still stuck due to a conflict. Here is my current grammar

´╗┐Model: model+=ModelElement+;
	
ModelElement:
	feature=Feature
	| reference=Reference;

Long_ID_Abstract:
	  Long_ID
	| Long_IDTail;

Long_ID: head=([Feature]|[Hierarchical_Feature]) ('.' tail=Long_IDTail)?;
	
Long_IDTail: '.' head=[Hierarchical_Feature] (tail=Long_IDTail)?;

Feature:
	'root' name=ID '{' body=Feature_Group '}';	

Feature_Group:
	'group' '{' sub_features+=Hierarchical_Feature (',' sub_features+=Hierarchical_Feature)* '}';
	
Hierarchical_Feature:
	     name=ID (body=Feature_Group)?;

	
Reference:
	ref=Long_ID ';';


I guess the conflict comes from the Feature vs Hierarchical_Feature choice. I have tried several solutions but none of them compiles. The easiest one would be to group both rules but it is not feasible since a "Feature" can only be present at the first place. And in the next steps, we will have the same problem with attributes (to be added) which will end Long_IDs.

Thank you very much for your help!
Re: (Fully)?QualifiedName [message #901830 is a reply to message #901766] Tue, 14 August 2012 17:35 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13425
Registered: July 2009
Senior Member
Hi,

you have to introduce a common supertype

AbstractFeature: Feature | Hierarchical_Feature;	

Long_ID: head=[AbstractFeature] ('.' tail=Long_IDTail)?;


~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Import all Files from given Folder
Next Topic:Synchronized model instance and text editor(s)
Goto Forum:
  


Current Time: Mon Apr 06 20:25:58 GMT 2020

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

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

Back to the top