Skip to content

Latest commit

 

History

History
185 lines (137 loc) · 7.51 KB

structure-extensions.adoc

File metadata and controls

185 lines (137 loc) · 7.51 KB

Reference for LionWeb Extensions on MPS' Language Structure Aspect

1. Prerequisites

We amend MPS' language structure aspect with node attributes to support advanced LionWeb features.

To use advanced LionWeb features, add io.lionweb.mps.structure.attribute to the Used Languages of the structure aspect of your language. Even if you don’t need any advanced LionWeb features, you should add this Used Language to all your LionWeb-processed languages: It checks the constraints described in this document.

2. Concepts as partitions

In LionWeb, partitions serve as the container for one node tree (similar to models in MPS).

Use intention Toggle LionWeb Partition to add a boolean attribute LionWeb partition to a concept. If no such attribute exists, we assume default value false.

3. Optional properties

LionWeb supports optional properties on structure level, whereas MPS only considers them on editor level.

Use intention Toggle LionWeb Optional to add a boolean attribute LionWeb optional to a property. If no such attribute exists, we assume default value false, i.e. consider the property as mandatory.

4. Multi-references

Unlike MPS, LionWeb supports multiple references, i.e. references with cardinality ⎵..n. MPS approximates them with smart references; LionWeb formalizes this approach.

Use intention Add LionWeb Smart Reference on a concept to turn the concept into a LionWeb smart reference. Point the new attribute LionWeb smart reference for to a child with the smart reference as target. LionWeb considers the child as a reference with the smart reference’s target as type, and does not represent the smart reference itself.

4.1. Example

A Book can refer to zero or more authors of type Writer. In MPS, we need an additional smart reference WriterReference, annotated with a LionWeb smart reference for that points at the child Book.authors. LionWeb omits the smart reference, and turns MPS' author child into a reference with multiple: true.

Book Concept
concept Book extends BaseConcept
  …​
  children:
  authors : WriterReference[0..n]

  references:
  << ... >>
Writer Concept
concept Writer extends BaseConcept
  …​
  children:
  << ... >>

  references:
  << ... >>
WriterReference Concept
concept WriterReference extends <default>
  …​
  children:
  << ... >>

  references:
  writer : Writer[1]

  LionWeb smart reference for: Book.authors
LionWeb equivalent
Concept Book   extends Node
  Reference authors: Writer  optional: true  multiple: true

Concept Writer extends Node
  << ... >>

4.2. Constraints on LionWeb smart reference concept

  • Must be a concrete (i.e. non-abstract) concept

  • Must not be used for anything else (e.g. a target of a reference, or super-concept)

  • Must not extend any concept except BaseConcept

  • Must not implement any interfaces

  • Must not have any property members

  • Must not have any child members

  • Must have exactly one reference member

5. Custom LionWeb keys

LionWeb uses keys to refer to language entities. By default, LionWeb-MPS derives the key from MPS' internal ids. As language designer, we can customize the LionWeb key (e.g. if they need to be consistent across different implementations).

Constraints
  • Keys must be valid identifiers. Use intention Replace invalid characters with dash to fix invalid keys.

  • Keys must be unique within one language.

5.1. Custom language key

Create a root node of concept lionweb LionWeb Language Key inside a structure aspect to customize the language’s key.

This concept provides two handy intentions:

  • Replace Key with Name for All Language Elements uses all elements' names as key. Example: MyGreatConcept gets key MyGreatConcept, and its property numberOfThings gets key MyGreatConcept-numberOfThings. This intention overwrites all existing manually assigned keys.

  • Add Name as Key to All Language Elements assignes the same keys, but only to elements without an existing LionWeb key.

5.2. Language element key

LionWeb-MPS supports custom keys for the following MPS language structure elements:

Use intention Toggle LionWeb Key Annotation to add or remove a LionWeb key. Alternatively, use intention Remove LionWeb key on the key itself to remove.

6. Use LionWeb JSON type

Contrary to MPS, LionWeb supports JSON as primitive type.

Add io.lionweb.mps.m3.structure to the Dependencies of the structure aspect of your language, and use JSON as data type of your property.

Note
LionWeb-MPS currently does not validate the contents of a JSON property. This might change in future releases.

7. Limitations on attributes

MPS' attributes map to LionWeb’s annotations. MPS specifies details via attribute info.

However, LionWeb does not support all edge cases of attributes:

  • LionWeb only supports attributes on nodes, i.e. specializations of NodeAttribute. LionWeb does not support attributes on properties, children, and links, i.e. specializations of PropertyAttribute, ChildAttribute, and LinkAttribute.

  • LionWeb does not support annotations on all annotations i.e. the attribute info / attributed concepts must not target NodeAttribute.

8. Partial support of primitive datatypes

LionWeb-MPS does not support MPS' primitive datatypes completely. We can process them based on the structure aspect of a language, but not based on the run-time language representation (because primitive datatypes are not represented in the SLanguage).

9. No support for legacy enumeration data types

LionWeb-MPS does not support deprecated Enumeration Data Types. Use Enumerations instead.