代写代考 Week 9: Projectional Language Workbenches

Week 9: Projectional Language Workbenches

Goals for today
Today we will look at a different approach for creating DSMLs

Copyright By PowCoder代写 加微信 powcoder

– Projectional language workbenches
– What is different about them and what are the benefits? – How do we build languages in a projectional workbench? – What are the drawbacks?
13/03/2020 (c) King’s College London 2

Quiz: Parsing vs Projection
What is the difference between parsing and projection in language workbenches? In your own words…
13/03/2020 (c) King’s College London 3

Does MPS differentiate concrete and abstract syntax? If so, how? In your own words…
13/03/2020 (c) King’s College London 4

Projectional editing
A different way of defining language syntax

Parsing vs projection
Textual languages are based on parsing
step myStep next mySecondStep step mySecondStep
13/03/2020 (c) King’s College London 6

Parsing vs projection
Textual languages are based on parsing
step myStep next mySecondStep step mySecondStep
:Flow Chart
myStep:Step
name = “myStep” name = “mySecondStep”
mySecondStep:Step
13/03/2020 (c) King’s College London

Parsing vs projection
Textual languages are based on parsing
Graphical languages are (mostly) based on projection:
– Produce diagram from abstract syntax
– User always changes abstract syntax, never diagram – Diagram is refreshed when abstract syntax
:Flow Chart
myStep:Step
name = “myStep” name = “mySecondStep”
mySecondStep:Step
mySecondStep
13/03/2020 (c) King’s College London

Parsing vs projection
Textual languages are based on parsing
:Flow Chart
myStep:Step
name = “myStep” name = “mySecondStep”
mySecondStep:Step
What if we always did syntax in this way?
Graphical languages are (mostly) based on projection:
– Produce diagram from abstract syntax
– User always changes abstract syntax, never diagram – Diagram is refreshed when abstract syntax
mySecondStep
13/03/2020 (c) King’s College London

We already know this: Model-View-Controller
Controller
13/03/2020 (c) King’s College London

We already know this: Model-View-Controller
Controller
13/03/2020 (c) King’s College London

We already know this: Model-View-Controller
Controller
13/03/2020 (c) King’s College London

We already know this: Model-View-Controller
Controller
13/03/2020 (c) King’s College London

We already know this: Model-View-Controller
Controller
13/03/2020 (c) King’s College London

We already know this: Model-View-Controller
1. Clicks button
Controller
13/03/2020 (c) King’s College London

We already know this: Model-View-Controller
1. Clicks button
Controller
2. Updates model
13/03/2020 (c) King’s College London

We already know this: Model-View-Controller
1. Clicks button
Controller
2. Updates model
13/03/2020
(c) King’s College London
3. Notifies observers

We already know this: Model-View-Controller
1. Clicks button
Controller
2. Updates model
4. Queries model
13/03/2020
(c) King’s College London
3. Notifies observers

We already know this: Model-View-Controller
5. Sees display change
1. Clicks button
Controller
2. Updates model
4. Queries model
13/03/2020
(c) King’s College London
3. Notifies observers

We already know this: Model-View-Controller
5. Sees display change
1. Clicks button
Controller Controller
Controller Controller
4. Queries model
2. Updates model
13/03/2020
(c) King’s College London
3. Notifies observers

We already know this: Model-View-Controller
Concrete Concrete
Editor Editor
Syntax Syntax
Syntax Syntax
Editor Editor
13/03/2020 (c) King’s College London
Concrete Concrete
Abstract Syntax

MPS – an example of a projectional language workbench
MetaProgramming System
– Developed by jetBrains
– The people behind IntelliJ
– Everything is a language
– Abstract syntax is captured using “Concepts”
– Essentially classes / interfaces with inheritance etc – Concrete syntax is captured using “Editors”
– MPS provides its own language for modelling editors
– Additional functionality (incl. semantics) is captured in so-called “Aspects”
– Associated to a particular Concept and applied to all instances of this concept
13/03/2020 (c) King’s College London 8

Building our first language in MPS
Like Eclipse, MPS manages everything in projects
– Need to create a new project for our language
13/03/2020 (c) King’s College London 9

Building our first language in MPS
Like Eclipse, MPS manages everything in projects
– Need to create a new project for our language
13/03/2020 (c) King’s College London 9

