How to turn an expression String into an Xtext object? [message #785840] |
Sun, 29 January 2012 10:34  |
Eclipse User |
|
|
|
Hello,
I have a DSL and a Debugger with Xtext 2.1.1 under Eclipse 3.7. Now I want to add an "Expressions View". When the expression view calls MyDslWatchExpressionDelegate.evaluateExpression(), the expression is passed as a String. So my question is, how can I turn this String into an Xtext object to which the MyDsl document is linked somehow, so that the expression can be evaluated considering references to the document. (I have a calculator like that from the Xtext arithmetics example in place.)
For example, if we had in a .mydsl document (don't care for the actual language) something like
...
int a = 3
int b = 4
...
the user might enter "a + b" in the expression view, and MyDslWatchExpressionDelegate.evaluateExpression() will be called with "a + b". How can I turn "a + b" into an object that can be passed to the calculator's evaluate function?
I could parse the string as a new document, but I don't know how to link the original document to the new one so that a and b could be referenced correctly.
Many thanks in advance for any kind of hint.
Uli
|
|
|
|
Re: How to turn an expression String into an Xtext object? [message #1006819 is a reply to message #1006816] |
Sat, 02 February 2013 07:00  |
Eclipse User |
|
|
|
Hi,
am not quite sure what you want to do (standalone, in eclipse ...),
but you can obtain a project aware resourceset using org.eclipse.xtext.ui.resource.IResourceSetProvider.
and you can load a resource from a string using org.eclipse.emf.ecore.resource.Resource.load(InputStream, Map<?, ?>)
[Updated on: Sat, 02 February 2013 07:04] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03347 seconds