|
|
Re: Xtext standalone application beginner tutorial [message #901104 is a reply to message #900859] |
Thu, 09 August 2012 19:43 |
Alfredo Motta Messages: 41 Registered: June 2012 |
Member |
|
|
Thank you Christian, I was able to solve the problem and this is the guide step by step for the next one interested
1- Create your sample grammar in Xtext with the 5 minute tutorial (Cattura.png)
2- Create a run configuration for the project (Cattura1.png)
3- Export the project as a runnable jar in the lib folder of your standalone project (Cattura2.png+Cattura3.png)
4- I got warnings and incomprehensible stuffs, but it works even with them (Cattura4.png)
5- Add the jar to your standalone project (Cattura5.png)
6- Run with the code from the XText FAQ and check your greeting
new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("../");
Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resourceSet.createResource(URI.createURI("file:/example.mydsl"));
InputStream in = new ByteArrayInputStream("Hello World".getBytes());
resource.load(in, resourceSet.getLoadOptions());
Model model = (Model) resource.getContents().get(0);
for(Greeting e:model.getGreetings()){
System.out.println(e);
}
IMPORTANT: The extension in this line
Resource resource = resourceSet.createResource(URI.createURI("file:/example.mydsl"));
should be the same of the mwe2 workflow in the grammar project
var file.extensions = "mydsl"
Cheers
-
Attachment: Cattura.PNG
(Size: 131.57KB, Downloaded 663 times) -
Attachment: Cattura1.PNG
(Size: 183.55KB, Downloaded 701 times) -
Attachment: Cattura2.PNG
(Size: 178.97KB, Downloaded 564 times) -
Attachment: Cattura4.PNG
(Size: 213.19KB, Downloaded 597 times) -
Attachment: Cattura5.PNG
(Size: 176.46KB, Downloaded 564 times)
|
|
|
Powered by
FUDForum. Page generated in 0.03604 seconds