Child pages
  • MPS User's Guide
93 more child pages
Skip to end of metadata
Go to start of metadata

MPS User Guide for Language Designers

Credits

Welcome to MPS. This User Guide 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.
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. Whatever didn't fit the mentioned scheme was placed into the last Miscelaneous section.

Icon

For your convenience, you can also view the user guide in a single page or as pdf.

Tutorials and cookbooks

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

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.

Beginner's Fast Track to MPS

Icon

Here's our offer for new comers: Try our new Fast Track to MPS page, which was designed specifically for developers, who are completely new to MPS and prefer a guided tour through the MPS landscape. You will walk the beaten path one step at a time, following clear marks that show you where to go next. The information is structured so that you progress from simpler concepts to the more involved ones and at the end of the journey you'll understand MPS and will be able to use it effectively on your projects.

Before you start

How to use the keyboard efficiently

Go to the Default keymap reference page to learn the most useful keyboard shortcuts.

MPS glossary

Abstract Syntax Tree (AST)

a logical representation of code in memory (and disk) in the shape of a tree forest that describes hierarchies of nodes. These nodes have a notion of a parent-child relationship. Additionally, two nodes can be mutually connected with explicit references that go across the hierarchy structure.

BaseLanguage

a projectional clone of Java 6 (with optional extensions for Java 7 and 8). It follows the Java specification and is 1:1 compatible with Java 6. Additionally, MPS provides several handy extensions to BaseLanguage, such as dates, collections, closures and many others.

Code generation

the process of transfromation code from one model (AST) into another model. For example, code describing a set of business rules can be transformed into plain Java so that it can be compiled with javac and run as part of an enterprise application.
Code generation in MPS has two phases - first a series of model-to-model transformations gradually reduce the concepts used in the AST of the program until a bottom-line set of base concepts is reached. Then a text-generating phase translates the AST into textual files.

DevKit

A package of related languages that have been grouped for user convenience.

Domain Specific Language (DSL)

a language dedicated to a particular problem domain, typically created with the aim of simplicity and greater expressivity compared to a general purpose language.

Language plugin

a packaged library ( a zip file) containing all the required elements in order to use a language either inside either IntelliJ IDEA or MPS.

Projectional editor

an editor that allows the user to edit the AST representation of code directly, while mimicing the behavior of a text editor to some extent. The user sees text on teh screen and edits it, however, in reality the text is only an illusion (projection) of an AST.

Module

The top-level organization element of an MPS project that typically groups several models together. It can have three basic types: Solution, Language and DevKit and may depend on other modules and models.

Model

A lower-level organizational element grouping individual concepts. It may depend on other models.

Runtime solution

A solution that is required by a language, sometimes also called a library. Runtime solutions may contain normal models as well as stubs for Java sources, classes or jar files external to MPS.

Structure

A language aspect defining all types (concepts) of AST nodes that can be used in the language together with their relationships.

Concept

A definition that describes the abstract structure of a syntax element. E.g. the IfStatement concepts says that an if holds a boolean Expression and up-to two StatementLists.

Constraints

A language aspect holding additional restrictions on concepts, their properties and relationships.

Behavior

Allows the language designer to define behavior of the language concepts.

Editor

Holds vizualization definitions of individual language concepts. Since the way concepts are viewed and edited on the screen can be customized, the editors specify how the user will interact with the language.

Scope

The set of elements that are visible and applicable to a particular position within a program. Typically only a sub-set of all elements of a particular kind can be used at any given program location.

Typesystem

A set of rules that validate and infer types of concepts in a program. 

Actions

User-invoked commands that may perform changes to the code. Actions can be attached to keyboard shortcuts or menu items.

Intention actions

Context-sensitive actions offered to the language user through a small pop-up window triggered by the Alt + Enter key shortcut. These actions typically perform a relatively local refactoring to the code under carret or a selected block of code.

Surround With intention actions

Intentions applicable to a selected block of code that wrap the block by another concept. E.g. Surround with Try-Catch.

Refactoring

A potentially substantial automated change in code structure triggered by a user action.

Frequently Asked Questions (FAQ)

Check out the FAQ document to get some of your questions answered before you even ask them.

User guide for language designers

  1. Introduction to MPS
  2. Using MPS
  3. 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.

    Aspect name

    Description

    Core documentation

    Other links

    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.

    Structure

    SModel language
        - programatic 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, part 1: Projects
    Video - Introduction to JetBrains MPS, part 2: Structure

    Constraints

    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)

    Constraints

    Scopes
    Video - Introduction to JetBrains MPS, part 3: Constraints

    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.

    Behavior

    Video - Introduction to JetBrains MPS, part 4: Behavior

    Editor

    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.

    Editor
    Diagramming Editor
    Transformation Menu Language
    Context assistant
    Context actions tool

    Editor cookbook
    Video - Introduction to JetBrains MPS, part 5: Editor

    Actions

    Since the MPS editor manipulates the underlying AST directly, some editing actions, such as typing certain characters or strings, translate into non-trivial AST changes. For example, typing the plus sign next to a number should insert a PlusExpression, hook its left child to the original number and set the cursor to the empty cell for the right child.
    The Actions aspect holds definitions of such customised AST transformations.

    Editor Actions

    Video - Introduction to JetBrains MPS, part 6: Actions

    Intentions

    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.

    Intentions

    Video - Introduction to JetBrains MPS, part 7: Intentions

    Generator

    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.

    Generator
    Generator Plan

    Generator cookbook
    Cross-model generation cookbook
    Building an interpreter cookbook
    Video - Introduction to JetBrains MPS, part 8: Generator

    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.

    TextGen

    Video - Introduction to JetBrains MPS, part 9: TextGen

    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 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.

    Dataflow

    Dataflow cookbook
    Video - Introduction to JetBrains MPS, part 10: Dataflow

    Typesystem

    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.

    Typesystem

    Typesystem cookbook
    Using the typesystem
    Debugging the typesystem 
    Video - Introduction to JetBrains MPS, part 11: Type-system

    Refactoring

    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.

    Refactoring

     

    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.

    Migrations

    Migrations with branching

    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.

    Testing

     

    ScriptsTODOScripts 

    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.

    Accessories

     

    xxxxxxxxxxxx

     

    xxxxxxxxxxxxxxxxxxx

    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

  4. Languages for IDE Integration - how to customise MPS, add language-specific visual extensions, use different persistence format, etc.
  5. IDE tools - tools that MPS offers you to manipulate the languages
  6. Platform Languages - out-of-the-box languages ready for use
  7. 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
  8. Tutorials (pdf variant)
  9. Cookbooks - quick how-to guides (pdf variant)
  10. Miscellaneous

On-line help

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:

 

Icon

Did not find the answers?
Post your questions to our discussion forum

  • No labels
Write a comment…