dsl case study: state machine language - · pdf filecase study: state machine language runtime...

19
Meta.ppt 1 TDT4250 - Model-driven Development of Information Systems, Autumn 2009 DSL case study: State machine language Define a DSL language for state machines Create GMF- and Xtext-based editors Translate to the executable SCXML language

Upload: hoangthuan

Post on 30-Jan-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

Meta.ppt 1

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

DSL case study:

State machine language

• Define a DSL language for state machines

• Create GMF- and Xtext-based editors

• Translate to the executable SCXML language

Page 2: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

2

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

DSL with Eclipse

EMF provides platform for DSL

Ecore – (meta)model for design and runtime

EMF.Edit & Editor – edit support and tree-based editor

EMF.Codegen – generic code generation mechanism

GMF – graphical editor runtime and generator

builds on Ecore model of language concepts

domain-specific languages for (among others)

graphical syntax, i.e. structure of diagram symbols

mapping between conceptual language and graphical syntax

generates a complete graphical editor

palette and pop-up tools for editing

saves concepts and diagram elements in separate files

Page 3: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

3

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

DSL with Eclipse

Xtext – text editor runtime and generator

domain-specific language for

textual language grammar

implicitly defines Ecore language model

generates a complete textual editor

syntax coloring and highlighting

completion

navigation and find references

folding, outline and quick outline

syntax checking / error markers

Page 4: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

4

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

DSL with Eclipse

Model transformations

model to model (M2M) using ATL (QVT)

model to text (M2T) using JET or Xpand

Page 5: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

5

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Case study: state machine language

Language with state machine concepts

states (hierarchy) with enter and exit actions

transitions with events, conditions and actions

Meta-levels

Specific state machine in example model

Model (type): State, Transition, Event, Condition, Action concepts

Meta-model: Ecore

Meta-meta-model: Ecore (!)

Page 6: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

6

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Case study: state machine language

Runtime based on SCXML

XML-based language for Statecharts

Implemented by Apache project (library)

Steps:

GMF (and EMF) for building graphical editor

Xtext for building textual editor

Transform (alternatives)

to Ecore model of SCXML using ATL

to SCXML-objects using Java

to SCXML markup using Xpand

Page 7: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

7

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

GMF – Graphical Modeling Framework

Provides a DSL, runtime and tools for building

graphical editors

EMF is used for defining the language concepts

Other models cover:

graphical structure and syntax (gmfgraph)

editing tools (gmftool)

mapping from language concepts to graphical syntax

(gmfmap)

together these implicitly define the generator model (gmfgen)

Page 8: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

8

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Overview of GMF models

Page 9: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

9

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Language concepts

State

name

enterAction and exitAction

sub-states

Transition

event

condition

action

ExternalTransition

source and target states

Page 10: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

10

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Graphical syntax

State

node syntactical type

rounded rectangle

label

compartment for

substates

Transition

connection syntactical type

line with arrow

between source and target states

label combining event, condition and action

Page 11: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

11

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Graphical state syntax

Syntactical types

State node

Substates compartment

Figure

rounded rectangle

label

rectangle (invisible)

inset to provide target area along edges

border layout, with label @ north and compartment @ center

Page 12: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

12

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Graphical transition syntax

Syntactical type

Transition link

Figure

polyline

label

polyline decoration @ target

points defining the arrow head shape -1,-1

0,0

-1, 1

Page 13: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

13

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Tool palette structure

Tools

Create State tool

Create Transition tool

Page 14: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

14

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Mapping from concepts to syntax

Defines

how to traverse the object structure to generate the diagram

and keep it updated when the object structure changes

top-level diagram elements

contained elements

what information in the objects go where in the diagram

labels

Lot’s of details are necessary

a complete specification has to be detailed

the model has necessary details, while the (generated) code

has irrelevant and unnecessary details

Page 15: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

15

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Mapping from concepts to syntax

Top level elements

state

State

node mapping: State class to state node

label mapping: State name attribute to label figure

child reference and compartment mapping: State subStates

reference to compartment

Transition

link mapping: ExternalTransition class to transition connection

Transitions are children of states

Transition source/target references to source and target

label mapping: Transition event, condition and action attributes

to label, with view and edit pattern (syntax)

Page 16: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

16

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

TMF Xtext – Textual Modeling Framework

Provides a DSL, runtime and tools for building

textual editors

EMF is used as the underlying target language

Ecore model is implicitly defined by the grammar

Grammar covers:

lexical syntax (terminals)

rules for syntactical structures

relation between syntax and Ecore classes

Page 17: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

17

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Language concepts

State

name

sub-states

transitions

variables

definitions for script-based events, conditions and actions

Transition

internal, actions triggered by transitions or states

event, condition

initial, default transition when entering parent state

condition, action

external, between states

event, condition, action

Page 18: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

18

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

Language syntax

State

either just a name or content within braces { }

Transition

internal, actions triggered by transitions or states

action when event [ condition ]

initial, default transition when entering parent state

-> state when [ condition ] / action

external, between states

state -> state when event [ condition ] / action

Event

name!, event script reference, state -> state, state-> or ->state

Action

name! or action script reference

Condition

condition script reference

Page 19: DSL case study: State machine language - · PDF fileCase study: state machine language Runtime based on SCXML ... Xtext for building textual editor Transform (alternatives) to Ecore

19

TDT4250 - Model-driven Development of Information Systems, Autumn 2009

Q

TMF Xtext – Textual Modeling Framework

Provides a DSL, runtime and tools for building

textual editors

EMF is used as the underlying target language

Ecore model is implicitly defined by the grammar

Grammar covers:

lexical syntax (terminals)

rules for syntactical structures

relation between syntax and Ecore classes