Automatic import of well-known functions [message #774636] |
Wed, 04 January 2012 10:22 |
Thomas Ponweiser Messages: 9 Registered: January 2012 |
Junior Member |
|
|
Hy everybody!
I'm currently developing a simple DSL quite similar to the "XText Simple Arithmetic Example" which should support C-like numeric and boolean expressions with references to variables and functions.
Additionally to those variables and functions defined locally in the file, I would like to provide also well known functions ("sin", "cos",...) and (constant) variables ("pi", "e",...).
For that purpose, I don't want to use any "import" keyword or something like that - instead those names should be imported implicitely.
Moreover those names should be determined on runtime. The approach to define some functions and variables statically in a resource file is not enough for me, even though I'd also like to know how this could be done (automatically importing a file without explicitely mentioning it in an "import" statement).
My first approach was to costumize my ScopeProvider:
public class AODslScopeProvider extends AbstractDeclarativeScopeProvider {
private List<String> functions = Arrays.asList("sin", "cos");
private List<String> variables = Arrays.asList("pi", "e");
private List<IEObjectDescription> knownObjects = new LinkedList<IEObjectDescription>();
public AODslScopeProvider() {
AodslFactory f = AodslFactory.eINSTANCE;
for(String funcName : functions) {
Function func = f.createFunction();
func.setName(funcName);
knownObjects.add(EObjectDescription.create(funcName, func));
}
for(String varName : variables) {
Variable var = f.createVariable();
var.setName(varName);
knownObjects.add(EObjectDescription.create(varName, var));
}
}
@Override
public IScope getScope(EObject context, EReference reference) {
// I guess this is not the way how SimpleScopes are meant to be used...
return new SimpleScope(super.getScope(context, reference), knownObjects);
}
}
This workes so far - the functions and variables are available in the editors content assistent, but actually referring to them leads to the following error:
The feature 'name' of 'ao.explorer.dsl.aodsl.impl.FuncCallImpl@1b09ef0{platform:/resource/test/src/test.aodsl#//@statements.2}' contains a dangling reference 'ao.explorer.dsl.aodsl.impl.FunctionImpl@1e7501{#//}'
Should I rather use a GlobalScopeProvider for that purpose? How do I do that? (I didn't find something like that in the example projects.) Or am I completely on the wrong track?
I'd be grateful for any advise!
kind regards,
Thomas
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03329 seconds