xtext at eclipse democamp london in june 2009
DESCRIPTION
Introduction to Xtext via chess notation, some real world examples and a live demonstration of a pizza recipe.TRANSCRIPT
![Page 1: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/1.jpg)
developing domain specific languages
Heiko BehrensEclipse DemoCamp 2009
London 29.07.2009
E-Mail [email protected]
Blog www.1160pm.net
![Page 2: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/2.jpg)
Xtext?
Xtext is a framework for development ofexternal textual DSLs.
A domain specific language (DSL)in the context of modeling
is a formal, processable languagetargeting at a specific viewpoint or aspect
of a software system.
Its semantics, flexibility and notation is designedin order to support working with that viewpoint
as good as possible.
![Page 3: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/3.jpg)
Rd2-c2
![Page 4: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/4.jpg)
Rd2-c2 ,rook at d2 moves to c2.”
Queen to c7.“”
“
Check.
![Page 5: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/5.jpg)
Moves in Chess:
!ook at a1 moves to a5.
"ishop at c8 captures knight at h3.
# b1 x c3
$2 - g4
Piece
Piece
Piece
Square
Square
Square
Square
Action
Action
Action
Action
Destination
Destination
Destination
Destination
![Page 6: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/6.jpg)
![Page 7: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/7.jpg)
Rook a1 move a5
Bishop c8 capture h3 Knight
Knight b1 capture c3 Queen
Pawn g2 move g4
SourceDestinationPiece
Move
WhitePlayerBlackPlayer
Game«enum»
Piece*
![Page 8: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/8.jpg)
"ishop at c8 captures knight at h3
" c8 x h3
![Page 9: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/9.jpg)
Model (textfile)
White: "Mayfield"
Black: "Trinks"
pawn at e2 moves to e4
pawn at f7 moves to g5
K b1 - c3
f7 - f5
queen at d1 moves to h5
// 1-0
![Page 10: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/10.jpg)
Grammar (similar to EBNF)Game:
! "White:" whitePlayer=STRING
! "Black:" blackPlayer=STRING
! (moves+=Move)+;!
Move:
! AlgebraicMove | SpokenMove;
AlgebraicMove:
! (piece=Piece)? source=Square (captures?='x'|'-') dest=Square;!
SpokenMove:
! piece=Piece 'at' source=Square
! (captures?='captures' capturedPiece=Piece 'at' | 'moves to')
! dest=Square;!
terminal Square:
! ('a'..'h')('1'..'8'); !
enum Piece:
! pawn = 'P' | pawn = 'pawn' |
! knight = 'N' | knight = 'knight' |
! bishop = 'B' | bishop = 'bishop' |
! rook = 'R' | rook = 'rook' |
! queen = 'Q' | queen = 'queen' |
! king = 'K' | king = 'king';
![Page 11: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/11.jpg)
Xtext framework (customizable with Google Guice)
Grammatik
Superclass
Subclass Class
ecore meta modelLL(*) Parser editor
Modell
![Page 12: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/12.jpg)
© itemis AG 2009 – All rights reserved
Demo
• Model File
• Xtext Grammar for writing simple chess games
• Derived meta model
• Java program that works with textual models
• Xpand-based generator
10
![Page 13: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/13.jpg)
Entities (1/2)@SuppressWarnings("serial")
@Entity@Table(name = "CUSTOMER_INFO")
public class CustomerInfo implements Serializable {
! @Id! @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idSeq")
! @SequenceGenerator(name = "idSeq", sequenceName = "CUST_SEQ", allocationSize = 1)! @Column(name = "CUST_ID", nullable = false)
! private String customerId;
! public void setCustomerId(String customerId) {! ! this.customerId = customerId;
! }
! public String getCustomerId() {! ! return customerId;
! }
! @Column(name = "EMAIL", nullable = false, length = 128)! private String emailAddress;
! public String getEmailAddress() {
! ! return emailAddress;! }
! public void setEmailAddress(String emailAddress) {
! ! String oldValue = emailAddress;! ! this.emailAddress = emailAddress;
! ! firePropertyChangedEvent("emailAddress", oldValue, this.emailAddress);! }
![Page 14: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/14.jpg)
Entities (2/2)
entity CustomerInfo
! (id=CUST_ID, sequenceName=CUST_SEQ) {
!
! String emailAddress (notNull, length = 128)
!
}
![Page 15: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/15.jpg)
DSLs in real world scenarios
modeling datadescribe architectures
configurationbusiness rulesdocumentationdata mappings
navigation on object graphsconstraints
knitting patterns...
![Page 16: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/16.jpg)
Demo! Graphical EMF model
! Enhanced with textual DSL (with Xtext)
! Validation
! Code Generation
! Changes textual DSL
![Page 17: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/17.jpg)
Language development has never been so easy.
![Page 18: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/18.jpg)
amoun%&nit' (am)
ingredient'
*rocedur)
![Page 19: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/19.jpg)
© itemis AG 2009 – All rights reserved
Demo
17
recipe:
"pizza without yeast"
ingredients:
125g curd
1 egg
20ml oil
40ml milk
5g salt
250g flour
1x ! soda
procedure:
"Combine all ingredients. Make it a ball.
Knead 10 times. Put dough on a greased cookie sheet
and roll."
![Page 20: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/20.jpg)
![Page 21: Xtext at Eclipse DemoCamp London in June 2009](https://reader034.vdocuments.net/reader034/viewer/2022042515/554a1534b4c90507558b5090/html5/thumbnails/21.jpg)
www.xtext.org
twitter: Xtext
xtext.itemis.com
twitter: itemis
me
Heiko Behrens
www.1160pm.net
twitter: HBehrens
Where to go next?