Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How can I generate code from my XText DSL without IDE?
How can I generate code from my XText DSL without IDE? [message #1297022] Tue, 15 April 2014 11:13 Go to next message
Simon Ziehme is currently offline Simon Ziehme
Messages: 12
Registered: November 2013
Junior Member
I would like generate my C++ code from my own dsl without IDE. Inside Eclipse IDE everthing is fine. I can also build my CDT project (headlessbuild) but the xtext/xtend generation is missing.

Any ideas?

Thanks Simon
Re: How can I generate code from my XText DSL without IDE? [message #1297121 is a reply to message #1297022] Tue, 15 April 2014 12:39 Go to previous messageGo to next message
Joerg Reichert is currently offline Joerg Reichert
Messages: 78
Registered: July 2009
Location: Leipzig
Member
Hi Simon,

In http://lwc11-xtext.eclipselabs.org.codespot.com/files/LWC11-XtextSubmission-v1.2.pdf on page 130 (14.2 Headless Generator) there is an example how to do this in pure Java. Alternatively and the more preferred way you can also write a mwe2 file and load and start this from command line.

With

fragment = generator.GeneratorFragment auto-inject {
     generateMwe = true
}


in the language generation workflow you can pregenerate a workflow file executing the generator of your DSL.

Best regards,
Joerg


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Re: How can I generate code from my XText DSL without IDE? [message #1297133 is a reply to message #1297121] Tue, 15 April 2014 12:47 Go to previous messageGo to next message
Simon Ziehme is currently offline Simon Ziehme
Messages: 12
Registered: November 2013
Junior Member
Thank you, Joerg.

Simon
Re: How can I generate code from my XText DSL without IDE? [message #1298881 is a reply to message #1297133] Wed, 16 April 2014 15:22 Go to previous messageGo to next message
Joerg Reichert is currently offline Joerg Reichert
Messages: 78
Registered: July 2009
Location: Leipzig
Member
One thing I forgotten to mention was, that there is the org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner. With that you can execute mwe2 files.

Joerg


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Re: How can I generate code from my XText DSL without IDE? [message #1299850 is a reply to message #1298881] Thu, 17 April 2014 06:43 Go to previous messageGo to next message
Simon Ziehme is currently offline Simon Ziehme
Messages: 12
Registered: November 2013
Junior Member
Thanks Joerg!

One question about the workflow.

I have a workspace/project for my DSL implementation, code generation ...
Now I will starting a runtime eclipse.
The dsl editor works fine, code genaration also.

I have also generated the mwe2 file. ( bin directory in the dsl impl. project)

Now, how can I call the generation on the command line?


./eclipse -nosplash org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner  -data "/home/simonz/dev/runtime-EclipseXtext"


This will be not working!?

Thanks Simon
Re: How can I generate code from my XText DSL without IDE? [message #1299912 is a reply to message #1299850] Thu, 17 April 2014 07:36 Go to previous message
Joerg Reichert is currently offline Joerg Reichert
Messages: 78
Registered: July 2009
Location: Leipzig
Member
Hi Simon,

you don't need to start Eclipse.

This a little example:
public class Main {

	public static void main(String[] args) {
		Injector injector = new Mwe2StandaloneSetup().createInjectorAndDoEMFRegistration();
		Mwe2Runner runner = injector.getInstance(Mwe2Runner.class);
		URI createURI = URI.createFileURI("src/org/xtext/example/mydsl/generator/MyDslGeneratorMWE.mwe2");
		Map<String, String> params = new HashMap<String, String>();
		params.put("modelPath", "samples/");
		params.put("targetDir", "output");
		runner.run(createURI, params);
	}

}


As an alternative, you even can pre-generate a Main class by using this snippet in the grammar mwe2 file:

fragment = generator.GeneratorFragment auto-inject {
	generateMwe = true
	generateJavaMain = true
	
}


This code doesn't use the Mwe2Runner and takes only one resource as input but you may adapt this to your needs as well.

Joerg


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Previous Topic:xText allows to create a Prolog Parser?
Next Topic:Xtend JUnit test in domainmodel example stop running
Goto Forum:
  


Current Time: Thu Oct 30 17:50:30 GMT 2014

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

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