You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Guide for setting up xtext in your project.

It is important to get the setup right, so that everyone get the same structure on their projects.

1. Creating a new Xtext Project:

Create a new Xtext project by right clicking your project and select New > Other... (or just Ctrl+N), then select "Xtext Project" as show in the image below.

 

2. Correct name and location:

Name the project as show below (change gr1600 to correspond to your group number). The location is were your project is located, and "xtext" at the end will be the name of a folder containing all the generated Xtext projects. After naming everything correctly you press next.

In the next step you can select details of what the wizard will generate, including the build system it targets. You should only need to set the Preferred Build System to Maven. 

After pressing Finish, the Xtext projects will be generated and should appear in the Project Explorer, as shown below.

4. Using Xtext

The most important files are the Xtext grammar (.xtext) and the so-called Workflow file (.mwe2). The grammar describes you DSL syntax, and the workflow is used to generate the parser and editor code based on the grammar. You'll find both these in the tdt4250.gr16xx.xtext project, in the tdt4250.gr16xx.xtext package/folder.

To be able to refer to and use the osm project and model, you'll need to add some information in the Xtext grammar, the workflow and the project dependencies (in MANIFEST.MF).

The Xtext grammar file needs an import, so you can refer to osm types with osm::<type from the ism model>:

The workflow file similarly needs to know of your osm genmodel, so it can generate code that properly refers to osm code. Add the line referencedResource = "platform:/resource/no.hal.pgo.osm/model/osm.genmodel to the GenerateXGr16xx.mwe2 file, as shown in the image below.

You also need to add two dependencies in the MANIFEST.MF inside the Xtext project (see image below).  

Now you can right-click on the GenerateXGr16xx.mwe2 class and Run as > MWE2 Workflow. After this, you'll find a lot of code has been generated, in several of the Xtext-related projects. One of these have to be edited, to be able to reference locations in osm files. Located the file XGr16xxStandaloneSetup.xtend file and add the following code:

override Injector createInjectorAndDoEMFRegistration() {
	OsmSupportStandaloneSetup.setup();
	return super.createInjectorAndDoEMFRegistration;
}

The file should now look like this:

This should be enough for getting startet with developing a proper grammar for your DSL syntax. And remember to re-run the mwe2 workflow file whenever you've changed the grammar and want to test the result.

Good luck!

 

  • No labels