MPS User's Guide
MPS User Guide for Language Designers
Welcome to MPS. This User Guide is a complete reference documentation to MPS and it will navigate you through the many concepts and usage patterns that MPS offers and will give you a hand whenever you need to know more details about any particular aspect of the system.
Topics
Fundamental knowledge - a high-level overview of the basic notions
Contributing to JetBrains MPS - guidelines for MPS contributors and developers on how to get around the MPS source code
Language repository - find out more about languages that are available for use in MPS, both by JetBrains and external vendors
Using MPS - get familiar with the interface through which you'll communicate with MPS
The first run - essential information for beginners about how MPS is organized, how it works, and how to interact with it.
Resolving difficulties, understanding reported errors - tips to help you find your way out when you get stuck somewhere.
Language definition - defining a language involves specifying several aspects, each of which codifies some part of the language - the allowed AST structure, the appearance on the screen, type-system rules, and more.
Aspect
Description
Core documentation
Structure
Defines the kinds of nodes (called Concepts) that may be used in user models. Each node in the program (model) refers to its concept. Concepts specify, which properties, children and references nodes may have. Concepts can extend other Concepts and implement ConceptInterfaces.
SModel language - programmatic access to the model
Open API - API reference for accessing models
Quotations - building AST snippets
Pattern - language for pattern matching nodes
Using model & module dependencies from code FAQ
Video - Introduction to JetBrains MPS, The First Run: Projects
Constraints
Restricts the relationships between nodes as well as the allowed values for properties beyond the rules defined in Structure.
Constraints typically define:
- the target scope for references (a collection of allowed nodes a reference can point to)
- situations, in which a node can be a child/parent/ancestor of another node
- allowed values for properties
- property accessor methods (getters and setters)
Behavior
Just like classes in OOP hold methods, Concepts may define methods and static methods that can be invoked on nodes in a polymorphic way. Nodes thus carry behaviour alongside their properties and relationships.
Editor
Instead of defining a parser that would translate code from an editable form (that is, text) into the tree-like structure that a computer could manipulate, MPS offers the concept of projectional editor, which lets the user edit the AST directly. The Editor aspect enables language designers to create a UI for editing their concepts.
Actions
The Actions aspect provides means to specify advanced editor behavior, such as copy/paste or node initialization.
Intentions
All modern IDEs assist developers with instant code manipulation actions available under a keyboard shortcut (Alt+Enter in MPS). Language authors can define such little code transformations for their languages in the Intentions aspect.
Generator
Models written in one or more languages are ultimately translated into runnable code in some target general-purpose language and platform, such as Java. Along the way, models are gradually transformed so that concepts are repeatedly replaced with concepts from a lower level of abstraction until the lowest level is reached. The rules for translating concepts and their proper ordering are defined in the Generator aspect.
TextGen
During code generation after the Generator has reached the bottom-line AST representation, the TextGen phase kicks in and translates all nodes in the model into their textual representation and saves the resulting textual source files on disk.
Dataflow
The ability to understand the flow of values and the flow of control through language constructs helps languages report issues such as unreachable code or potential null-pointer error . Language designers can leverage the Dataflow aspect to define the flow for each concept, which MPS will then use to calculate the dataflow for the whole program.
Typesystem
Languages that need to type-check their code need to provide type-system rules. The MPS type-system engine will evaluate the rules on-the-fly, calculate types for nodes and report errors wherever the calculated type differs from the expectations.
So-called checking rules may additionally be defined to verify non-typesystem assertions about the model.
Refactoring
Modern IDEs allow developers to seamlessly change the structure of their code through refactoring. MPS allows language designers to prepare such refactorings and make them part of their languages.
Migrations
When a new version of a language is released to the public, projects that use the previous version of the language must be migrated so that they use the new language constructs. Migration scripts, prepared by the language authors, will manipulate user code and automatically update it to the most recent version of the language.
Testing
Various aspects of language definition can be automatically tested. Language authors may create tests that will verify that the editor, actions, type-system, data flow or constraints of their languages behave according to the specifications.
Scripts
TODO
Accessories
The Accessories Models can be stored at two places - either as an aspect of a language (recommended), or as a regular model under a solution. In both cases, the model needs to be added to the Language Runtime Language Settings so as it could be used. A typical use case would be a default library of Concept instances to be available at any place the language is used.
IDE Integration - how to customize MPS, add language-specific visual extensions, use different persistence formats, and more.
UI Plugin - extending the UI (menus, tool windows, tabs, preferences, and more)
Find Usages - customizing the way users discover nodes
IDE tools - tools that MPS offers you to manipulate the languages
Dependencies Analyzer - analyze model dependencies (Analyze model dependencies)
Module Dependencies Tool (Analyze module dependencies)
Platform Languages - out-of-the-box languages ready for use
Icon description - describing icons by text
Building MPS projects - building languages from the command line, Ant integration, continuous integration, creating and using plugins, obfuscating code
Cookbooks - quick how-to guides
Common language patterns - a how-to guide covering recurring language design patterns
Description comments - a cookbook showing how to leverage attributes, scopes and error suppression to add support for description comments on arbitrary code elements of your languages
Requirement tracking language - a commented tour of the Requirement tracking sample project. You will learn about node attributes, multiple projections and scoping.
External tutorials and guides
How to Add JARs to a JetBrains MPS Project - a tutorial by Federico Tomasseti
MindMaps - a tutorial by Antoine Gagnon
Generators tutorial by Eugen Schindler
Maintainable generators by Kolja Dummann