importedNamespace w/o WildChar ? [message #871702] |
Mon, 14 May 2012 17:47 |
Cash Ko Messages: 21 Registered: May 2012 |
Junior Member |
|
|
I need some quick support (i am relatively new to the ANTLR/Xtext)
First my example:
...
SCHEMA a;
TYPE typeA AS LIST OF INTEGER;
...
END_SCHEMA;
...
SCHEMA b;
REFERENCE FROM a; // <---- can't use a WildChar here
FIELD c1 : typeA = []; //<--- here i would use simple names from schema "a".
...
END_SCHEMA;
...
Is there a possibility to define "importedNamespace=..." without using of WildCard in REFERENCE FROM (which means using of .* implicitly)?
I need a quick solution like this:
...
Schema: "SCHEMA" name=ID Reference* Type* Field* ... "END_SCHEMA";
...
Reference: "REFERENCE" "FROM" importedNamespace=[Schema];
...
Thank you!
[Updated on: Tue, 15 May 2012 07:36] Report message to a moderator
|
|
|
Re: importedNamespace w/o WildChar ? [message #871757 is a reply to message #871702] |
Mon, 14 May 2012 19:53 |
|
Hi,
id customize org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.internalGetImportedNamespaceResolvers(EObject, boolean) or org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.createImportedNamespaceResolver(String, boolean) if you want to change the bevaiour in general
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: importedNamespace w/o WildChar ? [message #888741 is a reply to message #871757] |
Mon, 18 June 2012 15:13 |
Cash Ko Messages: 21 Registered: May 2012 |
Junior Member |
|
|
Hi Christian,
i now try to extend my grammar with support for custom namespace import.
Here is my (very simplyfied) grammar:
Model: schemas+=DeclaredSchema*;
DeclaredSchema: 'SCHEMA' name=ID '{' refs+=Reference* '}';
Reference: 'REFERENCE' 'FROM' schemaRef=DeclaredSchemaRef ';';
DeclaredSchemaRef: ref=[DeclaredSchema];
Customzing of "getLocalElementsScope" (to get imported name spaces working)
public class MyDslINALSP extends ImportedNamespaceAwareLocalScopeProvider {
protected IScope getLocalElementsScope(IScope parent, final EObject context, final EReference reference) {
IScope result = super.getLocalElementsScope(parent, context, reference);
if (context instanceof DeclaredSchema) {
final List<ImportNormalizer> namespaceResolvers = getReferencedSchemaResolvers(context, isIgnoreCase(reference));
if (!namespaceResolvers.isEmpty())
result = createImportScope(result, namespaceResolvers, null, reference.getEReferenceType(), isIgnoreCase(reference));
}
return result;
}
@Inject
private IQualifiedNameConverter qualifiedNameConverter;
private List<ImportNormalizer> getReferencedSchemaResolvers(final EObject context, boolean ignoreCase) {
List<ImportNormalizer> importedNamespaceResolvers = Lists.newArrayList();
for (Reference ref : ((DeclaredSchema)context).getRefs()) {
// ----------------
String namespace = ref.getSchemaRef().getRef().getName();
// ----------------
QualifiedName importedNamespace = qualifiedNameConverter.toQualifiedName(namespace);
if (importedNamespace == null || importedNamespace.getSegmentCount() < 1) {
continue;
}
importedNamespaceResolvers.add(new ImportNormalizer(importedNamespace, true, ignoreCase));
}
return importedNamespaceResolvers;
}
In the following example ...
SCHEMA s1 {}
SCHEMA s2 {
REFERENCE FROM s1;
}
... i get an error...
Errors occurred during the build.
Errors running builder 'Xtext Project Builder' on project 'test'.
Cyclic resolution of lazy links : DeclaredSchemaRef.ref->DeclaredSchemaRef.ref
Can't understand what is wrong here?
It works if i define "Reference: 'REFERENCE' 'FROM' schemaRef=ID ';'", but i would like to have a list of declared schemas automatically proposed by a code assistant ...
Thank you!
[Updated on: Mon, 18 June 2012 15:14] Report message to a moderator
|
|
|
|
Re: importedNamespace w/o WildChar ? [message #890243 is a reply to message #890232] |
Thu, 21 June 2012 15:09 |
|
Hi,
i guess it is impossible to access the references at this point (since they do not exist so far)
what about using global scope provider/index to get propper content assist
instead of using cross references?
alternatively you could use nodemodelutil.getNodesForFeature to get the text
for the cross refs (as long as you do not use explicit imports this will work)
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.03329 seconds