Tutorials for JetBrains Meta Programming System (MPS)

Comprehensive tutorials and information about how to build and design your languages.

About

Heavy Meta TV hosts an in depth tutorial for JetBrains Meta Programming System (MPS) of about 20 hours. The tutorial were filmed as part of a series of live streams in 2018/2019. Since then MPS hasn’t changed fundamentally and most of the content is still up to date. Throughout the tutorial a simple expression language is used to teach the basics of developing languages inside of MPS. The videos heavily emphasis language design and discusses tradeoff and real word experience of the various design decision take through the course of implementation.

The series starts with a general introduction into modeling / language engineering and a general introduction into the various aspects of MPS. At the end of the tutorial you will have build a complete expression language from start to finish including a simple code generator to Java. The tutorial encourages coding along but feel free to jump in at any point. Each episode links to github where the project is in the same state as at the beginning of the episode which should make it easy to get started. Since each episode builds on the previous one it can hard to skip episodes if you aren’t familiar with basics. The source code for each episode is update along with new MPS releases which will allow you to use the current version of MPS.

In addition to the video and the source code each episode links to additional documentation and information on the topic it covers.

Feel free to give feedback or contribute to the descriptions or links in each video they all feature a little feedback and edit button that allows you to contribute via Github. Of course you can also find the source code of the page there.

If you like the content I always appreciate up votes on the episodes on Youtube it helps to reach new people via Youtubes recommendation. Feel free to drop me a tweet @dumdidum or contact me via the various ways listed on my Github profile.

Introduction to JetBrains Meta Programming System

You will get an overview about what the Meta Programming System by JetBrains is, what it is useful for, where its strengths are and how it compares to other implementation technologies of MPS. You will also get a short walk through of what others have build with MPS.

edit this episode on github

Introduction to Language Aspects

In this Episode you will get an overview on how MPS separates the different concerns of implementing a language with in the language workbench with language aspects. We will cover all the aspects that MPS offers to implement a language and also take a look at examples for the ones that used the most.

edit this episode on github

Starting the first Language

We start with an introduction to the language we would like to build and define some of the features that language will support which we will then implement over the course of the next episodes. You will learn how to create your first project and get stated with the initial definition of the language. For the language we will define basic editor and introduce how version control with MPS works.

Concepts in this part
  • Concept Declaration
  • Interface Declaration
  • Behavior Aspect
  • Properties
  • Reference
  • Structure Aspect

Further Readings:

edit this episode on github

Basic Editors

You will continue further with your language definition that we started you started in the last episode. This time the focus is on making the language easier to use and behave like a text editor to meet the users expectations. The implementation is done with “vanilla” MPS and not third party libraries are used. To achieve this goal we will use the substitute menu and actions from MPS.

Concepts in this part
  • Property Constrains
  • Element Factory
  • Empty Lines
  • Substitute Menu
  • Side Transformation

edit this episode on github

Editors with Grammar Cells and a Basic Type System

After building the first editors for the expression language with vanilla MPS this video will introduce you to grammar cells which is part of the MPS Extensions. You will use grammar cells to rebuild the existing editor to be able to compare the two approaches. Though the further tutorials we will use grammar cells when possible because of it advantages over using MPS out of the box. This part will also explain you the limitations of grammar cells and give you example when to not use them. In the second half this part introduces the basics of type system to assert the correctness of the program.

Note: when you follow the instructions in the video and add the grammar cell concepts to you editor you will get an error message Error Missing Dependency on jetbrains.mps.lang.core or similar. When you place the cursor on the error and open the intentions menu (alt + enter) there is an intention to fix the error. The intention will add a new root node to your editor aspect. That root adds a dependency that is required because of recent API changes in the editor runtime.

Concepts in this part
  • grammar.wrap
  • grammar.option
  • grammar.flag
  • grammar.rules
  • grammar.constant
  • grammar.constant
  • Inference Rule
  • Checking Rule

edit this episode on github

Enhanced Type System

This part continues with the basics of the type system build in previous part. The main objective is to build a type system that is extensible and still maintainable. Special focus is on operation types that make build that type system for binary expression much easier. You will also introduce new type like strings and take a look at type inference.

Concepts in this part
  • Inference Rule
  • Operation Type Container
  • operationtype
  • Checking Rule

edit this episode on github

Variable References and Scopes

This part will introduce the concept of variable references and scopes. The focus is on simple scopes with no nesting and an introduction the different ways of implementing Scope in MPS including Scope Providers.

Concepts in this part
  • Reference
  • Reference Scope
  • Visible Variables

Further Readings:

edit this episode on github

Nested Scopes and Testing

This part introduces nesting of scopes to allow shadowing names of variables and talks briefly about testing languages. For scoping some of the integrated scopes of MPS are explained the Hiding By Name Scope in particular. In language testing the node test aspect is covered extensively but editor tests are introduces briefly as well. With node tests the type system which was introduced over the previous two parts is tested for correct type calculation and error reporting.

Concepts in this part
  • Node Test
  • Scope
  • Scope Provider
  • Hiding by Name Scope

Further Readings:

edit this episode on github

Enhanced Testing and Additional Language Aspects

This part details on editor testing and builds tests for common use cases in the editor. The second half introduces some of the other aspects of MPS to the language. You will explore the use cases of intentions, refactoring and actions. As a bonus you will use the MPS APIs to interact with your language meta model to dynamically retrieve the available concepts of your language.

Concepts in this part
  • Editor Tests (Invoke Intention, Invoke Action, type)
  • Intentions
  • Parameterized Intentions
  • Meta Model API

edit this episode on github

Code Generator Basics

This part introduces the basics of a code generator to Java, it also discusses design decision when building generators.

Concepts in this part
  • Property Macro
  • Reduction Rule
  • Root Mapping Rule
  • Mapping Configuration
  • Generating Java Classes

edit this episode on github

Code Generator Continued

This part will continue to explain generators and looks some of the more advanced features e.g. how to use template switches for extensible generators.

Concepts in this part
  • Reference Macro
  • Template Switch
  • Generating Testcases to Classes

edit this episode on github