Eclipse Langium is an open source framework for designing and implementing text-based formal languages, especially domain-specific languages (DSLs). The project was initiated by TypeFox in 2021 and established as an Eclipse Foundation project in 2023.
Eclipse Langium offers a unique combination of expressiveness in terms of text parsing ability, processing infrastructure with built-in cross-referencing, and integration with today’s most relevant web-based tools and IDEs.
Another open source language toolbox the TypeFox founders created in 2008, Eclipse Xtext, has evolved into the de-facto standard for implementing DSLs within the larger Eclipse community. But Langium offers several advantages over Xtext that, in my opinion, make Langium the future of DSL design and implementation, especially in the context of web-based development tools.
This article highlights the most valuable benefits of Langium and how it fits into the larger ecosystem of web-based development tools.
Create Domain-Specific Languages With Langium
Langium provides a text parser with integrated cross-reference resolution and a language server for smart editor support. You can use Langium to build custom text languages that can be automatically processed. For example, you can execute user-defined behaviour with an interpreter, or generate executable code, documentation, or other output formats. Such a custom language can:
- Empower non-technical persons to provide data, logical constraints, executable behaviour, or similar concepts
- Greatly reduce the manual effort to create artefacts such as source code or documentation
- Strengthen the communication between stakeholders with a formal language
A DSL can be employed as an internal tool to improve the efficiency of your processes. Similarly to a low-code platform, you can capture information in a custom-tailored and structured manner for automatic distribution and processing. The difference is that a DSL uses plain text, so it does not depend on specific solutions from low-code vendors. With plain text you can copy-paste contents, send them via email, control the version history with Git or other SCMs, and much more.
There are always two aspects to working with a DSL: how users write and navigate the DSL text (the language frontend) and how the text is processed to create additional value (the language backend). Langium supports both these aspects. The frontend is covered with the Language Server Protocol (LSP), which makes it easy to integrate with popular text editors and IDEs, such as Visual Studio Code, Eclipse Platform, and others. The backend is based on an abstract representation of the DSL contents, called the Abstract Syntax Tree (AST). Adopters of Langium can use the provided ASTs to generate different artefacts or execute certain behaviour.
Figure 1: An example DSL specifying application requirements and tests in multiple text files.
Langium Brings Xtext’s Strengths Into a More Approachable Framework
Numerous companies from various types of industries have successfully adopted Xtext over the years. However, Xtext has some major drawbacks from today’s perspective:
- Xtext is based on Java, so there is a technological gap towards more modern web-compatible tool platforms that are based on TypeScript.
- Xtext is unnecessarily complicated in some regards. Its integration with the Eclipse Modeling Framework (EMF) can be good for interoperability with other Eclipse-based modeling tools but is usually not required.
- The Xtext project has numerous components with multiple layers of abstraction, making it very difficult for potential contributors to get acquainted with the framework code and its integrations. This is one of the reasons why the number of contributors to the project has dropped in recent years.
Eclipse Langium was built from the ground up with the explicit goal to keep the ideas and concepts that made Xtext great, while also improving on it. These concepts include the:
- Grammar language used as entry point for creating new DSLs
- Scoping and linking approach to resolve cross-references
- Overall handling of the AST as the centrepiece of all language processing
The Langium project is also improving on Xtext’s drawbacks:
- Langium is based on TypeScript, enabling simple integration with web-based tooling including plain web applications.
- Langium is kept as simple as possible while retaining the same level of extensibility and adaptability as Xtext.
- The Langium project uses standard development approaches that are common today. It can be understood by any developer who is familiar with TypeScript and the related technology stacks.
Integration Into Cloud DevTools Ecosystem Further Enhances Value
The Eclipse Cloud DevTools Working Group hosts many of the most influential web-based tool platforms. Most notably, Eclipse Theia is a leading solution for custom-tailored IDEs. Theia has a remarkable level of adoption in various industries and is the platform of choice for all who seek a custom-tailored development environment.
Langium is the most recent addition to the Eclipse Cloud DevTools Working Group. Both Langium and Theia are built with TypeScript. This makes the integration of a Langium-based DSL with an extension of the Theia platform a breeze — you can develop and build both components in the same code repository and the same technology stack. Since Theia uses the VS Code Extension API to integrate languages in general (including well-known programming languages), any extension that contributes a DSL built with Langium can also be used within Microsoft’s popular VS Code editor.
Another project from the Eclipse Cloud DevTools ecosystem that I’d like to highlight is Eclipse Sprotty, a framework for web-based diagramming. Langium offers a package for integrating your DSL with Sprotty. With this integration, you can visualise the contents of your DSL within a graphical view, which can be shown side-by-side with the source text. Useful built-in features include automatic and animated updates of the graphical view when the text is changed, synchronisation of selection between text and diagram, and the ability to modify the contents through user actions in the diagram.
The Future of Language Engineering Is Here
Eclipse Langium offers a unique combination of expressiveness in terms of text parsing ability, processing infrastructure with built-in cross-referencing, and integration with today’s most relevant web-based tools and IDEs. I have shown a selection of usage scenarios in this article, but many more are possible and are known to be already employed by several companies worldwide.
The Langium project is fully open to contributions. Have a look at the code repository on GitHub if you are interested and feel free to ask any questions on the Discussions forum there.
If you are considering implementing a custom language and are unsure how to proceed, you are welcome to contact me.