Building our first language in MPS
Like Eclipse, MPS manages everything in projects
– Need to create a new project for our language
Give project a sensible name
13/03/2020 (c) King’s College London

Building our first language in MPS
Like Eclipse, MPS manages everything in projects
– Need to create a new project for our language
13/03/2020 (c) King’s College London
And name our language

Building our first language in MPS
Like Eclipse, MPS manages everything in projects
– Need to create a new project for our language
13/03/2020 (c) King’s College London 9
Make sure to create a sandbox to help you try things out

Building our first language in MPS
Like Eclipse, MPS manages everything in projects
– Need to create a new project for our language
13/03/2020 (c) King’s College London 9

Building our first language in MPS
Language project: Everything that defines your language goes in here…
Like Eclipse, MPS manages everything in projects
– Need to create a new project for our language
13/03/2020 (c) King’s College London 9

Building our first language in MPS
Like Eclipse, MPS manages everything in projects
– Need to create a new project for our language
Sandbox project: try out your language here (a bit like the runtime Eclipse)
13/03/2020 (c) King’s College London 9

Building our first language in MPS
Like Eclipse, MPS manages everything in projects
– Need to create a new project for our language
Console etc will go here
13/03/2020 (c) King’s College London 9

Building our first language in MPS
Like Eclipse, MPS manages everything in projects
– Need to create a new project for our language
Inspector is like a properties view, showing additional information. Very useful in MPS, but initially hidden. Open with Alt+2.
13/03/2020 (c) King’s College London 9

Building our first language in MPS – Abstract Syntax
In projectional editors, everything revolves around the abstract syntax
– Remember graphical languages with Sirius?
In MPS, abstract syntax is built from Concepts
– A bit like meta-classes
– Each concept lives on its own, doesn’t need to be grouped into a meta-model
– So that’s a bit more like standard classes – Concepts can have
– Attributes
– References to other concepts
– Additional aspects (editor, behaviour, …)
13/03/2020 (c) King’s College London 10

Building our first language in MPS – Abstract Syntax (2)
To create a new concept
13/03/2020 (c) King’s College London 11

Building our first language in MPS – Abstract Syntax (2)
To create a new concept
– Right click on the structure node in your language – Select New/Concept
13/03/2020 (c) King’s College London 11

Building our first language in MPS – Abstract Syntax (2)
To create a new concept
– Right click on the structure node in your language – Select New/Concept
– Fill in the data for your new concept
– Use Ctrl+Space to see what can be entered
13/03/2020 (c) King’s College London 11

Building our first language in MPS – Abstract Syntax (2)
To create a new concept
– Right click on the structure node in your language – Select New/Concept
– Fill in the data for your new concept
– Use Ctrl+Space to see what can be entered
Editor for concepts. Note, Concept is a concept, too, so is manipulated just like anything else in MPS.
13/03/2020 (c) King’s College London 11

Building our first language in MPS – Abstract Syntax (2)
To create a new concept
– Right click on the structure node in your language
– Select New/Concept
– Fill in the data for your new bciotnlickepketywords in a textual language. These bits are
– Use Ctrl+Space to see what can be entered
Text in blue is constant text that cannot be edited. A projected by the editor and do not have to be entered.
13/03/2020 (c) King’s College London 11

Building our first language in MPS – Abstract Syntax (2)
To create a new concept
– Right click on the structure node in your language
– Select New/Concept
– Fill in the data for your new concept
Here, MPS is expecting some mandatory input.
– Use Ctrl+Space to see what can be entered
It has highlighted that information is missing.
13/03/2020 (c) King’s College London

Building our first language in MPS – Abstract Syntax (2)
To create a new concept
– Right click on the structure node in your language – Select New/Concept
– Fill in the data for your new concept
– Use Ctrl+Space to see what can be entered
Here, other text can be entered, but MPS has provided some default information already.
13/03/2020 (c) King’s College London 11

Building our first language in MPS – Abstract Syntax (2)
To create a new concept
– Right click on the structure node in your language – Select New/Concept
– Fill in the data for your new concept
– Use Ctrl+Space to see what can be entered
Here, other text can be entered, but no text has been entered by default.
13/03/2020 (c) King’s College London 11

