Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Run the text generation from my editor
Run the text generation from my editor [message #664854] Tue, 12 April 2011 09:37 Go to next message
Sam is currently offline SamFriend
Messages: 9
Registered: April 2011
Junior Member
Hi all,

I'm abeginner with Xtext and I don't know how to the run the generation process defined in the 'generator' project.

I already defined my grammar and the generation template with Xpand. I already test it in the 'generator' project and it wiorks well.

When I run my projects as Eclipse Application, I can edit files according to my grammar. At this step, I want to run the generation to transform the file I am editing.

I don't know how to do that.
Anyone can help me ?
Re: Run the text generation from my editor [message #664858 is a reply to message #664854] Tue, 12 April 2011 10:13 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Hi, in the Eclipse b3 project I wrote several different "runners" that
operate on the file being in the editor (with a console, with a dialog,
parameterized actions defined in extension points, etc). In my case I
execute an interpreter - but should not be difficult to use a similar
setup to run generation.

This info is naturally not worth much if your question is really "how do
I run generation from code?" - I have not done that, so I can't answer.

- henrik

On 4/12/11 11:37 AM, Sam wrote:
> Hi all,
>
> I'm abeginner with Xtext and I don't know how to the run the generation
> process defined in the 'generator' project.
>
> I already defined my grammar and the generation template with Xpand. I
> already test it in the 'generator' project and it wiorks well.
>
> When I run my projects as Eclipse Application, I can edit files
> according to my grammar. At this step, I want to run the generation to
> transform the file I am editing.
>
> I don't know how to do that.
> Anyone can help me ?
Re: Run the text generation from my editor [message #664864 is a reply to message #664858] Tue, 12 April 2011 10:42 Go to previous messageGo to next message
Sam is currently offline SamFriend
Messages: 9
Registered: April 2011
Junior Member
In fact, my goal is to add some elements in my model while I'm editing a file (with a button, a menu or automatically)
I use the 'generator' project provide by Xtext but I don't know what is its tnterest in real.

I first supposed that I can run the workflow from the editor but I don't success to use it.

What is the good way to use it ?
Re: Run the text generation from my editor [message #664868 is a reply to message #664864] Tue, 12 April 2011 10:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the problem is that the is not the way to do this. you could do something "automatically" like it is done in the domain model example. or call the workflow programmatically. or or or

The Basic Problem is that the Workflow in the Generator Project by default is meant to work on n dsl files.

so what you can do is eg.

(1) enable wizard in workflow
// project wizard (optional) 
			 fragment = projectWizard.SimpleProjectWizardFragment {
			 		generatorProjectName = "${projectName}.generator" 
					modelFileExtension = file.extensions
			 }

(2) mere plugin.xml_gen to plugin.xml in ui project
(3) start runtime and create new yourdsl project via new project wizard (in the XText section)
(4) the wizard creates a project with dsl file and a workflow that triggers the generator

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Run the text generation from my editor [message #664919 is a reply to message #664868] Tue, 12 April 2011 13:50 Go to previous messageGo to next message
Sam is currently offline SamFriend
Messages: 9
Registered: April 2011
Junior Member
OK thanks

I try this and it works fine, like you said.
The probleme is that I want to generate text directly in the source file.

How can I define the workflow for having the source file as the target file ?
Re: Run the text generation from my editor [message #664929 is a reply to message #664864] Tue, 12 April 2011 13:59 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 4/12/11 12:42 PM, Sam wrote:
> In fact, my goal is to add some elements in my model while I'm editing a
> file (with a button, a menu or automatically)
That is typically done with code completion or templates. You can extend
that functionality to generate things dynamically. I think that is
better than doing things in a different way.

- henrik
Re: Run the text generation from my editor [message #664958 is a reply to message #664929] Tue, 12 April 2011 15:19 Go to previous messageGo to next message
Sam is currently offline SamFriend
Messages: 9
Registered: April 2011
Junior Member
The text I want to generate must contains informations from existing elements, e.g. the name of elements.
So, I need to run generation only after edition.

A good way to do that will be to transform the model just before the user save the file.
I don't know where to do that. I suppose I need to re-implement tjhe serializer or hook the save event.

Can you help me for this ?
What I have to do and where ?
Re: Run the text generation from my editor [message #664990 is a reply to message #664958] Tue, 12 April 2011 17:31 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Why not just add a workspace builder that reads the saved model and
produces output? You could probably also hook the Xtext builder to add a
participant in that build.

You really do need to hook to changes of the resource, not the fact that
the editor saves it - for instance if you check the file out from a
repository, revert the version etc. These are not "editor save"
operations...

Hope that helps.
- henrik

On 4/12/11 5:19 PM, Sam wrote:
> The text I want to generate must contains informations from existing
> elements, e.g. the name of elements.
> So, I need to run generation only after edition.
>
> A good way to do that will be to transform the model just before the
> user save the file.
> I don't know where to do that. I suppose I need to re-implement tjhe
> serializer or hook the save event.
>
> Can you help me for this ?
> What I have to do and where ?
Re: Run the text generation from my editor [message #665094 is a reply to message #664990] Wed, 13 April 2011 09:10 Go to previous messageGo to next message
Sam is currently offline SamFriend
Messages: 9
Registered: April 2011
Junior Member
You may be right !!!

But can I do it ?
If you can help me out a little it would be great.

Thanks
Re: Run the text generation from my editor [message #665154 is a reply to message #665094] Wed, 13 April 2011 12:59 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
I can't write the code for you ;-), but can point you to similar things
I have done, and answer concrete questions.

For starters, look at how an Eclipse IncrementalBuilder is done (google
for it). Alternatively, look at how a participant can be registered with
the XtextBuilder.

- henrik

On 4/13/11 11:10 AM, Sam wrote:
> You may be right !!!
>
> But can I do it ? If you can help me out a little it would be great.
>
> Thanks
Previous Topic:Guice Error when Xtext builder runs in Eclipse Headless
Next Topic:XText
Goto Forum:
  


Current Time: Fri Apr 26 00:42:15 GMT 2024

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

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

Back to the top