Skip to content

Coming from MPS or Xtext

Audience: language engineers who already build languages with JetBrains MPS or Eclipse Xtext · about 20 minutes · Prerequisites: The Language Editor

What it is

A map from the parts of an MPS or Xtext language to the place each one lives in struktJS, with the differences that matter before you port anything. It is a reading guide, not a converter: there is no importer for MPS languages, MPS models, Xtext grammars or Xtext models. You rebuild the language in struktJS and then re-enter or script the models.

How this page was checked

The mapping comes from reading how struktJS defines each part (the Language authoring guide and the pages it links) and from the bundled languages. No MPS or Xtext project was ported for this page, so treat the "closest match" column as a starting point, and check the "Differences" notes against your own language.

Should you move at all?

struktJS is a projectional editor like MPS: you edit the structure of a program, not text that is parsed back into a tree. That decides most of what follows.

If you need... struktJS
A projectional editor that prevents syntax errors (MPS-style) Yes. Typing builds nodes; there is no parse step to fail.
Free-form text editing of a DSL with your own concrete syntax (Xtext-style) Not the model. Text is only how a model is stored (see below). End users do not type your grammar.
An editor in a browser, an embedded widget, or a desktop app with no JVM Yes: browser and desktop, embedding in a web page.
Models that diff and merge in git as readable text Yes. See Model-aware diff and merge.
Language workbench features such as multi-step generation plans, language migrations with data migration scripts, or the MPS build language Partly. The Differences section lists what is smaller here.
Exchange of models with other tools via LionWeb Not available. LionWeb is only a plan; see Importing and exporting languages.

Concept mapping: MPS

MPS struktJS Where you edit it
Language (with its aspects) A language: a named set of concepts plus language-wide checks, generators and settings, saved as <name>.lang.js (or shipped as a plugin) The Language Editor
Devkit A devkit: a bundle of sibling languages installed as one Plugins and devkits
Concept, abstract concept, concept interface A concept; isAbstract for a template-only one; an interface such as IExpression or IStatement Language Editor, Structure tab
extends and implements extends (one base) and the interface list Structure tab, Declaration
Property, child, reference link A Prop slot, a ChildSlot, a Ref slot Structure tab
Cardinality 1, 0..1, 0..n, 1..n The same strings, plus ranges such as 2..n Structure tab
Editor aspect (cells, Constant, Collection, indent, new line) The concept's editor: a small JSX template with Text, Child, Children, Indent, Br, tables and diagrams Editor tab; Editors and projections
Inspector The concept's inspector cell Editor tab
Alternative editors Notations: several layouts for one node, switchable per node Editor tab, Notations; Notations and views
Editor actions, substitute menu The completion menu (Ctrl+Space), driven by each concept's alias and slot types; side-transformations for operators Completion menu
Constraints aspect (can-be-child, can-be-parent, property constraints) Slot-level constraints (.must()), placement rules Constraints and placement
Scope (ScopeProvider, reference constraints) scope(), referenceScopes() and Ref slots Scope and dataflow
Typesystem rules, checking rules typesystem() (infer and check), checks() Type checking, Problems and Checks
Quick fixes and intentions Intentions (Alt+Enter) Intentions and quick fixes
Data flow aspect dataflow() Scope and dataflow
Behavior aspect (concept methods) Methods on the concept class Authoring concepts
Interpreter (for example KernelF) eval() per concept; the bundled KernelF-style language is the worked example Running a model
Generator: text generation generate() per concept Generators and Open Preview
Generator: reduction and weaving rules, model-to-model reduce, weave and post-process rules, run as a pipeline Evaluation and generation
Generator output to files, build Multi-file generation; the strukts generate and strukts package CLI commands Multi-file generation, The strukts CLI
Language extension / extending a language Language imports, and aspect overlays to change one imported concept's editor, generator or type rules without forking Language authoring guide
Migrations Migrate... on a language: rename concept or slot, add or remove a slot Language authoring guide
Tests language, node tests Test suites in the model, run from the Tests pane or strukts test Writing and running tests
Model, root node A model is a folder holding one or more roots, each its own file Projects and models, Models, roots and imports
Model imports, used languages Model imports and language imports Models, roots and imports
Find usages, rename refactoring Find Usages and Rename across models Find, Replace, Find Usages and Rename
Plugin / solution packaging A plugin folder, or a packaged language file Installing and removing plugins

Concept mapping: Xtext