Building our first language in MPS – Abstract Syntax (2)
To create a new concept
– Right click on the structure node in your language – Select New/Concept
– Fill in the data for your new concept
– Use Ctrl+Space to see what can be entered
Here, we can add multiple properties of the concept, one by one.
13/03/2020 (c) King’s College London 11

Building our first language in MPS – Abstract Syntax (2)
To create a new concept
– Right click on the structure node in your language – Select New/Concept
– Fill in the data for your new concept
– Use Ctrl+Space to see what can be entered
To test your new concept
– Make or rebuild your language from the language context menu
13/03/2020 (c) King’s College London 11

Building our first language in MPS – Abstract Syntax (2)
To create a new concept
– Right click on the structure node in your language – Select New/Concept
– Fill in the data for your new concept
– Use Ctrl+Space to see what can be entered
To test your new concept
– Make or rebuild your language from the language context menu
– Go to your sandbox and right-click, then select New and the name of your new concept
– Your concept must be rootable for this to work
13/03/2020 (c) King’s College London 11

Building our first language in MPS – Abstract Syntax (2)
To create a new concept
– Right click on the structure node in your language – Select New/Concept
– Fill in the data for your new concept
– Use Ctrl+Space to see what can be entered
To test your new concept
– Make or rebuild your language from the language context menu
– Go to your sandbox and right-click, then select New and the name of your new concept
– Your concept must be rootable for this to work
– You get a default editor a lot like the tree editor from EMF
– Not good for end-users, but useful to try things out quickly
13/03/2020 (c) King’s College London 11

In your pairs
– Build a basic MPS abstract syntax for a root StateMachine concept – Make sure your StateMachine has a name field
– Try it out in an example model
– Don’t forget to build/make your language
You have 10 minutes
13/03/2020 (c) King’s College London 12

Building our first language in MPS – Concrete Syntax
Controller
Abstract Syntax
13/03/2020 (c) King’s College London
Concrete Syntax

Building our first language in MPS – Concrete Syntax
Concrete Syntax
Controller
13/03/2020 (c) King’s College London
Abstract Syntax

Building our first language in MPS – Concrete Syntax (2)
Editors are described in their own DSML – Surprise☺ – Attached to each concept as an Aspect
– Editors consist of editor cells
– Each projects part of the underlying concept – Different types of cells for different purposes:
– Constants for putting out constant text etc
– Layout for grouping a number of cells and arranging them in a particular way
– Feature cells for accessing features of the underlying concept and projecting / editing their
– Editor cells are configured via main editor and inspector window
13/03/2020 (c) King’s College London 15

Building our first language in MPS – Concrete Syntax (3)
Building our own editor
13/03/2020 (c) King’s College London 16

Building our first language in MPS – Concrete Syntax (3)
Building our own editor
– Open concept and hover over it to see the Create Editor button
13/03/2020 (c) King’s College London 16

Building our first language in MPS – Concrete Syntax (3)
Building our own editor
– Open concept and hover over it to see the Create Editor button
– Alternatively, open Editor aspect and click to create new editor for concept
13/03/2020 (c) King’s College London 16

Building our first language in MPS – Concrete Syntax (3)
Building our own editor
– Open concept and hover over it to see the Create Editor button
– Alternatively, open Editor aspect and click to create new editor for concept
13/03/2020 (c) King’s College London 16

Building our first language in MPS – Concrete Syntax (3)
Building our own editor
– Open concept and hover over it to see the Create Editor button
– Alternatively, open Editor aspect and click to create new editor for concept
– Use Ctrl+Space to add initial cell
– Use Alt+Enter to add more complex layouts
13/03/2020 (c) King’s College London 16

In your pairs
– Add a basic MPS editor for your StateMachine concept
– Make sure your StateMachine’s name field can be edited – Try it out in an example model
– Don’t forget to rebuild/make your language
You have 10 minutes
13/03/2020 (c) King’s College London 17

A bit more syntax: Containment trees
Syntax is still basically a tree
– Captured by concept children in MPS – Remember, everything is an AST
– Need to define the child concept before we can add it into the tree
13/03/2020 (c) King’s College London 20

A bit more syntax: Containment trees
Syntax is still basically a tree
– Captured by concept children in MPS – Remember, everything is an AST
– Need to define the child concept before we can add it into the tree
13/03/2020 (c) King’s College London 20

