URLs in Xtext

DSLs often include URLs. However, Ecore does not provide such a datatype by default. Also Xtext doesn’t provide a native rule for entering URLs as it is available for strings or integers.

In this post, I will explain all the nescessary steps to use URLs in Ecore models and in Xtext-based DSLs.
Continue reading

Generate Proxies for the WPF frontend

In the previous post we learned how a WPF user interface can be driven from a java application. The solution that was presented allows showing views, modifying controls’ properties, and starting or stopping animations. It is based on a set of generic functions that provide for the required functionality. Each one of these takes additional parameters to adress a specific view, control, animation, and property.

Assuming there is a control named mute in the view main. To set its boolean property checked to true, we need to call wpfFrontend.setWidgetPropertyBool("main", "mute", "checked", true). This call will fail, when the view, the control, or the property is not found for the given names, which can likely happen because of mispelling or after refactoring the user interface. Such errors cannot be detected by the Java compiler and will lead to runtime errors that are hard to detect. One can use proxies that encapsulate all the adressing in order to avoid these problems and offer a more convenient way to access the elements of the WPF frontend. Using proxies the modification of the control’s property can be done by a call to a setter, e.g. wpfFrontend.main.mute.setChecked(true).

This post shows how such Java proxies can be generated from a high-level description of the frontend elements.
Continue reading

Remote Control a WPF Frontend from Java

Windows Presentation Foundation is a powerful framework for building rich user interfaces that comes with great GUI builders. However, for creating the application logic WPF requires to use one of one of the .NET programming languages such as Visual Basic or C#. Java, also a great programming language for writing application logic, is not supported.

This post describes how to connect a an application written in Java to a WPF based user interface.

The solution uses socket communication, allowing to separate the user interface and its computation logic into different processes or programs. This can be necessary, if they are implemented in different programming languages. Furthermore, it allows to run frontend and backend on different machines or processors.
Continue reading

Add Deprecated Annotations and Task Tags to your DSL

Some programming languages allow to discourage the usage of program element. For this purpose, Java provides the annotation @deprecated. It can be added to classes, fields and methods to express that the element should not be used any longer. There are many possible reasons, e.g., the element is unsafe or it has been superseded and may cease to exist in the future. When a deprecated element is used the compilers shows a warning. The Eclipse IDE marks all calls to deprecated methods and accesses to deprecated classes or fields.

Java developers using Eclipse JDT are probably also familiar to the task tags //XXX, //TODO and //FIXME. They offer a convenient way to mark positions in the source code that should be remembered for later reviews or adaptions. Eclipse lists all task tags found in the source code in a special view. By double clicking the entry in this view the IDE jumps to the corresponding position in the source code.

Both, the task tags and the deprecated-annotation are useful tools when creating Java programs in Eclipse. When working with large scale textual models, they can be beneficial, too. Xtext, however, does not provide such a feature out of the box. Though, it can be built with little effort by means of its validation framework.

This post describes how this can be done in such a way that it can be attached to different model elements with little effort.
Continue reading

Xtext based Lua-Editor

Lua is an imperative programming language. It was designed to be embedded as programming language within other programs. Lua uses automatic memory management with garbage collection. It is dynamically typed and provides coroutines. The Lua interpreter has a low memory footprint and is even suitable for embedded systems.

Lua uses a very simple grammar with specialized list operations. The complete symtax can be found here.

In this post we use Xtext to develop an IDE for this real-world programming language.
Continue reading

Generate EBNF-Descriptions for Xtext-based DSL

Creating DSLs in Xtext is easy and works out of the box. However, when it comes to documentation,  things get tricky. Your DSL should be used by other programmers to model a system that maybe didn’t take part in defining the language. So how can you describe the usage of your language to these guys?

Of course there is the possibility to provide code-snippets as examples and the tool support Xtext generated for your languages eases its use. However, sometimes a more complete documentation is useful. Using the original .xtext file for that purpose is not the best way, because its crowded with internal information for the parser that the user of the DSLs doesn’t care about. Furthermore, only few people are used to the Xtext-Language. The good old way is to provide a BNF or EBNF description of the language.

In this posts I will describe how to automatically generate EBNF descriptions for your DSL.
Continue reading