Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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 at the end makes sure that everything ends up in a cute folder named xtext.
After will be the name of a folder containing all the generated Xtext projects. After naming everything correctly you press next.

 

In the next window you only need to do one thing, you 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.
You do not need to change anything else than the "Preferred Build System" drop down.
After changing Preferred Build System you can press Finish. 

Image Removed

 

3. End result

 

Image Added

After pressing Finish, the Xtext projects will be generated and should appear in the Project Explorer, as shown Your project structure should now look like the image below.

 

4. Using Xtext

Adding osm:

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 If you want to use osm with Xtext your starting point should be the "GenerateXGr16xx.mwe2" file where you need to 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 your xtext folder the Xtext project (see image below).  

To use osm in your xtext editor you need to import it as shown below.

Image Removed

Now you have to can right-click on the GenerateXGr16xx.mwe2 class and Run as –> 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 add this into the to be edited, to be able to reference locations in osm files. Located the file XGr16xxStandaloneSetup.xtend file (see picture): and add the following code:

Code Block
override Injector createInjectorAndDoEMFRegistration() {

...


	OsmSupportStandaloneSetup.setup();

...


	return super.createInjectorAndDoEMFRegistration;

...

Image Removed

The last thing you now have to do is to import the org.eclipse.emf.mwe.utils.StandaloneSetup inside the GenerateXGr16xx.mwe2 file.

...


}

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!