The Entities DSL with Xbase
We will now implement a modified version of the Entities DSL that we implemented in Chapter 2, Creating Your First Xtext Language. This will allow us to implement a more complex DSL where, inside entities, we can also write operations apart from attributes. This is inspired by the Xtext Domain-Model example.
Creating the project
We create a new Xtext project with the following settings:
- Project name:
org.example.xbase.entities
- Name:
org.example.xbase.entities.Entities
- Extensions:
xentities
Defining attributes
We define the rules for attributes using some rules inherited from the Xbase grammar:
grammar org.example.xbase.entities.Entities with org.eclipse.xtext.xbase.Xbase generate entities "http://www.example.org/xbase/entities/Entities" Model: entities+=Entity*; Entity: 'entity' name=ID ('extends' superType=JvmParameterizedTypeReference)? '{' attributes += Attribute* '}'; Attribute: 'attr' (type...