Why Xtext

Method and tools news

Why using a framework like Xtext

When it comes to domain-specific languages, one might ask why bother with a framework like Xtext, when you also can simply use a parser generator like ANTLR or yacc/bison directly.

A parser is not enough

From a pure technical point of view simply writing (or generating) a parser works wonderful for exactly that. Parsing your domain-specific language and constructing an abstract syntax tree for it. The users can then write the DSL files in their favourite (text) editor and then let the tool process the files. But if the user is a programmer used to modern IDEs like Eclipse, IntelliJ IDEA or Microsoft’s VSCode or more of a business person, that might not be enough. Users like the early feedback on syntactic and semantic errors a powerful tool offers, getting assistance like content assist or quickfixes on errors or the possibility to navigate the code/model from the editor. Same holds true for other editor features like syntax highlighting and (rename) refactorings or code generation.

Building everything from scratch is hard

Modern IDEs and Editors like VSCode offer tool specific APIs or even a generic way like the language server protocol that allow to build features as listed above. But these APIs are often very low-level and hard to implement. Doing so from scratch is quite tedious and error prone, which drives the costs to build domain specific languages even higher. Why not just defining the language and letting the editor do its thing.

Code generation comes to the rescue

Here is where Xtext comes into play. Given a grammar Xtext generates the complete infrastructure needed to offer a complete and feature-rich tooling for your domain-specific languages with good defaults and still easily customizable in all aspects using dependency injection through well defined extension points.

What Xtext can offer

Xtext offers support for Eclipse as well as for all editors and tools that support the language server protocol like VSCode or IntelliJ IDEA (via 3rd party plugins) and the possibilty to run in the web via servlet.

Getting started

If you want to give Xtext a try just head over to the projects website. Here you can find instructions on how to download as well as the documentation with a tutorial. If you prefer reading books then Implementing Domain-Specific-Languages with Xtext and Xtend - Second Edition by Lorenzo Bettini will be a good choice.


Xtext is a great choice to develop textual domain-specific languages with powerfull tool support for your platform of choice.