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
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
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