Chapter 5. Code Generation

In this chapter you will learn how to write a code generator for your Xtext DSL using the Xtend programming language. Using the Entities DSL that we developed in the previous chapters, we will write a code generator which, for each entity declaration, will generate the corresponding Java class. We will also see how the code generator is automatically integrated by Xtext into the Eclipse builder infrastructure. Finally, the DSL implementation can be exported as a Java standalone command-line compiler.

Introduction to code generation

After a program written in your DSL has been parsed and validated, you might want to do something with the parsed EMF model, that is, the AST of that program. Typically, you may want to generate ...

Get Implementing Domain-Specific Languages with Xtext and Xtend now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.