Language-Specific Enhancements
Modern IDEs for general-purpose programming do a very good job at error detection. This is especially true for statically typed languages, where many mistakes developers might make, are found as they type. There are type checks to ensure that expressions are compatible, and data flow analysis to detect null pointer exceptions. Xtext provides a convenient means to define these kinds of validation rules, too. A validation rule that ensures that the resetting events are not conflicting with the valid transitions of a state is only a matter of a single line of code. The detected issues will be displayed right in your editor in exactly the same way problems in Java files are reported. Xtext will underline the parts of the file that are erroneous, and you get the opportunity to fix them immediately. You can even go a step further and provide quick fixes for any issue that you detect. Because DSL-specific validation rules are executed as you type, your users get important feedback and guidance as soon as possible. Validation is also performed when the parser is used at the command line.
Another way to guide your users is with content assist. The workflow for many developers is often heavily based on smart content proposals, and for good reason. IDEs allow you to write new methods with a couple of keystrokes, and they offer suitable proposals at any given point in the source code. Xtext automatically suggests valid proposals based on the lexical structure of the DSL. Additionally, the scoping and linking rules are taken into account to provide suggestions for cross references. Writing code in an Xtext-based language is facilitated by the guidance that users receive from the editor. You can even define template proposals to create complete structures with a single keystroke. Template proposals can contain placeholders that will be populated by the framework, which allows the selection of valid values from drop down lists and the like. These advanced IDE features are based on the fact that the editor is aware of the grammar definition and the currently edited semantic model, which allows it to derive a great deal of helpful information; see Figure 2.
Extensibility
Validation and content assist are just two of many aspects you might want to specifically tailor for your DLS. Actually, with Xtext, there is no functionality that cannot be extended or replaced by your own implementation because the framework makes extensive use of dependency injection using Google Guice. This design allows for easy customization because nothing is hard-wired deep down in some internal implementation class. Even with this great flexibility, the defaults should not be underestimated. They address the most common use cases and are based on common language design patterns.
Have Fun!
There is much more to Xtext, including the ability to integrate with Java code and the reusable statically typed expression language that can be embedded arbitrarily within your DSL but these fall beyond the scope of this introduction. Beginning next month, we'll present a series of tutorials on using Xtext on Dr. Dobb's. Until then, go try it out at the main Xtext site. There, you'll see that Xtext is open source, documented in detail, and fun to use.
Sven Efftinge is the Lead on the Xtext project. Sebastian Zarnekow is a Committer.



