Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xtext 2] parsing files shipped in the plug-in itself
[xtext 2] parsing files shipped in the plug-in itself [message #662567] Thu, 31 March 2011 07:26 Go to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Greetings,

I have found it very difficult to explain my problem. I apologize in advance if this explanation makes little or no sense Smile

As part of the Xtext-based plug-in that I'm developing, I need to have some kind of "global model" that provides some elements to be available to all the Xtext editors that a user may create or open. I need these elements to provide scope resolution.

The only thing that comes to mind is to ship this base model as part of the plug-in itself and parse it at some point after my plug-in is loaded and have somehow a global reference to it.

For example, I'll have a base.dsl file inside my plug-in and the model obtained from parsing such file will be available to any .dsl file that users of my plug-in may create.

My questions are:
1. Am I on the right track? Does this idea make sense at all? I'm totally open to alternatives.
2. If my idea makes sense, at which point should I load and parse the file? so far the only way I found to find a file in a plug-in is the one described at http://www.eclipse.org/forums/index.php?t=msg&goto=66050 6&S=0d0d50ff15cf9d886e9b79301ea40efd

Many thanks in advance,
-Alex

[Updated on: Sun, 03 April 2011 08:15]

Report message to a moderator

Re: parsing files shipped in the plug-in itself [message #662586 is a reply to message #662567] Thu, 31 March 2011 08:47 Go to previous messageGo to next message
Mark Christiaens is currently offline Mark ChristiaensFriend
Messages: 63
Registered: October 2010
Member
I don't know if I should recommend this approach but here's what I've tried recently. I created a read-only eclipse file system (EFS) with my own URI scheme. That file system provides a number of library files that should be present in every project. Then I link to that file system from every Eclipse project. The files that the read-only file system must make available are all stored inside the jar of that file system and can be read from the classpath.

It seemed to be working well until I discovered that there's a bug in some Eclipse validation code when copying the file-links from one project to another causing it to throw a NPE. I think I could work around this bug but it's going to be difficult.
---
Mark Christiaens
Discover the Future of VHDL Design
Go to www.sigasi.com
Re: parsing files shipped in the plug-in itself [message #662981 is a reply to message #662586] Fri, 01 April 2011 17:34 Go to previous messageGo to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Thanks Mark!

I got something working before I read your post. I'll be posting the code (in case somebody likes to review it) soon (after I fixed a minor problem I have with linking.

Cheers,
-Alex
Re: parsing files shipped in the plug-in itself [message #663020 is a reply to message #662981] Sat, 02 April 2011 06:30 Go to previous messageGo to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Here is what I did, and it works!

  @Inject public GlobalScope(IParser parser) {
    try {
      XtextResource resource = new XtextResource(URI.createURI(""));
      IParseResult result = parser.parse(new InputStreamReader(globalScopeContents(), "UTF-8"));
      root = result.getRootASTElement();
      resource.getContents().add(root);
    } catch (IOException e) {
      throw new IllegalStateException("Unable to parse global scope", e);
    }
  }

  private static InputStream globalScopeContents() throws IOException {
    Bundle bundle = Platform.getBundle("my.plugin");
    Path originPath = new Path("global.dsl");
    URL bundledFileURL = find(bundle, originPath, null);
    return (InputStream) resolve(bundledFileURL).getContent();
  }


It parses the file global.dsl which contains the elements to be considered as "global scope" or actually "implicit scope."

Comments/feedback welcome Smile

Cheers,
-Alex
Re: parsing files shipped in the plug-in itself [message #663053 is a reply to message #663020] Sat, 02 April 2011 19:28 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

the following should work with the default settings in your language:

place your global model in an exported folder of your grammar project (e.g. next to the .xtext grammar file) and deploy the plugin.

Then declare a dependency to the grammar plugin
in the project where you do the actual modeling (either plugin dependency or import the package where the global model is located). In other words, make the global model be on the classpath of the project.

Now, the elements of the global model should be visible. Out of the box. No adaptions required. Of course the project where you do the modeling must eb a java project.

If you use the ImportUriScoping fragment, you will have to adapt the ImportUriGlobalScopeProvider, using an extended implementation that adds a classpath Uri to the global model (this can be done in the getImportedUris method).

Alex
Re: parsing files shipped in the plug-in itself [message #663056 is a reply to message #663053] Sat, 02 April 2011 20:53 Go to previous message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Thanks Alex,

Unfortunately I'm unable to use your tip. The editor I'm working on needs to be language-independent (I mean it does not require, but be used in a JDT or CDT project.)

I guess I have to stick to my somehow ugly but still useful solution Smile

Cheers,
-Alex
Previous Topic:Passing complex boolean expressions to Xbase filter method
Next Topic:[xtext 2] Some problems with qualified names
Goto Forum:
  


Current Time: Fri Apr 26 09:36:39 GMT 2024

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

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

Back to the top