Channels ▼
RSS

Open Source

Project of the Month: Xtext DSL Framework


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.

Figure 2: Xtext-based Eclipse editor.


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.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video