A bit more syntax: Containment trees
Syntax is still basically a tree
– Captured by concept children in MPS – Remember, everything is an AST
– Need to define the child concept before we can add it into the tree
13/03/2020 (c) King’s College London 20

A bit more syntax: Containment trees
Syntax is still basically a tree
– Captured by concept children in MPS – Remember, everything is an AST
– Need to define the child concept before we can add it into the tree
Define multiplicity here. Use Ctrl+Space to learn about what’s available.
13/03/2020 (c) King’s College London 20

A bit more syntax: Containment trees
Syntax is still basically a tree
– Captured by concept children in MPS – Remember, everything is an AST
– Need to define the child concept before we can add it into the tree Editors can then handle the children
– Provide code-completion for creating child nodes of the right type
13/03/2020 (c) King’s College London 20

A bit more syntax: Containment trees
Syntax is still basically a tree
– Captured by concept children in MPS – Remember, everything is an AST
– Need to define the child concept before we can add it into the tree Editors can then handle the children
– Provide code-completion for creating child nodes of the right type
13/03/2020 (c) King’s College London 20
Use Alt+Enter to create all these wrapped collection editors

A bit more syntax: Containment trees
Syntax is still basically a tree
– Captured by concept children in MPS – Remember, everything is an AST
– Need to define the child concept before we can add it into the tree Editors can then handle the children
– Provide code-completion for creating child nodes of the right type
Notice the extra constant cell
13/03/2020 (c) King’s College London

A bit more syntax: Containment trees
Syntax is still basically a tree
– Captured by concept children in MPS – Remember, everything is an AST
– Need to define the child concept before we can add it into the tree
Editors can then handle the children
– Provide code-completion for creating child nodes of the right type
– Needs configuration of layouts to make it look good
– Use vertical/indent layout for the whole concept, setting indent-layout-new-line-
childen style
Use Inspector window to add extra configuration. Use Ctrl+Space to find out what’s available.
13/03/2020 (c) King’s College London 20

A bit more syntax: Containment trees
Syntax is still basically a tree
– Captured by concept children in MPS – Remember, everything is an AST
– Need to define the child concept before we can add it into the tree
Editors can then handle the children
– Provide code-completion for creating child nodes of the right type
– Needs configuration of layouts to make it look good
– Use vertical/indent layout for the whole concept, setting indent-layout-new-line-
childen style
– Set editor for children list to
-indent-layout-indent style – Cell layout vertical
13/03/2020 (c) King’s College London 20

In your pairs
– Add a concept for States and allow a state machine to contain such states – Also add an editor for this
– Try it out in an example model
– Don’t forget to rebuild/make your language – Observe how the editors interact
You have 10 minutes
13/03/2020 (c) King’s College London 21

Interfaces and language reuse
Naming things isn’t that unusual in a language
– Should be able to reuse the capability
– In MPS, can simply make our concept implement interface INamedConcept – This will add in a name property and additional support for it
– We’re reusing an existing language!
– Because there’s no parsing, this isn’t a problem
– Similarly, can use inheritance in our own languages
– BTW: Can explore the definition of those concepts by Ctrl+Click-ing on the concept name
13/03/2020 (c) King’s College London 23

In your pairs
– Simplify your language by reusing the name concept from INamedConcept for States and State Machines
– What do you do with your editors? – Try it out in an example model
– Don’t forget to rebuild/make your language
You have 10 minutes
13/03/2020 (c) King’s College London 24

Cross references
Cross references are references outside of the tree structure
– As with metamodels
– In MPS, cross references can only have a multiplicity of [0..1] or [1]
– For [..*] multiplicity must create a special child concept that only holds a [1] reference – Called a smart reference
13/03/2020 (c) King’s College London 27

Cross references
Cross references are references outside of the tree structure
– As with metamodels
– In MPS, cross references can only have a multiplicity of [0..1] or [1]
– For [..*] multiplicity must create a special child concept that only holds a [1] reference – Called a smart reference
Editor support
– Editors provide code completion, finding any node that is an instance of the referenced concept – Editors support Ctrl+Click for finding referenced object
– Useful when the referenced concept has sub-concepts or is an interface
– Specification of editor

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com