Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Parse DSL instances into Resource without Eclipse application
Parse DSL instances into Resource without Eclipse application [message #1730669] Wed, 27 April 2016 14:25 Go to next message
Sina Madani is currently offline Sina MadaniFriend
Messages: 109
Registered: November 2015
Location: York, UK
Senior Member
I have defined a grammar for my language. The documentation for Xtext tries to restrict you to the Eclipse/Xtext/Xtend framework. What I'd like to do is "take home" the generated code and basically use it as a stand-alone parser. I don't want to use Xtend or depend on an instance of Eclipse with an editor etc. I just want to create a stand-alone Java program (using the Java programming language, not Xtend) as a command-line compiler which takes as input a file which uses the grammar (e.g. with extension ".mydsl") and generates some code. How this generation is done is not relevant and completely independent of the Xtext/Xtend framework.
I am unable to figure out how to use the generated code to do this. I presume there is a method somewhere in the generated code which takes as input the file and then creates the XtextResource object(s). I want to get the Resource object (i.e. the one that is passed into the "doGenerate" method of MyDslGenerator.xtend). Any ideas how I can go about this? Thanks Smile
Re: Parse DSL instances into Resource without Eclipse application [message #1730673 is a reply to message #1730669] Wed, 27 April 2016 14:46 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13204
Registered: July 2009
Senior Member
Hi,

have a look at

https://wiki.eclipse.org/Xtext/FAQ#How_do_I_load_my_model_in_a_standalone_Java_application.C2.A0.3F


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Parse DSL instances into Resource without Eclipse application [message #1730677 is a reply to message #1730673] Wed, 27 April 2016 15:11 Go to previous messageGo to next message
Sina Madani is currently offline Sina MadaniFriend
Messages: 109
Registered: November 2015
Location: York, UK
Senior Member
Thanks Christian. I can't believe I missed that in the FAQ.

However, I am still unsure how this can be used. Suppose that I wanted to make a new project. What files/packages do I need in order to make it work outside of the Xtext project?
Re: Parse DSL instances into Resource without Eclipse application [message #1730680 is a reply to message #1730677] Wed, 27 April 2016 15:14 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13204
Registered: July 2009
Senior Member
all you need is in the your.dsl (the runtime project). if you create a java main there and run it once you can use the export -> java application wizard.

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Parse DSL instances into Resource without Eclipse application [message #1730684 is a reply to message #1730680] Wed, 27 April 2016 15:58 Go to previous messageGo to next message
Sina Madani is currently offline Sina MadaniFriend
Messages: 109
Registered: November 2015
Location: York, UK
Senior Member
OK thank you so much!

I'm encountering a slight issue with the Injector. I presume this is the org.eclipse.emf.mwe.internal.core.ast.util.Injector and not the com.google.Injector. But for some reason I get an error "The method getInstance(Class<XtextResourceSet>) is undefined for the type Injector". I also get a warning "Discouraged access: The type 'Injector' is not API (restriction on required library 'C:\Program Files\Eclipse\plugins\org.eclipse.emf.mwe.core_1.3.13.v201512160556.jar')".

                Injector injector = (Injector) new IDLStandaloneSetup().createInjectorAndDoEMFRegistration();
		XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
		resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, true);


EDIT: Never mind, I looked at the method and it's using Google Guice so it is the Google Injector I need.

[Updated on: Wed, 27 April 2016 16:03]

Report message to a moderator

Re: Parse DSL instances into Resource without Eclipse application [message #1730685 is a reply to message #1730684] Wed, 27 April 2016 16:04 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13204
Registered: July 2009
Senior Member
No com.google.inject

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Parse DSL instances into Resource without Eclipse application [message #1730686 is a reply to message #1730685] Wed, 27 April 2016 16:09 Go to previous message
Sina Madani is currently offline Sina MadaniFriend
Messages: 109
Registered: November 2015
Location: York, UK
Senior Member
Thanks for the help. Much appreciated.
Previous Topic:Altering/Restricting Xtext DSL Entry and Exit Rule
Next Topic:Xtext project build with Maven Tycho
Goto Forum:
  


Current Time: Tue Nov 19 13:31:58 GMT 2019

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

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

Back to the top