Resolving variables from an external source [message #1732039] |
Thu, 12 May 2016 04:00  |
Eclipse User |
|
|
|
I'm new to working with Xtext and Xtend and I have stumbled upon a problem which I hope someone can help me solve. What I'm trying to achieve is to resolve variables from an external source rather than declaring them explicitly in the DSL. I got the following example to demonstrate: Here is the grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase
Model:
configUrl=ConfigUrl
devices+=Device*
test=Test
;
ConfigUrl:
"ConfigURL=" url=STRING
;
Device:
'Device' name=ID
'has channels: ' (channels+=Channel (',' channels+=Channel)*)?
;
Channel:
name=ID
;
Test:
'DoSomething' channel=[Channel|QualifiedName]
;
and here is an example usage:
ConfigURL="---some url goes here---"
Device Light has channels: state
DoSomething Light.state
Instead of explicitly declaring the devices in the DSL I would like to resolve them from and external source (the ConfigURL variable). As far as I can tell, what I'm looking for is related to the scoping functionality of Xtend. I have tried to implement the IScope interface and got the getAllElements to work (entries shows up in the autocompletion), but cannot get getSingleElement to work and thus why the variable cannot be resolved once entered.
Thanks,
|
|
|
|
|
|
Re: Resolving variables from an external source [message #1732577 is a reply to message #1732575] |
Wed, 18 May 2016 06:57  |
Eclipse User |
|
|
|
Do you really want to cross-reference data you fetch live from the internet? Scoping, linking etc. are live services, i.e. they are called on user actions like keystrokes and should not have to deal with long running operations. Imagine content assist blocking because of a temporary internet problem...
Nevertheless, in order to refer to elements from non-Xtext based models, you have to register an implementation for the minimum infrastructure that Xtext needs. This is as Karsten pointed out mainly about index entries for the referable elements.
If you don't want to deep dive into the innards of Xtext, you could also build an Xtext grammar that is able to parse these files. I'd not be suprised if there already was an Xtext grammar for JSON.
|
|
|
Powered by
FUDForum. Page generated in 0.05207 seconds