Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Combining Importing scope and a local scope
Combining Importing scope and a local scope [message #1699296] Tue, 23 June 2015 09:41 Go to next message
Eleanor Richie is currently offline Eleanor RichieFriend
Messages: 125
Registered: August 2014
Senior Member
Hi,

I have a language that allows something like this:

package pack{
field foo1
field foo2
}

definitions def {
field fox1
field fox2
}

use MyFile.pack.all; //It means that ALL the fields in the package pack are included in the coming expression.

expression using def //After the using I have a cross-reference with the definitions
{
field expField
ref fox1
ref foo1
ref expField
}
---------------------------------------------------------------
I override the method internalGetImportedNamespaceResolvers so that it can resolve the fields in the package and it worked. Then I followed this example to https://github.com/LorenzoBettini/xtext-scoping/blob/master/org.xtext.example.helloscoping/org.xtext.example.helloscoping/src/org/xtext/example/helloscoping/scoping/HelloScopingScopeProvider.java to add the fields in the used definition scope to the expression and it worked but then I found that the work I had done for the package to be included is no longer working.
Here is my implementation for getscope:
@Override
   public IScope getScope(EObject context, EReference reference) {
      if (context == null) {
         throw new NullPointerException("context");
      }
      IScope result = null;
   if (context instanceof FieldReference){
         FieldReference fieldReference = (FieldReference) context;
         Expression exp= (Expression) fieldReference.eContainer();
		if(exp== null || exp.getUsedDefinition() == null) { 
			return IScope.NULLSCOPE;
		}
		
		IScope parentScope = Scopes.scopeFor(exp.getUsedDefinition().getFields(), IScope.NULLSCOPE);
		return Scopes.scopeFor(exp.getFields(), parentScope);

}
   else if (!(context instanceof Model)) {    
            result = getScope(context.eContainer(), reference);
            }
       else {
         result = getResourceScope(context.eResource(), reference);
      }
         return getLocalElementsScope(result, context, reference);

   }


----------------------------------------------------------------
All I want is like combining the scope of the definition, expression and the used package in a single scope for the expression. Any Help Please? Sad
Re: Combining Importing scope and a local scope [message #1699318 is a reply to message #1699296] Tue, 23 June 2015 11:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
to get the out/globale scope you have to call delegateGetScope as well (maybe as parent scope of your parentScope)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Combining Importing scope and a local scope [message #1699326 is a reply to message #1699318] Tue, 23 June 2015 12:10 Go to previous messageGo to next message
Eleanor Richie is currently offline Eleanor RichieFriend
Messages: 125
Registered: August 2014
Senior Member
what does delegateGetScope do? Do I have to make anything in getLocalElementsScope?
Re: Combining Importing scope and a local scope [message #1699328 is a reply to message #1699326] Tue, 23 June 2015 12:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi

delegateGetScope from your local scopeprovider calls your importednamespaceawarelocalscopeprovider call globalscopeprovider


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Combining Importing scope and a local scope [message #1699447 is a reply to message #1699328] Wed, 24 June 2015 11:36 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
I am facing a similar challenge. In my DSL, a symbol is defined either in the file the user edits, an imported file, or is a global symbol accessible from all files. For the last category of symbols a possible solution could be to define a file that declares all global symbols.

When searching for a symbol in the scope provider (MyDSLScopeProvider extends AbstractDeclarativeScopeProvider) I plan to apply the following strategy:

  1. Search the context for the symbol.
  2. Get the included files from the root container of the context and load the corresponding resources. Search the loaded resources until one of them yelds the symbol.
  3. Search the file containing the global symbols.

Include files have the syntax file.ext or dir\file.ext. In both cases the path is relative to the file making the include. I suppose I should use XtextResourceSet to load the resource. What is the format of URI's the ResourceSet expects for loading a file relative to the current file?

For the global symbols, perhaps the best would be to load the resource when the plugin initializes. Are the StandaloneSetup or RuntimeModule the proper place where to include the code for loading the resource?
Re: Combining Importing scope and a local scope [message #1699448 is a reply to message #1699447] Wed, 24 June 2015 11:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this should happen automatically

YourDslScopeProvider calls importednamespaceawarelocalscopeprovider calls globalscopeprovider


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Combining Importing scope and a local scope [message #1699465 is a reply to message #1699448] Wed, 24 June 2015 13:01 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
It doesn't. For includes I used the rule name as described in https://blogs.itemis.de/leipzig/archives/776. I use URI scoping and simple names:
fragment = scoping.ImportURIScopingFragment auto-inject {
ignoreCase = true
}
fragment = exporting.SimpleNamesFragment auto-inject {}
// scoping and exporting API
// fragment = scoping.ImportNamespacesScopingFragment auto-inject {
// ignoreCase = true
// }
// fragment = exporting.QualifiedNamesFragment auto-inject {}

and the include rule in the grammar is:
Include : '#include' WS importURI = ppath;

I can only see symbols defined in one file. Those declared in included files can not be resolved.
Re: Combining Importing scope and a local scope [message #1699468 is a reply to message #1699465] Wed, 24 June 2015 13:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
HI,

import uri scoping i a complete different topic. if makes only stuff visible that you explicitely import. so please explain your exact requirements


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Combining Importing scope and a local scope [message #1699482 is a reply to message #1699468] Wed, 24 June 2015 14:27 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Sorry. I thought the topic of the original post was adequate.

The use case is as follows:
1. A file may contain symbol definitions resolved by scoping. The scope of the symbols is local to the file.
2. A file may include other files. The symbols defined in the included file should be available to the file including it.
3. There are no namespaces and symbol names are simple identifiers.
4. A file has access to a set of predefined symbols with global scope. These symbols are not specified in any file. The interpreter of the DSL declares the symbols and makes them available to all files.

Regarding (4) I think I could use a file that defines the global symbols. This file should be part of the plugin distribution. The plugin should load the file either the first time it fails to find a symbol or when the plugin is loaded.

The problem is that the symbols of included files are not available. I would appreciate some advice on how to find why this happens. The grammar follows the conventions for include files described in https://blogs.itemis.de/leipzig/archives/776.

Secondly, when would be best to load the file with the definitions of global variables.

Finally, how should I load that file. One way could be to invoke method getResource of ResourceSet or the XText specialization of ResourceSet with a URI like "platform:/plugin/.../system.ext" where system.ext stores the global symbol definitions. The problem is I don't know how to get a reference to a properly configured ResourceSet object.
Re: Combining Importing scope and a local scope [message #1699485 is a reply to message #1699482] Wed, 24 June 2015 14:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

can you share a minimal grammar and sample models i can copy & paste. i have no time to do this myself


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Combining Importing scope and a local scope [message #1699503 is a reply to message #1699485] Wed, 24 June 2015 16:01 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Download the files from https://drive.google.com/file/d/0B2HwrGII4cXVcFlYYXEtT2p4UjA/view The zip file includes the project files and a folder(named sample) containing two sample files of the DSL. The grammar includes only the rules required for showing the problem.

Re: Combining Importing scope and a local scope [message #1699512 is a reply to message #1699503] Wed, 24 June 2015 16:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
(1)
you have to remove fragment = types.TypesGeneratorFragment auto-inject {} as well
(2)
then your multi file extension stuff does not seem to work
change the workflow to
var fileExtensions = "p4,jmod"
and merge plugin.xml and plugin.xml_gen

(3)
reenable global scope in the scope provider

def IScope scope_Field_declaration(Field context, EReference reference) {
val view = EcoreUtil2.getRootContainer(context) as View;
new SimpleScope(delegateGetScope(context, reference), Scopes.scopedElementsFor(view.fields), true)
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Combining Importing scope and a local scope [message #1699585 is a reply to message #1699512] Thu, 25 June 2015 09:00 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Thank you Christian. Your suggestions were most helpful.

Regarding (1), should I remove the fragment because is not needed or does it get in the way in scoping?
(3) Is it that without the delegate scope, the SimpleScope could not access information available in other files?

After applying your suggestions, the plugin tries to load the included file. I get the error message:
0 [main] ERROR org.eclipse.xtext.linking.lazy.LazyLinkingResource - resolution of uriFragment '|1' failed.
java.lang.IllegalStateException: No IResourceServiceProvider found in registry for uri incl.jmod

I kept only one file extension (jmod) to remove a potential source of error. In the workflow I have
var fileExtensions = "jmod"
and in the plugin.xml in the ui project I replaced the value of extensions and fileExtensions as well.
Re: Combining Importing scope and a local scope [message #1699603 is a reply to message #1699585] Thu, 25 June 2015 10:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
What do you exactly do when you get the error. are you sure the plugin.xml is correct regarding the file extensions

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Combining Importing scope and a local scope [message #1699608 is a reply to message #1699603] Thu, 25 June 2015 10:51 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
I searched the directories for case insensitive occurrences of "extensions". It finds it in the workflow file, and the terms "extensions" and "fileExtensions" in the plugin.xml file of the ui project. In all cases the value is "jmod".

To get the error, from within Eclipse I choose "Launch Runtime Eclipse" and open an instance of Eclipse with sample.jmod opened. The file incl.jmod is also opened in the editor and both files belong to the same project and are in the same folder. The error along with a stack trace is printed in the Console of the Eclipse instance I use to develop the plug-in.

In a second test I closed both files from Runtime Eclipse and closed the instance. Then I launched the instance again.
1. Open the file incl.jmod (no errors reported in the console)
2. Open the sample.jmod (I get the error)

Before experimenting, I always execute the "Generate Language Infrastructure" command.
Re: Combining Importing scope and a local scope [message #1699614 is a reply to message #1699608] Thu, 25 June 2015 11:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
do the following:

adapt the workflow, run it and copy plugin.xml_gen to plugin.xml (as said before)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Combining Importing scope and a local scope [message #1699640 is a reply to message #1699614] Thu, 25 June 2015 12:54 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
I'm baffled. It worked! I suppose there were other differences between plugin.xml and plugin.xml_gen.

Regarding system symbols, I store their definition in a file distributed with the plug-in.

In the ScopeProvider, I load the file resource with:
system = rs.getResource(URI.createPlatformPluginURI("/..../sytem.jmod")

When searching for a symbol, I put in a list the symbols defined in the current file and append those defined in system.jmod.
Everything works fine except for Ctlr+Left click jumps to the beginning of the current file instead of visiting system.jmod. This makes sense since I present the symbols defined in system.jmod as belonging to the current file.
Perhaps there is a way to place those symbols in the global scope or have the parent scope of the current file associated with the resource that contains the system.jmod file.

Anyway, it's not a big deal if I can't jump to the definition of global symbols.

Thank you for the helpful suggestions. I appreciate your help.

Regards.
Re: Combining Importing scope and a local scope [message #1699646 is a reply to message #1699640] Thu, 25 June 2015 13:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

why don't you ship them with your project and add a implicit explicit import for that


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Combining Importing scope and a local scope [message #1699651 is a reply to message #1699646] Thu, 25 June 2015 14:33 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Not sure if I understand correctly your suggestion.

I do ship the file with the system symbols with the plugin project. I don't know however how to add an implicit dependency (include) to that file.
Re: Combining Importing scope and a local scope [message #1699655 is a reply to message #1699651] Thu, 25 June 2015 14:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
how does the model in the runtime look like? java Project? etc?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Combining Importing scope and a local scope [message #1699656 is a reply to message #1699655] Thu, 25 June 2015 15:10 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
The project I'm using to test the plugin contains java files, is integrated with Maven and uses Git for version control.
Re: Combining Importing scope and a local scope [message #1699664 is a reply to message #1699656] Thu, 25 June 2015 15:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
No i meanin production. How does the project the user models in look like

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Combining Importing scope and a local scope [message #1699679 is a reply to message #1699664] Thu, 25 June 2015 19:00 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Yes, the user project in production has the configuration I listed in the previous message. Why is it important what other files exist in the user project?
Re: Combining Importing scope and a local scope [message #1699686 is a reply to message #1699679] Thu, 25 June 2015 19:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
if it is a java project and the lib jar is on the classpath you can do

import "classpath:/lib/test.mydsl" explicitely or implicitely

public class MyDslImportUriGlobalScopeProvider extends
		ImportUriGlobalScopeProvider {
	
	@Override
	protected LinkedHashSet<URI> getImportedUris(Resource resource) {
		LinkedHashSet<URI> importedUris = super.getImportedUris(resource);
		importedUris.add(URI.createURI("classpath:/lib/test.mydsl"));
		return importedUris;
	}

}



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Combining Importing scope and a local scope [message #1700389 is a reply to message #1699686] Thu, 02 July 2015 10:37 Go to previous message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Thank you. That works.
Previous Topic:get path of the active project
Next Topic:Editor won't open
Goto Forum:
  


Current Time: Fri Apr 26 12:57:14 GMT 2024

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

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

Back to the top