The core idea behind the shiny new generator are so called generator fragments. They allow to contribute entries to various places during the generation process. It is possible to add extensions to the plugin.xml, declare exported packages for the MANIFEST.MF or list guice bindings. Furthermore and properly most important: generator fragments provide a mighty mechanism to create any kind of output files utilizing the Xpand template language.
Because the interface of fragments has been designed to be composable, it is easily possible to implement reusable components. Xtext itself ships with a neat set of default and often required fragments.
- The generated grammar access provides strongly typed accessors for the various elements of your concrete syntax such as alternatives, assignments, cross references and keywords.
- The Xtext parser that is responsable for reading text and instantiating a model. You'll get optionally an ANLTR-Parser, too.
- A serializer, that is capable to transform the semantic model into its native textual form.
- Xtext comes with a fragment, that creates a Check based validation stub. It allows to implement constraints for model instances declarativly. As there exists another fragment for java based validation, it is possible to use both and combine the expressivness of Check with the performance boost of native Java code for expensive validation.
- A Java API for content assist is generated for the editor of your DSL. You can even choose to use an Xtend based API.
- You'll get a custom EMF resource factory, that will create and configure your Xtext resources.
- And the fragment that covers functionality that has not been in Xtext before, will generate Java classes for the infered metamodels. It uses EMF GenModels to output their corresponding Java API. Working with your semantic model is far more comfortable when there is no nead to deal with dynamic EMF models.
If someone has special needs for his language generation, he can implement a generator fragment that serves his very own interests well. Is your solution matching potential requirements of other parties, too? We will be happy to accept patches with reusable, customizable fragments to be packaged with Xtext.
No comments:
Post a Comment