Calling parser/generator programmatically [message #1220230] |
Tue, 10 December 2013 14:02 |
Leandro Marques Messages: 11 Registered: July 2009 |
Junior Member |
|
|
Hi guys,
I am creating a new grammar and code generator but I don't want to use it in an Eclipse editor. I actually would like to create a REST service to receive the file the unit to be compiled and then code would be generated. For this, I would need to call the xtext parser and generator programmatically within a Java Web project (tomcat).
How can I do it?
In this same context, another question is: is it ok to return a JSON resource with the possible compilation errors present on the given unit from REST service call?
Thanks in advance,
[Updated on: Tue, 10 December 2013 14:50] Report message to a moderator
|
|
|
Re: Calling parser/generator programmatically [message #1220243 is a reply to message #1220230] |
Tue, 10 December 2013 14:59 |
|
Hi,
this should work straight forward
Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
ResourceSet resourceSet = injector.getInstance(ResourceSet.class);
Resource r = resourceSet.getResource(URI.createURI("x.mydsl"), true);
r.load(null);
IGenerator generator = injector.getInstance(IGenerator.class);
InMemoryFileSystemAccess fsa = injector.getInstance(InMemoryFileSystemAccess.class);
generator.doGenerate(r, fsa);
for (CharSequence s : fsa.getTextFiles().values()) {
System.out.println(s);
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
Re: Calling parser/generator programmatically [message #1721272 is a reply to message #1721234] |
Tue, 26 January 2016 09:05 |
Uli Merkel Messages: 250 Registered: June 2013 |
Senior Member |
|
|
In Lorenzo Bettinis famous book near the end of chapter 7, there is something about unit-testing eclipse functionality like opening editors etc.
Perhaps this may give you some hint how you con start re-generation for some DSL files.
And at the very end of chapter 5, there are some instructions how to get a "standalone command-line compiler" which takes the DSL file path as an argument for the generator.
So it's just a one-liner in a batch command file
Greetings from Frankfurt/Germany,
Uli
[Updated on: Tue, 26 January 2016 13:34] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03474 seconds