Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to turn an expression String into an Xtext object?
How to turn an expression String into an Xtext object? [message #785840] Sun, 29 January 2012 15:34 Go to next message
Uli B is currently offline Uli BFriend
Messages: 36
Registered: January 2012
Member
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 #1006816 is a reply to message #785840] Sat, 02 February 2013 11:37 Go to previous messageGo to next message
Alexis Drogoul is currently offline Alexis DrogoulFriend
Messages: 5
Registered: July 2010
Junior Member
Hi,

It's been a year now and no answer to your request... Unfortunately, I do not have one myself, but it happens that I would like exactly what you were looking for. Did you receive any suggestion ? Implement this by yourself ? In any case, I would be interested by the solution you have chosen.

Thanks !
Re: How to turn an expression String into an Xtext object? [message #1006819 is a reply to message #1006816] Sat, 02 February 2013 12:00 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
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<?, ?>)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 02 February 2013 12:04]

Report message to a moderator

Previous Topic:writing to IXtextDocument
Next Topic:DSL showing attributes based on its content value
Goto Forum:
  


Current Time: Tue Sep 24 17:14:27 GMT 2024

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

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

Back to the top