Xtext at Eclipse DemoCamp London in June 2009

3,205 views

Published on

Introduction to Xtext via chess notation, some real world examples and a live demonstration of a pizza recipe.

Published in: Technology, Travel
2 Comments
2 Likes
Statistics
Notes
No Downloads
Views
Total views
3,205
On SlideShare
0
From Embeds
0
Number of Embeds
70
Actions
Shares
0
Downloads
125
Comments
2
Likes
2
Embeds 0
No embeds

No notes for slide

Xtext at Eclipse DemoCamp London in June 2009

  1. 1. developing domain specific languages Heiko Behrens Eclipse DemoCamp 2009 London 29.07.2009 E-Mail Heiko.Behrens@itemis.de Blog www.1160pm.net
  2. 2. Xtext? Xtext is a framework for development of external textual DSLs. A domain specific language (DSL) in the context of modeling is a formal, processable language targeting at a specific viewpoint or aspect of a software system. Its semantics, flexibility and notation is designed in order to support working with that viewpoint as good as possible.
  3. 3. Rd2-c2
  4. 4. “ Queen to c7. Check.” “ Rd2-c2 , ” rook at d2 moves to c2.
  5. 5. Moves in Chess: !ook at a1 moves to a5. P iece S q uare A ction De stin ation "ishop at c8 captures knight at h3.n P iece S q uare io Action D es tinat # b1 x c3 Piece S qua re ction stination AD e $2 - g4 ation S A D quar e ction e stin
  6. 6. Rook a1 move a5 Bishop c8 capture h3 Knight Knight b1 capture c3 Queen Pawn g2 move g4 Game Move Source «enum» WhitePlayer * Destination Piece BlackPlayer Piece
  7. 7. "ishop at c8 captures knight at h3 " c8 x h3
  8. 8. 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
  9. 9. 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';
  10. 10. ik at Modell m m ra G Superclass Subclass Class LL(*) Parser ecore meta model editor Xtext framework (customizable with Google Guice)
  11. 11. Demo • Model File • Xtext Grammar for writing simple chess games • Derived meta model • Java program that works with textual models • Xpand-based generator © itemis AG 2009 – All rights reserved 10
  12. 12. 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); ! }
  13. 13. Entities (2/2) entity CustomerInfo ! (id=CUST_ID, sequenceName=CUST_SEQ) { ! ! String emailAddress (notNull, length = 128) ! }
  14. 14. DSLs in real world scenarios modeling data describe architectures configuration business rules documentation data mappings navigation on object graphs constraints knitting patterns ...
  15. 15. Demo ! Graphical EMF model ! Enhanced with textual DSL (with Xtext) ! Validation ! Code Generation ! Changes textual DSL
  16. 16. Language development has never been so easy.
  17. 17. amoun% &nit' (am) ingredient' *rocedur)
  18. 18. Demo 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." © itemis AG 2009 – All rights reserved 17
  19. 19. Where to go next? www.xtext.org twitter: Xtext xtext.itemis.com twitter: itemis me www.1160pm.net Heiko Behrens twitter: HBehrens

×