Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Package declaration
Package declaration [message #894588] Mon, 09 July 2012 17:51 Go to next message
Stéphane Seyvoz is currently offline Stéphane SeyvozFriend
Messages: 5
Registered: July 2012
Junior Member
Hi all,

I have a problem using XText, and didn't find a solution yet, so I decided to ask my question here.
I'm trying to implement support for a language where we do not have explicit package declaration, or, well, in a "non-commonly-Java-like-syntax"-way.

Usually you would meet (as in the Xtext examples) the following syntax:

package org.orgname.product;
import org.other.*;
something DeclarationName {
// elements...
}

In the language I'm working with, the current package declaration is different, we currently do :

import org.other.*;
something org.orgname.product.DeclarationName {
// elements...
}

The problem is that in the { } scope, Xtext expects elements to be org.orgname.product.DeclarationName.* elements, and not org.orgname.product.*, which our own tools expect.

The org.orgname.product.DeclarationName is matched as a standard QualifiedName in the grammar.

To summarize : how can I "implicitly declare" a namespace using the package prefix from my QualifiedName ? (And still have the freshly declared "something ....DeclarationName" available for references from other files)

How can I implement a way for Xtext to consider the right scope for all the inner elements, so it still does the same good old auto-completion and quickfixes for cross-references ?
Meaning, if I use an element from the same package, no import would be added, and if the element is in another package, its selection would add the import the standard way ? (it works with more classical "package" declaration : I tried... I just need to do it "our way").

I've tried to familiarize with DeclarativeScopeProvider and ImportedNamespaceAwareLocalScopeProvider, but didn't really find how to do it.

Thank you, sorry for the messy description, and the Xtext framework is really awesome by the way !

[Updated on: Mon, 09 July 2012 17:56]

Report message to a moderator

Re: Package declaration [message #894591 is a reply to message #894588] Mon, 09 July 2012 18:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13352
Registered: July 2009
Senior Member
Hi,

a complete reproducable example would have helped to give it a try
never the less
overrriding
org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getQualifiedNameOfLocalElement(EObject)
shoud be worth a try

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


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Package declaration [message #894712 is a reply to message #894591] Tue, 10 July 2012 08:59 Go to previous messageGo to next message
Stéphane Seyvoz is currently offline Stéphane SeyvozFriend
Messages: 5
Registered: July 2012
Junior Member
Thanks for your quick answer, you will find our grammar file attached to this message.
It's a bit complex, which is why I didn't post it at first.

In the grammar, I commented all that concerned the "PackageDeclaration" rule, as we do not want this behavior at the moment.
I personnally prefer using the "package" keyword in a Java-like way but don't have much choice at the moment, due to the other tools development and other members acceptance.

Our "implicit" package definition should be done using CompositeDefinition, PrimitiveDefinition, and TypeDefinition names (QualifiedName).
I want to fix the scope of our "elements" referred by these rules, actually considered as prefixed by the full QualifiedName of those rules (we only want the scope to consider the same package as the parent element).

Please note before using this grammar that it relies on another grammar in the ProvidedInterfaceDefinition and RequiredInterfaceDefinition rules. You can comment all references to those elements as they are not really important for our problem.

Thanks again, I will investigate your proposition and come back to you if I can (or can't !) make it work.

[Updated on: Tue, 10 July 2012 09:35]

Report message to a moderator

Re: Package declaration [message #894716 is a reply to message #894712] Tue, 10 July 2012 09:03 Go to previous messageGo to next message
Stéphane Seyvoz is currently offline Stéphane SeyvozFriend
Messages: 5
Registered: July 2012
Junior Member
You can find a sample Eclipse project attached to this message.
  • Attachment: Example.zip
    (Size: 2.94KB, Downloaded 115 times)

[Updated on: Tue, 10 July 2012 09:22]

Report message to a moderator

Re: Package declaration [message #894729 is a reply to message #894716] Tue, 10 July 2012 09:41 Go to previous messageGo to next message
Stéphane Seyvoz is currently offline Stéphane SeyvozFriend
Messages: 5
Registered: July 2012
Junior Member
Oops small correction to apply to the grammar, I just found that the

QualifiedNameWithWildcard:
QualifiedName '.*'? ;

rule was missing the '.' at the end.
This wasn't related to my problem since I've had it before removing the dot, but the dot removal was was the result of following experiments. Please consider it to be there anyway.

[Updated on: Tue, 10 July 2012 09:43]

Report message to a moderator

Re: Package declaration [message #894828 is a reply to message #894712] Tue, 10 July 2012 16:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13352
Registered: July 2009
Senior Member
Hi,

in this case you would do a fake import for the parent

public class MyDslImportedNamespaceAwareLocalScopeProvider extends
		ImportedNamespaceAwareLocalScopeProvider {
	
	@Inject IQualifiedNameConverter qualifiedNameConverter;
	

	
	@Override
	protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(
			EObject context, boolean ignoreCase) {
		// TODO Auto-generated method stub
		List<ImportNormalizer> result = new ArrayList<ImportNormalizer>();
		result.addAll(super.internalGetImportedNamespaceResolvers(context, 
ignoreCase));
		if (context instanceof CompositeDefinition) {
		 
result.add(createImportedNamespaceResolver(qualifiedNameConverter.toString(getQualifiedNameProvider().getFullyQualifiedName(context).skipLast(1)) 
+ ".*", ignoreCase));
		}
		return result;
		
	}

}


~Christian


--
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: Package declaration [message #894835 is a reply to message #894828] Tue, 10 July 2012 17:12 Go to previous message
Stéphane Seyvoz is currently offline Stéphane SeyvozFriend
Messages: 5
Registered: July 2012
Junior Member
I had been messing with a custom ImportedNamespaceAwareLocalScopeProvider for some time, but had not thought of that.

A very neat solution to my problem, thank you !
Previous Topic:Using xpand with xtext
Next Topic:referencing java methods
Goto Forum:
  


Current Time: Sun Feb 16 20:05:19 GMT 2020

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

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

Back to the top