Book Image

Implementing Domain-Specific Languages with Xtext and Xtend

By : Lorenzo Bettini
Book Image

Implementing Domain-Specific Languages with Xtext and Xtend

By: Lorenzo Bettini

Overview of this book

Xtext is an open source Eclipse framework for implementing domain-specific languages together with its IDE functionalities. It lets you implement languages really quickly, and, most of all, it covers all aspects of a complete language infrastructure, starting from the parser, code generator, interpreter, and more. "Implementing Domain-Specific Languages with Xtext and Xtend" will teach you how to develop a DSL with Xtext, an Eclipse framework for implementing domain-specific languages. The chapters are like tutorials that describe the main concepts of Xtext such as grammar definition, validation, code generation, customizations, and many more, through uncomplicated and easy-to-understand examples. Starting with briefly covering the features of Xtext that are involved in a DSL implementation, including integration in an IDE, the book will then introduce you to Xtend as this language will be used in all the examples throughout the book. We then proceed by explaining the main concepts of Xtext, such as validation, code generation, and customizations of runtime and UI aspects. By the end of the book, you will have learned how to test a DSL implemented in Xtext with Junit, in order to follow a test-driven development strategy that will help the developer implement maintainable code that is much faster and cleaner. A test-driven approach is used throughout the book when presenting advanced concepts such as type checking and scoping. The book also shows you how to build and release a DSL so that it can be installed in Eclipse, and gives you hints on how to build the DSL headlessly in a continuous integration server. "Implementing Domain-Specific Languages with Xtext and Xtend" aims to complement the official Xtext documentation to explain the main concepts through simplified examples and to teach the best practices for a DSL implementation in Xtext. It is a Beginner's Guide which should set you up for professional development DSL and its Eclipse IDE tooling.
Table of Contents (21 chapters)
Implementing Domain-Specific Languages with Xtext and Xtend
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
13
Bibliography
Index

Using the Xtext Buckminster wizard


In this chapter we will use a brand new example DSL project to demonstrate the building and releasing mechanisms (of course, the same mechanisms can be applied to an existing DSL as well):

  1. Go to File | New | Project..., in the dialog, navigate to the Xtext category and select Xtext Project.

  2. In the next dialog you should specify the following names:

    • Project name: org.example.build.hello

    • Name: org.example.build.hello.Hello

    • Extensions: hello

    • Check the option Create SDK feature project (this option must be checked for this example to work)

The wizard will create four projects in the workspace and it will open the file Hello.xtext.

We will use this example only for building and releasing, thus, we are not interested in the DSL itself; we can simply leave the default grammar as it is. However, make sure to run the MWE2 workflow at least once, so that all the Xtext artifacts are generated.

We add a Junit Xtend test class, HelloParserTest, in the org.example.build...