Xtext @ Profict Summer Camp
-
Upload
sven-efftinge -
Category
Technology
-
view
1.108 -
download
1
Transcript of Xtext @ Profict Summer Camp
![Page 1: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/1.jpg)
Domain-Specific Languages with
Sven Efftinge
copyright 2008 by itemis AG
![Page 2: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/2.jpg)
Kiel, Germany
![Page 3: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/3.jpg)
![Page 4: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/4.jpg)
Peter
Dennis
Jan
![Page 5: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/5.jpg)
![Page 6: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/6.jpg)
![Page 7: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/7.jpg)
![Page 8: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/8.jpg)
“... won’t talk about
model-driven stuff”
![Page 9: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/9.jpg)
You’re lucky!
![Page 10: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/10.jpg)
No UML!
![Page 11: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/11.jpg)
No MDA!
No meta meta meta meta ...
![Page 12: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/12.jpg)
![Page 13: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/13.jpg)
taken from Martin Fowler’s upcoming Book on DSLs
Hands-on a
concrete example
![Page 14: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/14.jpg)
You’re working for a company specialized on systems for
secret compartments
![Page 15: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/15.jpg)
Your customer:
Mrs. H she likes secrets
![Page 16: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/16.jpg)
To open the secret compartment, she has to
![Page 17: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/17.jpg)
To open the secret compartment, she has to
close the door,
![Page 18: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/18.jpg)
To open the secret compartment, she has to
close the door,
open the second draw in her chest,
![Page 19: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/19.jpg)
turn her bedside light on.
To open the secret compartment, she has to
close the door,
open the second draw in her chest,
![Page 20: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/20.jpg)
events doorClosed drawOpened lightOn doorOpened panelClosedend
resetEvents doorOpenedend
commands unlockPanel lockPanel lockDoor unlockDoor end
state idle actions {unlockDoor lockPanel} doorClosed => activeend
state active drawOpened => waitingForLight lightOn => waitingForDrawend
state waitingForLight lightOn => unlockedPanelend
state waitingForDraw drawOpened => unlockedPanelend
state unlockedPanel actions {unlockPanel lockDoor} panelClosed => idleend
![Page 21: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/21.jpg)
events doorClosed drawOpened lightOn doorOpened panelClosedend
resetEvents doorOpenedend
commands unlockPanel lockPanel lockDoor unlockDoor end
state idle actions {unlockDoor lockPanel} doorClosed => activeend
state active drawOpened => waitingForLight lightOn => waitingForDrawend
state waitingForLight lightOn => unlockedPanelend
state waitingForDraw drawOpened => unlockedPanelend
state unlockedPanel actions {unlockPanel lockDoor} panelClosed => idleend
event :doorClosedevent :drawOpenedevent :lightOnevent :doorOpenedevent :panelClosed
command :unlockPanelcommand :lockPanelcommand :lockDoorcommand :unlockDoor
resetEvents :doorOpened
state :idle do actions :unlockDoor, :lockPanel transitions :doorClosed => :activeend
state :active do transitions :drawOpened => :waitingForLight, :lightOn => :waitingForDrawend
state :waitingForLight do transitions :lightOn => :unlockedPanelend
state :waitingForDraw do transitions :drawOpened => :unlockedPanelend
state :unlockedPanel do actions :unlockPanel, :lockDoor transitions :panelClosed => :idleend
External DSL Internal DSL
![Page 22: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/22.jpg)
events doorClosed drawOpened lightOn doorOpened panelClosedend
resetEvents doorOpenedend
commands unlockPanel lockPanel lockDoor unlockDoor end
state idle actions {unlockDoor lockPanel} doorClosed => activeend
state active drawOpened => waitingForLight lightOn => waitingForDrawend
state waitingForLight lightOn => unlockedPanelend
state waitingForDraw drawOpened => unlockedPanelend
state unlockedPanel actions {unlockPanel lockDoor} panelClosed => idleend
event :doorClosedevent :drawOpenedevent :lightOnevent :doorOpenedevent :panelClosed
command :unlockPanelcommand :lockPanelcommand :lockDoorcommand :unlockDoor
resetEvents :doorOpened
state :idle do actions :unlockDoor, :lockPanel transitions :doorClosed => :activeend
state :active do transitions :drawOpened => :waitingForLight, :lightOn => :waitingForDrawend
state :waitingForLight do transitions :lightOn => :unlockedPanelend
state :waitingForDraw do transitions :drawOpened => :unlockedPanelend
state :unlockedPanel do actions :unlockPanel, :lockDoor transitions :panelClosed => :idleend
External DSL Internal DSL
![Page 23: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/23.jpg)
On top of external DSLs
no compromises
![Page 24: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/24.jpg)
On top of external DSLs
domain-specific static analysis
no compromises
![Page 25: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/25.jpg)
On top of external DSLs
domain-specific static analysisgraphical views
no compromises
![Page 26: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/26.jpg)
On top of external DSLs
domain-specific static analysisgraphical views
no compromises
closed scope
![Page 27: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/27.jpg)
Implementing anexternal DSLis complicated
![Page 28: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/28.jpg)
![Page 29: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/29.jpg)
... to develop DSLs?
Why not using a DSL ...
![Page 30: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/30.jpg)
Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+;Event : name=ID;Command : name=ID;State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end';Transition : event=[Event] '=>' state=[State];
![Page 31: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/31.jpg)
Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+;Event : name=ID;Command : name=ID;State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end';Transition : event=[Event] '=>' state=[State];
starts with keyword ‘events’
![Page 32: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/32.jpg)
Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+;Event : name=ID;Command : name=ID;State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end';Transition : event=[Event] '=>' state=[State];
followed by at least one definition of Event
which is defined here and consists of just one
identifier (ID)
![Page 33: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/33.jpg)
Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+;Event : name=ID;Command : name=ID;State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end';Transition : event=[Event] '=>' state=[State];
this is a cross reference, referencing Events
declared in the previous section.
![Page 34: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/34.jpg)
Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+;Event : name=ID;Command : name=ID;State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end';Transition : event=[Event] '=>' state=[State];
commands are very similar to events
![Page 35: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/35.jpg)
Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+;Event : name=ID;Command : name=ID;State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end';Transition : event=[Event] '=>' state=[State];
States have a name (ID)
![Page 36: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/36.jpg)
Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+;Event : name=ID;Command : name=ID;State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end';Transition : event=[Event] '=>' state=[State];
States have a name (ID)
optional action block
![Page 37: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/37.jpg)
Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+;Event : name=ID;Command : name=ID;State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end';Transition : event=[Event] '=>' state=[State];
States have a name (ID)
optional action block
any number of Transitions
![Page 38: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/38.jpg)
This was the example DSL implemented in
So what do we get from such a description?
![Page 39: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/39.jpg)
![Page 40: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/40.jpg)
Antlr based Parser
![Page 41: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/41.jpg)
Eclipse based Editor
Antlr based Parser
![Page 42: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/42.jpg)
Statemachine
name:StringCommand
name:StringState
name:StringEvent
Transition
** *
*
*
stateseventscommands
actions
stateevent
resetStates
EMF based Semantic Model
Eclipse based Editor
Antlr based Parser
![Page 43: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/43.jpg)
Demo
![Page 44: Xtext @ Profict Summer Camp](https://reader033.fdocuments.us/reader033/viewer/2022052204/554a1579b4c9058c5d8b4e2e/html5/thumbnails/44.jpg)
oaw.itemis.comThank you very much!
the eclipse distro can be downloaded from
http://oaw.itemis.com