How to Integrate Xtext into other projects [message #1771522] |
Sat, 26 August 2017 12:11  |
Eclipse User |
|
|
|
Hello,
is there a recommended way to integrate a language written in Xtext into another project?
For example: I want to write a JavaFX application an within this application the user should be able to write his programm into the UI, the UI should then be read by the JavaFX application and the text transfered to Xtext so that Xtext generates code.
A possible solution would be to "manually" (JavaFX-Application writes and saves) write into the eclipse IDE and save to invoke the generator of the Xtext-framework. This would obviously be very bad.
Basically: Is it possible to manually call the scanner, parser etc. of a certain Xtext project with another Java-app?
Greetings,
Robert
|
|
|
|
|
|
|
|
|
Re: How to Integrate Xtext into other projects [message #1772117 is a reply to message #1772057] |
Tue, 05 September 2017 13:03   |
Eclipse User |
|
|
|
The file extension should be correct.
I am not exporting anything manually yet. Should I?
I am not sure If I really understood on how to import the language the right way.
I ve used Properties - Java Build Path and added under project the org.xtext.toolLanguage and under libraries the 5 .jars mentioned in the other post. Am I missing something?
The platform resource: I am working in one Eclipse workspace with the Xtext-Project and another Java-Project. Should this work or am I missing here something? :)
___________________________________________________
I have another question though and don´t want to make a new topic out of it: Is the xtext-File written Xtext? So is there a grammar for the file extension "xtext" and if so, is it public?
___________________________________________________
EDIT: I somehow fixed it, I am not sure how, but it works. Maybe the file could not get parsed properly with the grammar, I am not sure though. Sadly I was not really able to understand the exceptions I got :)
The code now:
//imports
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.xtext.ToolLanguageStandaloneSetup;
import org.xtext.toolLanguage.Model;
import org.xtext.toolLanguage.ToolLanguagePackage;
//these would be the imports for the default dsl
//import org.xtext.example.mydsl.MyDslStandaloneSetup;
//import org.xtext.example.mydsl.myDsl.Model;
//import org.xtext.toolLanguage.Model;
import com.google.inject.Injector;
//main-Code
Injector injector = new ToolLanguageStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resourceSet.getResource(URI.createFileURI("./example.toolLanguage"), true);
Model model = (Model) resource.getContents().get(0);
System.out.println(model.getRules());
I manually added under properties - Java Build Path:
Projects: The xtext Project needed
Libraries:
com.google.inject_3.0.0...
org.eclipse.emf.common_2.12.0...
org.eclipse.emf.ecore_2.12.0...
org.eclipse.xtext_2.11.0...
You should find some of these jars referenced in the Xtext-Project too :)
Though you might want to consider using some build-tool or something :D
___________________________________
Again thank you very much for your help, specially thank you Christian Dietrich, you helped me a lot so far :)
[Updated on: Tue, 05 September 2017 13:30] by Moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06401 seconds