Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

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" 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 the gr1600 with your groups nrto correspond to your group number).
 The location is were your project is located, and the "xtext" in the end makes sure that everything ends up in a cute folder named xtext.at the end will be the name of a folder containing all the generated Xtext projects. After naming everything correctly you press next.

Image Added

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. 

Image Added

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

Image Added

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>:

Image Added

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.

Image Added

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

Image Added

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:

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

The file should now look like this:

Image Added

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!

 Image Removed