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.
Beginner's Fast Track to MPS
Structure of the User Guide
- First, the Introduction section will offer a high-level overview of the basic notions and their roles.
- In the second section, named Using MPS, you'll get familiar with the interface through which you'll communicate with MPS. Although very small, there still are some differences between how you interact with MPS and how you typically use other common programming tools.
- In the third section, called Defining Languages, we'll get to the meat of MPS. We'll show details on how to define the many aspects of your custom languages - their structure, editors, generators and type systems rules.
- The IDE integration section will then provide some additional context necessary to help you improve the IDE aspect of your languages and integrate them nicely into MPS.
- The Platform languages section gives you details on all languages bundled with MPS including the corner stone language of MPS - the BaseLanguage.
- The Delivering languages to the users and Java IDE integration section covers the build language and the process of building standalone IDEs as well as language plugins.
- Don't forget to check out our tutorials and focused cookbooks listed in the Tutorials and Cookbooks sections, to learn more about individual aspects of MPS
- Whatever didn't fit the mentioned scheme was placed into the last Miscelaneous section.
Alternative User Guides
Not a language designer yet? Try out one of our simplified MPS user guides
You do not need to design your own languages and DSLs to benefit from MPS. You may well enjoy using languages designed and developed by somebody else. These languages are typically distributed as language plugins for Java IDEs or they may come bundled with their own standalone IDEs. Since using existing languages is a much simpler tasks than creating them, we prepared dedicated user guides covering the topics relevant to the DSL users.
- Check out the MPS user guide for Java developers (IntelliJ IDEA) if you want to learn quickly how to use MPS for Java development.
- The MPS user guide for DSL users collects the essential knowledge required for developing in MPS-based DSLs using an MPS-based standalone IDE.
User guide for language designers
- Introduction to MPS
- Using MPS
- The first run - essential information for total beginners into how MPS is organised, how it works and how users are supposed to interact with it.
- MPS Java compatibility
- Commanding the editor
- IDE configuration
- Getting the module dependencies right
- Resolving difficulties, understanding reported errors
- Where to find language plugins
- Version control notes
- Using Debugger
- Using Migrations with branching
Defining Languages - 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, etc.
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.
- programatic access to the model
- API reference for accessing models
- building AST snippets
- language for pattern matching nodes
Using model & module dependencies from code FAQ
Restricts the relationships between nodes as well as the allowed values for properties beyond the rules defined in Structure.
Constraints typicaly 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)
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.
Instead of defining a parser that would translate code from an editable form (i.e. text) into the tree-like structure that a computer could manipulate, MPS offers the concept of projectional editor, which let's the user edit the AST directly. The Editor aspect enables language designers to create a UI for editing their concept concepts.
The Actions aspect provides means to specify advanced editor behavior, such as copy/paste or node initialization.
Video - Introduction to JetBrains MPS, part 6: Actions (obsolete)
All modern IDEs assist developers with instant code manipulating action available under a handy key-shortcut (Alt + Enter in MPS). Language authors can define such little code transformations for their languages in the Intentions aspect.
Models written in one or more languages get ultimately translated into runnable code in some target general-purpose language and platform, such as Java. Along the way models get gradually transformed so that repeatedly concepts get replaced with concepts from a lower level of abstraction until the bottom-line level is reached. The rules for translating concepts and their proper ordering is defined in the Generator aspect.
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.
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 designer 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.
Language 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.
Modern IDEs allow the developer to seamlessly and flawlessly change the structure of their code through refactoring. MPS allows the language designers to prepare such refactorings and make them part of their languages.
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.
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 Scripts
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.
- Languages for IDE Integration - how to customise MPS, add language-specific visual extensions, use different persistence format, etc.
- Generic placeholders and generic comments
- Commenting out nodes
- Custom language aspects
- Icon description - describing icons by text
- UI Plugin - extending the UI (menus, tool windows, tabs, preferences, etc.)
- Find Usages - customising the way users discover nodes
- Suppressing Errors
- Extension support
- Custom Persistence Cookbook
- MPS and Ant
- MPS and Git
- HTTP support plugin
- IDE tools - tools that MPS offers you to manipulate the languages
- Platform Languages - out-of-the-box languages ready for use
- Delivering languages to the users and Java IDE integration - building languages from the command line, Ant integration, continuous integration, creating and using plugins, obfuscating code
- Tutorials (pdf variant)
- The Fast Track to MPS tutorial
- Shapes - an introductory MPS tutorial
- JetBrains MPS Calculator tutorial
- Generator demos tutorial
- How to Add JARs to a Jetbrains MPS Project by Federico Tomasseti
- MindMaps by Antoine Gagnon
- Markus Voelter's tutorial
- The beginners screen-cast series on JetBrains TV
- The MPS screen-casts page
- The MPS channel on JetBrains TV
- Cookbooks - quick how-to guides (pdf variant)
- Common language patterns - a how-to guide covering recurring language design patterns
- Getting the dependencies right
- Editor cookbook
- Generator cookbook
- Building an interpreter cookbook
- 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
- Type System
- Dataflow cookbook
- Regular expressions
- Open API - accessing models from code
- Custom Persistence Cookbook
- Custom Language Aspect Cookbook
- Finding your way out - a brief collection of guidelines that should help you move forward when you get stuck somewhere.
MPS comes with bundled help, which shows context-sensitive help information when you hit the F1 key. As an alternative you can view the help pages on-line: