Need a hint for dynamic imports [message #1037801] |
Tue, 09 April 2013 22:52  |
Eclipse User |
|
|
|
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:
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 #1038325 is a reply to message #1037852] |
Wed, 10 April 2013 14:36  |
Eclipse User |
|
|
|
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/
|
|
|
Powered by
FUDForum. Page generated in 0.04908 seconds