Your SlideShare is downloading. ×
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Building DSLs with Xtext - Eclipse Modeling Day 2009

2,965

Published on

Slides of Eclipse Modeling Day in New York and Toronto http://wiki.eclipse.org/Eclipse_Modeling_Day …

Slides of Eclipse Modeling Day in New York and Toronto http://wiki.eclipse.org/Eclipse_Modeling_Day

Motivation of specific tools with apple corer analogy, Example of domain-specific language (chess notation), introduction to Xtext with demo plus outlook

Published in: Technology
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,965
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
195
Comments
0
Likes
9
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Building DSLs with Xtext Eclipse Modeling Day New York, 16 November 2009 Toronto, 18 November 2009 Heiko Behrens (itemis) © itemis AG 2009 – All rights reserved
  • 2. FOUNDATION MEMBER TM
  • 3. Model-Driven Software Development with DSLs
  • 4. Suppose...
  • 5. You’d want to core an apple...
  • 6. ... for your kids.
  • 7. ? Right tool for the job?
  • 8. Your trusty swiss army knife!
  • 9. Suppose...
  • 10. You’d want to core a few more apples...
  • 11. ... for an apple cake.
  • 12. Still the best tool for the job?
  • 13. Better use this one.
  • 14. and this one:
  • 15. ... a DSL is ...
  • 16. A specific tool for a specific job
  • 17. A specific tool for a specific job
  • 18. Domain-Specific Language (DSL) A DSL 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.
  • 19. Rd2-c2
  • 20. “ Queen to c7. Check.” “ Rd2-c2 , ” rook at d2 moves to c2.
  • 21. 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. P iece S q uare ion 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
  • 22. 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
  • 23. "ishop at c8 captures knight at h3 " c8 x h3
  • 24. 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
  • 25. Xtext is a complete environment for development of textual - programming languages and - domain-specific languages. It is implemented in Java and is based on Eclipse, EMF, and Antlr.
  • 26. ar Model m m ra G Generator Runtime Superclass Subclass Class LL(*) Parser ecore meta model editor
  • 27. 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';
  • 28. Demo • Model File within Editor + Custom View • 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 31
  • 29. Real World DSLs
  • 30. Regular Expressions
  • 31. [-+]?[0-9]*.?[0-9]+
  • 32. Complex Event Processing
  • 33. from FlightBookings F, CarBookings C, HotelBookings H matching [24 hours: F, C, H ] on F.name = C.name = H.name select F.name, true bookingWithCar, into TripleBookings from FlightBookings F, CarBookings C, HotelBookings H matching [24 hours: F, !C, H ] on F.name = C.name = H.name select F.name, false bookingWithCar into TripleBookings from TripleBookings where prev(bookingWithCar) and not bookingWithCar select name into LostCustomers
  • 34. internal DSL (with Java)
  • 35. Mailer.mail() .to(“you@gmail.com”) .from(“me@gmail.com”) .subject(“Writing DSLs in Java”) .body(“...”) .send();
  • 36. ANT
  • 37. <project name="MyProject" default="dist" basedir="."> <property name="src" location="src"/> <property name="build" location="build"/> <property name="dist" location="dist"/> <target name="init"> <mkdir dir="${build}"/> </target> <target name="compile" depends="init"> <javac srcdir="${src}" destdir="${build}"/> </target> <target name="dist" depends="compile"> <mkdir dir="${dist}/lib"/> <jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}"/> </target> <target name="clean"> <delete dir="${build}"/> <delete dir="${dist}"/> </target> </project>
  • 38. ANT ?
  • 39. <project name="MyProject" default="dist" basedir="."> <property name="src" location="src"/> <property name="build" location="build"/> <property name="dist" location="dist"/> <target name="init"> <mkdir dir="${build}"/> </target> <target name="compile" depends="init"> <javac srcdir="${src}" destdir="${build}"/> </target> <target name="dist" depends="compile"> <mkdir dir="${dist}/lib"/> <jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}"/> </target> <target name="clean"> <delete dir="${build}"/> <delete dir="${dist}"/> </target> </project>
  • 40. Entities by Example vs.
  • 41. package templates; import java.util.*; import java.io.Serializable; import javax.persistence.*; @SuppressWarnings("serial") @Entity public class Customer implements Serializable { ! private Long id; ! private String name; ! private Address address; ! private Set<Order> orders = new HashSet<Order>(); ! // No-arg constructor ! public Customer() { ! } ! @Id ! public Long getId() { ! ! return id; ! } ! public void setId(Long id) { ! ! this.id = id; ! } ! public String getName() { ! ! return name; ! } ! public void setName(String name) { ! ! this.name = name; ! } ! public Address getAddress() { ! ! return address; ! } ! public void setAddress(Address address) { ! ! this.address = address; ! } ! @OneToMany ! public Collection<Order> getOrders() { ! ! return orders; ! } ! public void setOrders(Set<Order> orders) { ! ! this.orders = orders; ! } }
  • 42. package templates; import java.io.Serializable; import java.util.*; import javax.persistence.*; @SuppressWarnings("serial") @Entity public class Customer implements Serializable { ! private Long id; ! private String name; ! private Address address; ! private Set<Order> orders = new HashSet<Order>(); ! // No-arg constructor ! public Customer() { ! } ! @Id ! public Long getId() { ! ! return id; ! } ! public void setId(Long id) { ! ! this.id = id; ! } ! public String getName() { ! ! return name; ! } ! public void setName(String name) { ! ! this.name = name; ! } ! public Address getAddress() { ! ! return address; ! } ! public void setAddress(Address address) { ! ! this.address = address; ! } ! @OneToMany ! public Collection<Order> getOrders() { ! ! return orders; ! } ! public void setOrders(Set<Order> orders) { ! ! this.orders = orders; ! } }
  • 43. entity Customer { ! property name : String ! property address : Address ! property orders : Order[] } POJOs DAOs
  • 44. The Finder Method
  • 45. <entity name="Customer"> <attribute type="String" name="name"/> <findMethod name="findFixed"> <expression> <equals> <attributeRef attr="name"/> <constant val="John Doe"/> </equals> </expression> <findMethod> </entity> entity Customer { ! property name : String ! finder findFixed : name = "John Doe" }
  • 46. Demo ! Implement simple Entity DSL ! Use prepared Generator
  • 47. grammar org.xtext.webinar.Entity ! with org.eclipse.xtext.common.Terminals entity generate entity "http://www.xtext.org/webinar/Entity" Model Model: types ! (elements+=Type)*; * Type: Type name: EString ! SimpleType | Entity; SimpleType: ! 'type' name=ID; SimpleType Entity Entity: extends ! 'entity' name=ID ('extends' extends=[Entity])? '{' properties ! ! properties+=Property* * ! '}'; Property name: EString type many: EBoolean Property: ! 'property' name=ID ':' type=[Type] (many?='[]')?;
  • 48. grammar org.xtext.webinar.Entity ! with org.eclipse.xtext.common.Terminals entity generate entity "http://www.xtext.org/webinar/Entity" Model Model: types ! (elements+=Type)*; * Type: Type name: EString ! SimpleType | Entity; SimpleType: ! 'type' name=ID; SimpleType Entity Entity: extends ! 'entity' name=ID ('extends' extends=[Entity])? '{' properties ! ! properties+=Property* * ! '}'; Property name: EString type many: EBoolean Property: ! 'property' name=ID ':' type=[Type] (many?='[]')?;
  • 49. grammar org.xtext.webinar.Entity ! with org.eclipse.xtext.common.Terminals entity generate entity "http://www.xtext.org/webinar/Entity" Model Model: types ! (elements+=Type)*; * Type: Type name: EString ! SimpleType | Entity; SimpleType: ! 'type' name=ID; SimpleType Entity Entity: extends ! 'entity' name=ID ('extends' extends=[Entity])? '{' properties ! ! properties+=Property* * ! '}'; Property name: EString type many: EBoolean Property: ! 'property' name=ID ':' type=[Type] (many?='[]')?;
  • 50. grammar org.xtext.webinar.Entity ! with org.eclipse.xtext.common.Terminals entity generate entity "http://www.xtext.org/webinar/Entity" Model Model: types ! (elements+=Type)*; * Type: Type name: EString ! SimpleType | Entity; SimpleType: ! 'type' name=ID; SimpleType Entity Entity: extends ! 'entity' name=ID ('extends' extends=[Entity])? '{' properties ! ! properties+=Property* * ! '}'; Property name: EString type many: EBoolean Property: ! 'property' name=ID ':' type=[Type] (many?='[]')?;
  • 51. grammar org.xtext.webinar.Entity ! with org.eclipse.xtext.common.Terminals entity generate entity "http://www.xtext.org/webinar/Entity" Model Model: types ! (elements+=Type)*; * Type: Type name: EString ! SimpleType | Entity; SimpleType: ! 'type' name=ID; SimpleType Entity Entity: extends ! 'entity' name=ID ('extends' extends=[Entity])? '{' properties ! ! properties+=Property* * ! '}'; Property name: EString type many: EBoolean Property: ! 'property' name=ID ':' type=[Type] (many?='[]')?;
  • 52. grammar org.xtext.webinar.Entity ! with org.eclipse.xtext.common.Terminals entity generate entity "http://www.xtext.org/webinar/Entity" Model Model: types ! (elements+=Type)*; * Type: Type name: EString ! SimpleType | Entity; SimpleType: ! 'type' name=ID; SimpleType Entity Entity: extends ! 'entity' name=ID ('extends' extends=[Entity])? '{' properties ! ! properties+=Property* * ! '}'; Property name: EString type many: EBoolean Property: ! 'property' name=ID ':' type=[Type] (many?='[]')?;
  • 53. grammar org.xtext.webinar.Entity ! with org.eclipse.xtext.common.Terminals entity generate entity "http://www.xtext.org/webinar/Entity" Model Model: types ! (elements+=Type)*; * Type: Type name: EString ! SimpleType | Entity; SimpleType: ! 'type' name=ID; SimpleType Entity Entity: extends ! 'entity' name=ID ('extends' extends=[Entity])? '{' properties ! ! properties+=Property* * ! '}'; Property name: EString type many: EBoolean Property: ! 'property' name=ID ':' type=[Type] (many?='[]')?;
  • 54. Pimp my Write
  • 55. Whitespace-Aware Languages
  • 56. Incremental Generation
  • 57. Conclusion
  • 58. Abstraction
  • 59. Use a DSL to develop your tools
  • 60. Support Newsgroup Community Forum Professional Support
  • 61. twitter @HBehrens blog http://HeikoBehrens.net mail Heiko.Behrens@itemis.de xing http://www.xing.com/profile/Heiko_Behrens linkedin http://www.linkedin.com/in/HeikoBehrens www.xtext.org The Committer Team twitter @Xtext Heiko Michael Sven Moritz Peter Dennis Jan Patrick Knut Sebastian Behrens Clay Efftinge Eysholdt Friese Hübner Köhnlein Schönbach Wannheden Zarnekow

×