A DSL for entities
We will now implement a simple DSL to model entities, which can be seen as simple Java classes. Each entity can have a super type entity (you can think of it as a Java superclass) and some attributes (similar to Java fields). This example is a variant of the domain model example that can be found in the Xtext documentation.
Creating the project
First of all, we will use the Xtext project wizard to create the projects for our DSL. We have already experimented with this at the end of Chapter 1, Implementing a DSL.
- Start Eclipse and navigate to File | New | Project.... In the dialog, navigate to the Xtext category and select Xtext Project.
- In the next dialog, you should specify the following names:
- Project name:
org.example.entities
- Name:
org.example.entities.Entities
- Extensions:
entities
- Project name:
- Press Finish.
The wizard will create several projects and it will open the file Entities.xtext
, which is the grammar definition.
The main dialog of the wizard is shown in the following screenshot...