Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » parsing DSL in a Java application
parsing DSL in a Java application [message #901740] Tue, 14 August 2012 12:31 Go to next message
Andrea Sindico is currently offline Andrea SindicoFriend
Messages: 266
Registered: November 2010
Senior Member

I need to programmatically turn a text conform to an XText grammar into an AST conform to an ECORE meta-model generated by XText from the same grammar. I know XText also generate the Java classes implementing such parser but I don't know either where they are and how to use it. Any help is very appreciated

I have managed to instantiate the injector

Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();

but is still not clear to me how to use it to create an instance of the ParseHelper<MyDSLRootElement> generic class
Re: parsing DSL in a Java application [message #901752 is a reply to message #901740] Tue, 14 August 2012 13:03 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Short answer: You just load the source file (xxx.mydsl) as an EMF
resource, and then get the model from the EMF resource. Xtext takes care
of the rest.

- henrik

On 2012-14-08 14:31, Andrea Sindico wrote:
> I need to programmatically turn a text conform to an XText grammar into
> an AST conform to an ECORE meta-model generated by XText from the same
> grammar. I know XText also generate the Java classes implementing such
> parser but I don't know either where they are and how to use it. Any
> help is very appreciated
>
> I have managed to instantiate the injector
> Injector injector = new
> MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
>
> but is still not clear to me how to use it to create an instance of the
> ParseHelper<MyDSLRootElement> generic class
Re: parsing DSL in a Java application [message #901790 is a reply to message #901752] Tue, 14 August 2012 15:19 Go to previous messageGo to next message
Andrea Sindico is currently offline Andrea SindicoFriend
Messages: 266
Registered: November 2010
Senior Member

Hi Henrik, I guess I haven't understood your answer or my question was not clear enough.
I am in the middle of an ACCELEO Transformation aimed at producing code (i.e. Java) from an input UML model. Some elements of this UML model (i.e. Activities Opaque actions) contain some text which is conform to an Xtext grammar and I'd like to get the equivalent AST Ecore representation in the ACCELEO transformation. To this end I am developing a Java class with a method which takes as input a string, containing the DSL excerpt, and shall produce an ECORE model conform to it. In this way I can write a simple ACCELEO module wrapping that java class and enabling me to get the Ecore model from the DSL textual representation. I hope this clarify why I can't just open a source file.

My question is how can I programmatically ( I mean in a Java Class) turn a string containing a DSL script to the related ECORE model? If it is not that hard may I ask you to post the required lines of code. Thanks a lot in advance


Follow me on Twitter @andreasindico

Re: parsing DSL in a Java application [message #901833 is a reply to message #901790] Tue, 14 August 2012 17:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

have a look at http://wiki.eclipse.org/Xtext/FAQ#How_do_I_load_my_model_in_a_standalone_Java_application.C2.A0.3F

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: parsing DSL in a Java application [message #901947 is a reply to message #901833] Wed, 15 August 2012 09:01 Go to previous message
Andrea Sindico is currently offline Andrea SindicoFriend
Messages: 266
Registered: November 2010
Senior Member

Thank you Christian, it was indeed what I was looking for

Follow me on Twitter @andreasindico

Previous Topic:Synchronized model instance and text editor(s)
Next Topic:Customize code checker
Goto Forum:
  


Current Time: Fri Mar 29 11:45:20 GMT 2024

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

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

Back to the top