Package declaration [message #894588] |
Mon, 09 July 2012 13:51  |
Eclipse User |
|
|
|
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 13:56] by Moderator
|
|
|
|
Re: Package declaration [message #894712 is a reply to message #894591] |
Tue, 10 July 2012 04:59   |
Eclipse User |
|
|
|
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 05:35] by Moderator
|
|
|
|
|
|
Re: Package declaration [message #894835 is a reply to message #894828] |
Tue, 10 July 2012 13:12  |
Eclipse User |
|
|
|
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 !
|
|
|
Powered by
FUDForum. Page generated in 0.49121 seconds