Posts Tagged ‘ DSL ’

Semantic typing in domain-specific languages

In domain-specific languages (DSL) concepts of the targeted problem-domain are introduced as language constructs. This is done in order to model using these concepts and abstract from specific technical solutions. However, a static typing of the DSL is useful, especially when it is used to calculate values. In DSLs the typesystem can be designed individually just as all the provided language constructs. For this reason, the data types shouldn’t be introduced because of technical differences but because of their semantics in the problem domain. Such semantic type systems and a static typing of a DSLs can prevent semantic errors during modeling by checking for type incompatibilities. This article discusses the idea of semantic typing and shows a concrete implementation in a DSL for creating user interfaces.

Continue reading

Generate graphical Visualizations for textual DSLs

The advantage of using a textual notation for models is that no special editors are required to create and edit these models. Furthermore, the models can also be diffed and merged using standard tools. Such textual notations are particularly suitable for expert tools. Graphical notation, on the other hand, illustrate complex relations and are often easier to understand. The combination of both notations makes optimum use of their particular benefits.

In this post I will demonstrate how we can achieve this goal by enhancing the textual Xtext editors with graphical visualizations. The visualization will be shown in a view within the Eclipse IDE. Thus, we will use the SWT-based Zest toolkit for rendering.

Continue reading

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

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