Package declaration [message #894588] |
Mon, 09 July 2012 17:51 |
Stéphane Seyvoz 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 #894712 is a reply to message #894591] |
Tue, 10 July 2012 08:59 |
Stéphane Seyvoz 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 #894729 is a reply to message #894716] |
Tue, 10 July 2012 09:41 |
Stéphane Seyvoz 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 |
|
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
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
Powered by
FUDForum. Page generated in 0.04407 seconds