Xtext Domain Model Example
Example domain model dsl with comments.
Xtext domain model example. But in xtext the grammar also describes how the parser should instantiate a model from the text. These lessons are independent from each other. For example to model a database the domain model would define concepts such as. Table and column with.
As an example the behaviour of the the formatters from our projects and the one from domain model example org eclipse xtext example domainmodel for the indentation of comments was identical. Xtext 1 0 2 1 6. Writing a code generator with xtend. Such a domain can be more or less anything.
Five simple steps to your jvm language. This kind of language is really a sweet spot for dsls so feel free to use this as a blueprint and add your project specific features later on. Visualizing the xtext domain model example the xtext domain model example describes a language that. As a small exercise you could implement support for the many attribute of a feature or enforce naming conventions e g.
Where a traditional parser creates a generic syntax tree an xtext parser will create a strictly typed emf model. Simply choose new example xtend examples xtend introductory examples and have a look at the features of xtend. The tutorial shows how to create the entity dsl we used in the example above. They are extended by model to text transformations to generate intermediate graphviz dot files as inputs for the gef dot graph view.
What is a domain specific language a domain specific language dsl is a small programming language which focuses on a particular domain. In this tutorial we will basically implement the domain model language again but this time we will make use of the special jvm support shipped with xtext. As soon as you generate the xtext artifacts for a grammar a code generator stub is put into the runtime project of your language. Each of them will be based on the language that was built in the first domain model tutorial.
We re going to enhance the grammar first so open up the domainmodel xtext file ctrl cmd shift r open resource is quite helpful for finding non java files navigate to the end of the file. The following examples are shipped with the xtext framework and are available from the xtext example wizard. Generated field names should start with an underscore. The example project provides a good overview of the potential use of test driven development when creating a dsl.
The idea is that its concepts and notation is as close as possible to what you have in mind when you think about a solution in that domain. The value returned by the call to id is assigned to the feature name. Hence providing below an example dsl with comments from the domain model example so that its easy to relate to it.