Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Need a hint for dynamic imports(auto-generating an import)
Need a hint for dynamic imports [message #1037801] Tue, 09 April 2013 22:52 Go to next message
Eclipse UserFriend
I want to be able to reference a dataset and dynamically import it into my file for content assist.

I need help figuring out where in the xtext workflow I can trigger dynamic imports.

Example1:

I have data/sample.csv defined within my project.

I want to read the header line from that csv and create a dynamic resource based on that information.

I'd like to define it so that the syntax is:

import data.sample

then when a user gets to a certain point within their script, hitting ctrl+space will give them an content-assist with a list of referencable fields.

Example2:
data is stored within a database. Same situation, slightly different code behind the scenes.
import sql:sampledb.sampletable

The login, password, and database type would be either stored as configuration data or as parameters
import sql:sampledb.sampletable(login,password,mysql)


My only point of bringing up the second example is that the syntax for the imports would be slightly different.

I understand that I need to build a resource and add that resource to my resourceset. Where I'm coming up a little bit shy is where to trigger the event that would build the resource.

Of course I'll have to find a way to manage file updates as well. Monitoring the file is straightforward enough, but I'll have to update or replace the resource and I'm unsure how to trigger that.
Re: Need a hint for dynamic imports [message #1037852 is a reply to message #1037801] Wed, 10 April 2013 00:52 Go to previous messageGo to next message
Eclipse UserFriend
Just thinking as I'm typing here... but I'm leaning towards handling this in my scope provider. Any calls to the scope provider look for any new import references and if there are any new ones, handle them before processing the reference. That seems straightforward enough. I think I might have been over-thinking the problem.

Re: Need a hint for dynamic imports [message #1038325 is a reply to message #1037852] Wed, 10 April 2013 14:36 Go to previous message
Eclipse UserFriend
Hi,

depending on what you do in your script and how they work
(xbase/noxbase singlefile/multiplefiles) it can work more or less out of the box
here a very quick try:

DSL1

Model:
	elements+=Element*;

Element:
	name=ID "=" value=ID
;	



dsl2

Model:
	imports+=Import*
	uses+=Use*;
	
Import:
	"import" importURI=STRING
;

Use:
	"use" key=[def::Element]
;


    bean = StandaloneSetup {
    	scanClassPath = true
    	platformUri = "${runtimeProject}/.."
    	registerGeneratedEPackage = "org.xtext.example.define.defineDsl.DefineDslPackage"
    	registerGenModelFile = "platform:/resource/org.xtext.example.define/src-gen/org/xtext/example/define/DefineDsl.genmodel"
    }
.....
    		fragment = scoping.ImportURIScopingFragment auto-inject {}
    		fragment = exporting.SimpleNamesFragment auto-inject {}
    
    		// scoping and exporting API
//    		fragment = scoping.ImportNamespacesScopingFragment auto-inject {}
//    		fragment = exporting.QualifiedNamesFragment auto-inject {}
    		fragment = builder.BuilderIntegrationFragment auto-inject {}

....
    		// provides the necessary bindings for java types integration
//    		fragment = types.TypesGeneratorFragment auto-inject {}
//    
//    		// generates the required bindings only if the grammar inherits from Xbase
//    		fragment = xbase.XbaseGeneratorFragment auto-inject {}
    



import "test.define"
use a


if you dont want to use explicit imports at all
http://christiandietrich.wordpress.com/2012/08/07/xtext-referencing-elements-of-one-dsl-from-another-dsl/
Previous Topic:Referring to user-defined variables from Xbase expressions
Next Topic:Possible move coloring after opening?
Goto Forum:
  


Current Time: Fri Jul 04 22:18:46 EDT 2025

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

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

Back to the top