Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Calling parser/generator programmatically(How to call xtext parser and generator programmatically in a Web project)
Calling parser/generator programmatically [message #1220230] Tue, 10 December 2013 14:02 Go to next message
Leandro Marques is currently offline Leandro MarquesFriend
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 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
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 #1220274 is a reply to message #1220243] Tue, 10 December 2013 18:40 Go to previous messageGo to next message
Leandro Marques is currently offline Leandro MarquesFriend
Messages: 11
Registered: July 2009
Junior Member
However, and unfortunately it does not work. I cannot access classes like "MyDslStandaloneSetup" while executing an instance of eclips with the language plugin installed. My idea is:

1) install the language plugin in an Eclipse instance, with built-in parser and generator
2) With the plugin installed, create a web project, which contains a REST service
3) Through the REST service I am going to receive a content following the described grammar.
4) Using the built-in parser and compiler (programmatically) I would like to compile and generate code for that language.
5) If possible I would like also to return compilation errors to the user.

Imagine that as an architeture of a web-based editor for a DSL that uses xtext in the back end. The remote editor should be able to generate a set of resorces, and return compilation errors to the remote user.

How can I do it?

Thanks in advance,
Re: Calling parser/generator programmatically [message #1220275 is a reply to message #1220274] Tue, 10 December 2013 19:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

sorry i still do not understand what you mean,
i thought you want to call this code from withing an web application (WAR) and not from within eclipse


but if you call this from an osgi envionment you can indeed not call standalonesetup. but you can something like the combination
- of my previous post
- http://koehnlein.blogspot.de/2012/11/xtext-tip-how-do-i-get-guice-injector.html
- http://christiandietrich.wordpress.com/2011/10/15/xtext-calling-the-generator-from-a-context-menu/



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Calling parser/generator programmatically [message #1220429 is a reply to message #1220275] Wed, 11 December 2013 17:13 Go to previous messageGo to next message
Leandro Marques is currently offline Leandro MarquesFriend
Messages: 11
Registered: July 2009
Junior Member
I think it might work. Thanks
Re: Calling parser/generator programmatically [message #1721234 is a reply to message #1220429] Tue, 26 January 2016 04:43 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
Hi ,

I would like to ask this question again as the answers might be updated.?

Thanks In Advance
Re: Calling parser/generator programmatically [message #1721272 is a reply to message #1721234] Tue, 26 January 2016 09:05 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
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

Previous Topic:Problems with code generator
Next Topic:Splitting a model into several files? Scoping?
Goto Forum:
  


Current Time: Thu Mar 28 14:55:09 GMT 2024

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

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

Back to the top