Implementing Domain-Specific Languages with Xtext and Xtend

Starting

Lorenzo BettiniAugust 2013

If you know Eclipse then learning how to implement a DSL using Xtext is a natural progression. And this guide makes it easy to get started through a step-by-step approach accompanied with simple examples.

$29.99

$49.99

RRP $29.99

RRP $49.99

eBook

Print + eBook

Want this title & more?

$16.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781782160304

Paperback342 pages

About This Book

Learn to quickly develop a domain-specific language with Xtext Implement any aspect of a DSL using Xtend, a fully featured Java-like programming language Discover how to test a DSL implementation and how to customize runtime and IDE aspects of the DSL

Who This Book Is For

This book is for programmers who want to learn about Xtext and how to use it to implement a DSL (or a programming language) together with Eclipse IDE tooling. It assumes that the user is familiar with Eclipse and its functionality. Existing basic knowledge of a compiler implementation would be useful, though not strictly required, since the book will explain all the stages of the development of a DSL.

Table of Contents

Chapter 1: Implementing a DSL

Domain Specific Languages

Implementing a DSL

IDE integration

Enter Xtext

The aim of this book

Summary

Chapter 2: Creating Your First Xtext Language

A DSL for entities

The Xtext generator

The Eclipse Modeling Framework (EMF)

Improvements to the DSL

Summary

Chapter 3: The Xtend Programming Language

An introduction to Xtend

Xtend – a better Java with less "noise"

Debugging Xtend code

Summary

Chapter 4: Validation

Validation in Xtext

Quickfixes

Summary

Chapter 5: Code Generation

Introduction to code generation

Writing a code generator in Xtend

Integration with the Eclipse build mechanism

Standalone command-line compiler

Summary

Chapter 6: Customizations

Dependency injection

Google Guice in Xtext

Customizations of IDE concepts

Custom formatting

Other customizations

Summary

Chapter 7: Testing

Introduction to testing

Junit 4

The ISetup interface

Implementing tests for your DSL

Test suite

Testing the UI

Testing and modularity

Clean code

Summary

Chapter 8: An Expression Language

The Expressions DSL

The grammar for the Expressions DSL

Left recursive grammars

Forward references

Typing expressions

Writing an interpreter

Summary

Chapter 9: Type Checking

SmallJava

First validation rules

Type checking

Improving the UI

Summary

Chapter 10: Scoping

Cross-reference resolution in Xtext

Custom scoping

Global scoping

Providing a library

Dealing with super

What to put in the index?

Additional automatic features

Summary

Chapter 11: Building and Releasing

Release engineering

Introduction to Buckminster

Using the Xtext Buckminster wizard

Maintaining the examples of this book

Summary

Chapter 12: Xbase

Getting introduced with Xbase

The Expressions DSL with Xbase

The Entities DSL with Xbase

Customizations

Summary

Chapter 13: Bibliography

What You Will Learn

Learn to write an Xtext grammar for a DSL Use Xtend as an alternative to Java to write cleaner, easier-to-read, and more maintainable code Write constraint checks for a DSL using the validator mechanism Learn how to write a code generator and an interpreter for a DSL Discover how automatic symbol resolution works in Xtext and how to customize it Build and deploy a DSL implementation so that others can install it Get well versed with the typical Xtext development workflow

In Detail

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.

Authors

Lorenzo Bettini

Lorenzo Bettini is an assistant professor (Researcher) in computer science at Dipartimento di Informatica, Università di Torino, Italy. Previously, he was a Postdoc and a contractual researcher at Dipartimento di Sistemi e Informatica, Università di Firenze, Italy.
He has a Masters Degree in computer science and a PhD in theoretical computer science.
His research interests cover design, theory, and the implementation of programming languages (in particular, object-oriented languages and network-aware languages).
He has been using Xtext since version 0.7. He has used Xtext and Xtend for implementing many Domain Specific Languages and Java-like programming languages.
He is also the author of about 60 papers published in international conferences and international journals.
You can contact him at http://www.lorenzobettini.it.

Alerts & Offers

Series & Level

We understand your time is important. Uniquely amongst the major publishers, we seek to develop and publish the broadest range of learning and information products on each technology. Every Packt product delivers a specific learning pathway, broadly defined by the Series type. This structured approach enables you to select the pathway which best suits your knowledge level, learning style and task objectives.

Learning

As a new user, these step-by-step tutorial guides will give you all the practical skills necessary to become competent and efficient.

Beginner's Guide

Friendly, informal tutorials that provide a practical introduction using examples, activities, and challenges.

Essentials

Fast paced, concentrated introductions showing the quickest way to put the tool to work in the real world.

Cookbook

A collection of practical self-contained recipes that all users of the technology will find useful for building more powerful and reliable systems.

Blueprints

Guides you through the most common types of project you'll encounter, giving you end-to-end guidance on how to build your specific solution quickly and reliably.

Mastering

Take your skills to the next level with advanced tutorials that will give you confidence to master the tool's most powerful features.

Starting

Accessible to readers adopting the topic, these titles get you into the tool or technology so that you can become an effective user.

Progressing

Building on core skills you already have, these titles share solutions and expertise so you become a highly productive power user.