Xtext struktJS Notes
Grammar (.xtext) A language's concepts The grammar's parser rules become concepts. Its concrete syntax does not become an editor syntax.
Parser rule A concept One concept per rule that produces a node.
Assignment name=ID A Prop slot of kind name Other terminals map to string, number, boolean.
Containment items+=Item* A ChildSlot with cardinality 0..n + is 1..n, ? is 0..1.
Cross-reference [Entity] A Ref slot Resolution is by name in scope, not by a stored id.
Rule hierarchy / alternatives (Expr: Add | Mul | Lit) An interface (IExpression) that the alternatives implement A slot of that type accepts any implementor.
Enum rule A closed-set property; see the Entities demo for a worked enum Check the Entities sample for the form you want.
Keywords and punctuation in a rule Text in the concept's editor template Layout is yours; it is not parsed back.
Operator precedence by rule nesting A per-concept operator spec (key, kind, precedence) Typing an operator at the end of a filled cell wraps the node, so precedence is declared as data.
Scope provider, IQualifiedNameProvider scope() and Ref See Same-named declarations for how name clashes are spelled.
Validator @Check methods checks() and slot .must() constraints The Problems panel and Checks pane show them live.
Quick-fix provider Intentions
Content assist The completion menu It lists concepts valid at the cursor, not tokens.
Formatter Not needed There is no free-form text to format. The stored text form is printed in a fixed way.
Xtend / template generator generate() per concept, or reduce rules for model-to-model
Xtext index and linking across files Model imports and cross-model resolution
Language server, Eclipse / VS Code plug-in The IDE, the browser demo, or the embeddable editor No LSP bridge is planned.

Differences worth knowing first

  • Stored text is not your DSL's syntax. A model file is real source text, Python-style (.model.py) by default, with JavaScript and TypeScript available and a JSON, XML or S-expression form for some languages. A concept's surface() says how it prints and parses in that grammar, and must round-trip losslessly. The reader of a stored model sees Python-looking code; the author sees your projection. See The model file format and Persistence grammars.
  • Node ids are not persisted. A node's identity inside a session is a number; the file does not keep it. That is what makes the text diff cleanly, and it is also why an id-based exchange format (such as LionWeb) needs a separate id strategy.
  • Inference is bidirectional, not constraint solving. MPS's type system solves equations and runs both ways. struktJS infers types with plain infer and check hooks and needs expected-type information passed down explicitly (for example for lambdas or empty collections). Port rules as functions, not as equations.
  • Aspects live together. In MPS an aspect is a separate model; here one concept holds structure, editor, checks and generator in one class, and the Language Editor shows them on tabs. A tab is a view of the same concept.
  • Smaller than MPS in places. There is no equivalent of the MPS build language or of the generator-plan editor, and migrations are limited to the structural operations above. Port a multi-step MPS generation plan as a pipeline of reduce rules plus generate().
  • Project code is code. A language's rule bodies are JavaScript. A project that carries its own *.lang.js is only run after you trust it; see Trusting project code.

How to port a language

  1. List your concepts and their slots. Build a table of concept, base concept, interfaces, and each property, child and reference with its cardinality. This is the Structure work and ports mechanically.
  2. Create the language with New Language… in the Explorer, starting from the Blank card, or from Data model if the language is mostly records. See The Language Editor.
  3. Add the concepts and fill the Structure tab. Put the interfaces in first (IExpression, IStatement), because slot types refer to them.
  4. Write the editor template for each concept. Start from the Constant/Collection layout of the MPS editor or the keywords of the Xtext rule. Do the common concepts first and let the generic fallback show the rest.
  5. Declare references and scopes. Mark reference, declaration and block concepts, then add scope() where names are not simply visible in the enclosing blocks.
  6. Port checks and constraints. Slot rules become .must(); node rules become checks(). Run them against a hand-built model, not only against the shipped samples.
  7. Port types, then generators. Types first, because generators often read them. For a generator, begin with generate() for text output and add reduce rules only for model-to-model steps.
  8. Bring the models over. Re-enter small models by hand. For many, script it: write the models as .model.py text in the language's persisted form, or build them with the Model Console and its API, and confirm with strukts check. There is no import from MPS XML or Xtext files.
  9. Add tests and put the command line in CI. Test suites travel with the model; see CI with Gradle and Bazel.

Troubleshooting

Symptom Likely cause What to do
A reference cell offers nothing The target concept is not a declaration, or scope() does not introduce the name Check the declaration flag and the scope descriptor.
Two concepts fight over one key Same head, alias or operator key in two languages See Same-named declarations and the collision scan in the language guide.
A stored model re-reads differently surface() is not lossless for that concept Fix the mapping until print then parse reproduces the node.
A rule that worked in MPS gives a different type The rule relied on solving both ways Pass the expected type down explicitly.