SlideShare a Scribd company logo
Building DSLs with
      Eclipse
                            Peter Friese, itemis

                                   @peterfriese
                                    @xtext




(c) 2009 Peter Friese. Distributed under the EDL V1.0 - http://www.eclipse.org/org/documents/edl-v10.php
                       More info: http://www.peterfriese.de / http://www.itemis.com
Building DSLs With Eclipse
Building DSLs With Eclipse
Building DSLs With Eclipse
Building DSLs With Eclipse
Building DSLs With Eclipse
What is a DSL?
Domain
Building DSLs With Eclipse
Building DSLs With Eclipse
Building DSLs With Eclipse
Building DSLs With Eclipse
Building DSLs With Eclipse
Building DSLs With Eclipse
Language
Building DSLs With Eclipse
Building DSLs With Eclipse
Suppose...
You’d want to core an apple...
... for your kids.
?
Right tool for the job?
Your trusty swiss army knife!
Because you can use it for other stuff, too.
      E.g., opening a bottle of wine.
Suppose...
You’d want to core a few more apples...
... for an apple cake.
Still the best tool for the job?
Better use this one.
and this one:
BUT

avoid the unitasker!
BUT

avoid the unitasker!
... a DSL is ...
A specific tool
for a specific job
A specific tool
for a specific job
Samples for DSLs
SQL
select name, salary
 from employees
 where salary > 2000
 order by salary
ANT
<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>
<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>
External
   or
Internal
Internal DSLs
Mailer.mail()
 .to(“you@gmail.com”)
 .from(“me@gmail.com”)
 .subject(“Writing DSLs in Java”)
 .body(“...”)
 .send();
Simple
Limited
External DSLs
Building DSLs With Eclipse
1)Create ANTLR grammar
2)Generate lexer / parser
3)Parser will create parse tree
4)Transform parse tree to semantic model

5)Iterate model
6)Pass model element(s) to template
Flexible
Adaptable
Complicated
Why not use a DSL...




... for building DSLs?
Building DSLs With Eclipse
Demo 1
Building DSLs With Eclipse
@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);
	   }
@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);
	   }
entity CustomerInfo
	 (id=CUST_ID, sequenceName=CUST_SEQ)
{
	
	 String emailAddress (notNull, length = 128)
	
}
entity CustomerInfo
	 (id=CUST_ID, sequenceName=CUST_SEQ)
{
	
	 String emailAddress (notNull, length = 128)
	
}




               Bean
                         DAO
              (POJO)
Building DSLs With Eclipse
Underlying Technology
Model




G
 ra
      m
       m
           ar
ar
Model




               m
              m
          ra
          G
        Generator
ar
Model




                                    m
                                   m
                               ra
                               G
                             Generator



        Runtime
                  Superclass




                  Subclass              Class




 LL(*) Parser   ECore meta model                Editor
ar
Model




                                    m
                                   m
                               ra
                               G
                             Generator



        Runtime
                  Superclass




                  Subclass              Class




 LL(*) Parser   ECore meta model                Editor
Grammar (similar to EBNF)
 grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals

 generate entity "http://www.xtext.org/example/Entity"

 Model:
   (types+=Type)*;

 Type:
   TypeDef | Entity;

 TypeDef:
   "typedef" name=ID ("mapsto" mappedType=JAVAID)?;

 JAVAID:
   name=ID("." ID)*;

 Entity:
   "entity" name=ID ("extends" superEntity=[Entity])?
   "{"
     (attributes+=Attribute)*
   "}";

 Attribute:
   type=[Type] (many?="*")? name=ID;
grammar org.xtext.example.Entity
    with org.eclipse.xtext.common.Terminals            Meta model inference
generate entity
    "http://www.xtext.org/example/Entity"
                                              entity
Model:
  (types+=Type)*;
                                                                       Model
Type:
  TypeDef | Entity;
                                                                          types
TypeDef:                                                                *
                                                                    Type
  "typedef" name=ID
                                                                 name: EString
  ("mapsto" mappedType=JAVAID)?;
                                                                                                superEntity
JAVAID:
  name=ID("." ID)*;                                      TypeDef                    Entity


Entity:                                       mappedType                                attributes
  "entity" name=ID
                                                                                  Attribute
  ("extends" superEntity=[Entity])?                       JAVAID
                                                                               name: EString
  "{"                                                  name: EString
                                                                               many: EBoolean
    (attributes+=Attribute)*
  "}";                                                                                  type

Attribute:
  type=[Type] (many?="*")? name=ID;
grammar org.xtext.example.Entity
    with org.eclipse.xtext.common.Terminals            Meta model inference
generate entity
    "http://www.xtext.org/example/Entity"
                                              entity                   Rules -> Classes
Model:
  (types+=Type)*;
                                                                       Model
Type:
  TypeDef | Entity;
                                                                          types
TypeDef:                                                                *
                                                                    Type
  "typedef" name=ID
                                                                 name: EString
  ("mapsto" mappedType=JAVAID)?;
                                                                                                superEntity
JAVAID:
  name=ID("." ID)*;                                      TypeDef                    Entity


Entity:                                       mappedType                                attributes
  "entity" name=ID
                                                                                  Attribute
  ("extends" superEntity=[Entity])?                       JAVAID
                                                                               name: EString
  "{"                                                  name: EString
                                                                               many: EBoolean
    (attributes+=Attribute)*
  "}";                                                                                  type

Attribute:
  type=[Type] (many?="*")? name=ID;
grammar org.xtext.example.Entity
    with org.eclipse.xtext.common.Terminals            Meta model inference
generate entity
    "http://www.xtext.org/example/Entity"
                                              entity
Model:
  (types+=Type)*;
                                                                       Model
Type:
  TypeDef | Entity;
                                                                          types
TypeDef:                                                                *
                                                                    Type
  "typedef" name=ID
                                                                 name: EString
  ("mapsto" mappedType=JAVAID)?;
                                                                                                superEntity
JAVAID:
  name=ID("." ID)*;                                      TypeDef                    Entity


Entity:                                       mappedType                                attributes
  "entity" name=ID
                                                                                  Attribute
  ("extends" superEntity=[Entity])?                       JAVAID
                                                                               name: EString
  "{"                                                  name: EString
                                                                               many: EBoolean
    (attributes+=Attribute)*
  "}";                                                                                  type

Attribute:
  type=[Type] (many?="*")? name=ID;
grammar org.xtext.example.Entity
    with org.eclipse.xtext.common.Terminals            Meta model inference
generate entity
    "http://www.xtext.org/example/Entity"
                                              entity            Alternatives -> Hierarchy
Model:
  (types+=Type)*;
                                                                       Model
Type:
  TypeDef | Entity;
                                                                          types
TypeDef:                                                                *
                                                                    Type
  "typedef" name=ID
                                                                 name: EString
  ("mapsto" mappedType=JAVAID)?;
                                                                                                superEntity
JAVAID:
  name=ID("." ID)*;                                      TypeDef                    Entity


Entity:                                       mappedType                                attributes
  "entity" name=ID
                                                                                  Attribute
  ("extends" superEntity=[Entity])?                       JAVAID
                                                                               name: EString
  "{"                                                  name: EString
                                                                               many: EBoolean
    (attributes+=Attribute)*
  "}";                                                                                  type

Attribute:
  type=[Type] (many?="*")? name=ID;
grammar org.xtext.example.Entity
    with org.eclipse.xtext.common.Terminals            Meta model inference
generate entity
    "http://www.xtext.org/example/Entity"
                                              entity
Model:
  (types+=Type)*;
                                                                       Model
Type:
  TypeDef | Entity;
                                                                          types
TypeDef:                                                                *
                                                                    Type
  "typedef" name=ID
                                                                 name: EString
  ("mapsto" mappedType=JAVAID)?;
                                                                                                superEntity
JAVAID:
  name=ID("." ID)*;                                      TypeDef                    Entity


Entity:                                       mappedType                                attributes
  "entity" name=ID
                                                                                  Attribute
  ("extends" superEntity=[Entity])?                       JAVAID
                                                                               name: EString
  "{"                                                  name: EString
                                                                               many: EBoolean
    (attributes+=Attribute)*
  "}";                                                                                  type

Attribute:
  type=[Type] (many?="*")? name=ID;
grammar org.xtext.example.Entity
    with org.eclipse.xtext.common.Terminals            Meta model inference
generate entity
    "http://www.xtext.org/example/Entity"
                                              entity               Assignment -> Feature
Model:
  (types+=Type)*;
                                                                       Model
Type:
  TypeDef | Entity;
                                                                          types
TypeDef:                                                                *
                                                                    Type
  "typedef" name=ID
                                                                 name: EString
  ("mapsto" mappedType=JAVAID)?;
                                                                                                superEntity
JAVAID:
  name=ID("." ID)*;                                      TypeDef                    Entity


Entity:                                       mappedType                                attributes
  "entity" name=ID
                                                                                  Attribute
  ("extends" superEntity=[Entity])?                       JAVAID
                                                                               name: EString
  "{"                                                  name: EString
                                                                               many: EBoolean
    (attributes+=Attribute)*
  "}";                                                                                  type

Attribute:
  type=[Type] (many?="*")? name=ID;
grammar org.xtext.example.Entity
    with org.eclipse.xtext.common.Terminals            Meta model inference
generate entity
    "http://www.xtext.org/example/Entity"
                                              entity
Model:
  (types+=Type)*;
                                                                       Model
Type:
  TypeDef | Entity;
                                                                          types
TypeDef:                                                                *
                                                                    Type
  "typedef" name=ID
                                                                 name: EString
  ("mapsto" mappedType=JAVAID)?;
                                                                                                superEntity
JAVAID:
  name=ID("." ID)*;                                      TypeDef                    Entity


Entity:                                       mappedType                                attributes
  "entity" name=ID
                                                                                  Attribute
  ("extends" superEntity=[Entity])?                       JAVAID
                                                                               name: EString
  "{"                                                  name: EString
                                                                               many: EBoolean
    (attributes+=Attribute)*
  "}";                                                                                  type

Attribute:
  type=[Type] (many?="*")? name=ID;
Demo 2
Building DSLs With Eclipse
Poll "Simple poll"

	 question "What's your name?" name

	   question "How do you feel today?" howareyou
	   	 () "Fine" fine
	   	 () "Great" great
	   	 () "Bad" bad
	   	 () "Not too bad" not2bad
	   	
	   	
	   question "What's your favourite food?" food
	   	 [] "Pizza" pizza
	   	 [] "Pasta" pasta
	   	 [] "Sushi" sushi
	   	 [] "Mexican" mexican
Building DSLs With Eclipse
Building DSLs With Eclipse
Building DSLs With Eclipse
Pimp My Write
Tooltips
                Scoping
  Outline
                           Label Provider
   Validation         Hyperlinking / Navigation
                                       AST
Code Formatting
                      Content Assist
            Folding
                               Quick Fix
     Datatype Converter
                              Parser
   Syntax Highlighting
Tooltips
                Scoping
  Outline

                      Hyperlinking / Navigation
                                       AST
Code Formatting
                      Content Assist
            Folding
                               Quick Fix
     Datatype Converter
                              Parser
   Syntax Highlighting
Tooltips
                Scoping
  Outline
                          Label Provider
   Validation         Hyperlinking / Navigation
                                       AST
Code Formatting
                      Content Assist
            Folding
                               Quick Fix
     Datatype Converter
                              Parser
   Syntax Highlighting
Conclusion
Abstraction
Use a DSL to develop your tools
Support
Newsgroup
Community Forum
Professional Support
Heiko     Sven       Moritz    Peter    Dennis     Jan        Patrick Sebastian   Michael     Knut
Behrens   Efftinge   Eysholdt   Friese   Hübner   Köhnlein   Schönbach Zarnekow     Clay     Wannheden

                                                                                   Individual
Building DSLs With Eclipse
Twitter: @xtext
http://www.xtext.org

More Related Content

PDF
Codegeneration With Xtend
KEY
Gwt and Xtend
PDF
Auto-GWT : Better GWT Programming with Xtend
PPT
JSConf: All You Can Leet
PDF
Activator and Reactive at Play NYC meetup
PDF
Class-based views with Django
PDF
Selenium cheat sheet
PDF
Workshop 8: Templating: Handlebars, DustJS
Codegeneration With Xtend
Gwt and Xtend
Auto-GWT : Better GWT Programming with Xtend
JSConf: All You Can Leet
Activator and Reactive at Play NYC meetup
Class-based views with Django
Selenium cheat sheet
Workshop 8: Templating: Handlebars, DustJS

What's hot (20)

PDF
KEY
jQuery - Tips And Tricks
PDF
Java Script Best Practices
PDF
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
PDF
Rails on Oracle 2011
PDF
QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"
PPTX
Omnisearch in AEM 6.2 - Search All the Things
PDF
JavaScript Unit Testing with Jasmine
PDF
Why Every Tester Should Learn Ruby
PPT
JavaScript Tutorial
PDF
SilverStripe CMS JavaScript Refactoring
PDF
Ten useful JavaScript tips & best practices
PDF
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
PDF
Core concepts-javascript
PPTX
JavaScript Basics and Trends
PPTX
Workshop 1: Good practices in JavaScript
PPTX
Akka in-action
PDF
QA Lab: тестирование ПО. Станислав Шмидт: "Self-testing REST APIs with API Fi...
PPTX
Java Annotations and Pre-processing
PDF
Testing your javascript code with jasmine
jQuery - Tips And Tricks
Java Script Best Practices
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails on Oracle 2011
QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"
Omnisearch in AEM 6.2 - Search All the Things
JavaScript Unit Testing with Jasmine
Why Every Tester Should Learn Ruby
JavaScript Tutorial
SilverStripe CMS JavaScript Refactoring
Ten useful JavaScript tips & best practices
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Core concepts-javascript
JavaScript Basics and Trends
Workshop 1: Good practices in JavaScript
Akka in-action
QA Lab: тестирование ПО. Станислав Шмидт: "Self-testing REST APIs with API Fi...
Java Annotations and Pre-processing
Testing your javascript code with jasmine
Ad

Similar to Building DSLs With Eclipse (20)

PDF
Jazoon 2010 - Building DSLs with Eclipse
PDF
Overcoming The Impedance Mismatch Between Source Code And Architecture
KEY
Domänenspezifische Sprachen mit Xtext
PDF
Building DSLs with Xtext - Eclipse Modeling Day 2009
KEY
Xbase - Implementing Domain-Specific Languages for Java
KEY
Xtext Eclipse Con
PDF
Textual Modeling Framework Xtext
PDF
Data access layer and schema definitions
PDF
20070329 Tech Study
PDF
Extending and scripting PDT
KEY
コードで学ぶドメイン駆動設計入門
PDF
Annotations in PHP: They Exist
PPT
Spring data
PDF
Annotations in PHP - ConFoo 2013
KEY
Enterprise Java Web Application Frameworks Sample Stack Implementation
PDF
DevLOVE Beautiful Development - 第一幕 陽の巻
PDF
A fresh look at graphical editing
PPTX
Building RESTful Java Applications with EMF
ZIP
MDSD with Eclipse @ JUG Hamburg
PDF
What every developer should know about EMF Compare
Jazoon 2010 - Building DSLs with Eclipse
Overcoming The Impedance Mismatch Between Source Code And Architecture
Domänenspezifische Sprachen mit Xtext
Building DSLs with Xtext - Eclipse Modeling Day 2009
Xbase - Implementing Domain-Specific Languages for Java
Xtext Eclipse Con
Textual Modeling Framework Xtext
Data access layer and schema definitions
20070329 Tech Study
Extending and scripting PDT
コードで学ぶドメイン駆動設計入門
Annotations in PHP: They Exist
Spring data
Annotations in PHP - ConFoo 2013
Enterprise Java Web Application Frameworks Sample Stack Implementation
DevLOVE Beautiful Development - 第一幕 陽の巻
A fresh look at graphical editing
Building RESTful Java Applications with EMF
MDSD with Eclipse @ JUG Hamburg
What every developer should know about EMF Compare
Ad

More from Peter Friese (20)

PDF
Building Reusable SwiftUI Components
PDF
Firebase & SwiftUI Workshop
PDF
Building Reusable SwiftUI Components
PDF
Firebase for Apple Developers - SwiftHeroes
PDF
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
PDF
async/await in Swift
PDF
Firebase for Apple Developers
PDF
Building Apps with SwiftUI and Firebase
PDF
Rapid Application Development with SwiftUI and Firebase
PDF
Rapid Application Development with SwiftUI and Firebase
PDF
6 Things You Didn't Know About Firebase Auth
PDF
Five Things You Didn't Know About Firebase Auth
PDF
Building High-Quality Apps for Google Assistant
PDF
Building Conversational Experiences with Actions on Google
PDF
Building Conversational Experiences with Actions on Google
PDF
What's new in Android Wear 2.0
PDF
Google Fit, Android Wear & Xamarin
PDF
Introduction to Android Wear
PDF
Google Play Services Rock
PDF
Introduction to Android Wear
Building Reusable SwiftUI Components
Firebase & SwiftUI Workshop
Building Reusable SwiftUI Components
Firebase for Apple Developers - SwiftHeroes
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
async/await in Swift
Firebase for Apple Developers
Building Apps with SwiftUI and Firebase
Rapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and Firebase
6 Things You Didn't Know About Firebase Auth
Five Things You Didn't Know About Firebase Auth
Building High-Quality Apps for Google Assistant
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google
What's new in Android Wear 2.0
Google Fit, Android Wear & Xamarin
Introduction to Android Wear
Google Play Services Rock
Introduction to Android Wear

Recently uploaded (20)

PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Mushroom cultivation and it's methods.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Machine Learning_overview_presentation.pptx
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Tartificialntelligence_presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
Teaching material agriculture food technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
Mushroom cultivation and it's methods.pdf
NewMind AI Weekly Chronicles - August'25-Week II
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation theory and applications.pdf
Heart disease approach using modified random forest and particle swarm optimi...
OMC Textile Division Presentation 2021.pptx
Assigned Numbers - 2025 - Bluetooth® Document
1. Introduction to Computer Programming.pptx
Spectroscopy.pptx food analysis technology
Machine Learning_overview_presentation.pptx
cloud_computing_Infrastucture_as_cloud_p
Machine learning based COVID-19 study performance prediction
Tartificialntelligence_presentation.pptx
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectral efficient network and resource selection model in 5G networks
Teaching material agriculture food technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Building DSLs With Eclipse

  • 1. Building DSLs with Eclipse Peter Friese, itemis @peterfriese @xtext (c) 2009 Peter Friese. Distributed under the EDL V1.0 - http://www.eclipse.org/org/documents/edl-v10.php More info: http://www.peterfriese.de / http://www.itemis.com
  • 7. What is a DSL?
  • 19. You’d want to core an apple...
  • 20. ... for your kids.
  • 21. ? Right tool for the job?
  • 22. Your trusty swiss army knife!
  • 23. Because you can use it for other stuff, too. E.g., opening a bottle of wine.
  • 25. You’d want to core a few more apples...
  • 26. ... for an apple cake.
  • 27. Still the best tool for the job?
  • 32. ... a DSL is ...
  • 33. A specific tool for a specific job
  • 34. A specific tool for a specific job
  • 36. SQL
  • 37. select name, salary from employees where salary > 2000 order by salary
  • 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. <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>
  • 41. External or Internal
  • 43. Mailer.mail() .to(“you@gmail.com”) .from(“me@gmail.com”) .subject(“Writing DSLs in Java”) .body(“...”) .send();
  • 48. 1)Create ANTLR grammar 2)Generate lexer / parser 3)Parser will create parse tree 4)Transform parse tree to semantic model 5)Iterate model 6)Pass model element(s) to template
  • 52. Why not use a DSL... ... for building DSLs?
  • 56. @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); }
  • 57. @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); }
  • 58. entity CustomerInfo (id=CUST_ID, sequenceName=CUST_SEQ) { String emailAddress (notNull, length = 128) }
  • 59. entity CustomerInfo (id=CUST_ID, sequenceName=CUST_SEQ) { String emailAddress (notNull, length = 128) } Bean DAO (POJO)
  • 62. Model G ra m m ar
  • 63. ar Model m m ra G Generator
  • 64. ar Model m m ra G Generator Runtime Superclass Subclass Class LL(*) Parser ECore meta model Editor
  • 65. ar Model m m ra G Generator Runtime Superclass Subclass Class LL(*) Parser ECore meta model Editor
  • 66. Grammar (similar to EBNF) grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals generate entity "http://www.xtext.org/example/Entity" Model: (types+=Type)*; Type: TypeDef | Entity; TypeDef: "typedef" name=ID ("mapsto" mappedType=JAVAID)?; JAVAID: name=ID("." ID)*; Entity: "entity" name=ID ("extends" superEntity=[Entity])? "{" (attributes+=Attribute)* "}"; Attribute: type=[Type] (many?="*")? name=ID;
  • 67. grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals Meta model inference generate entity "http://www.xtext.org/example/Entity" entity Model: (types+=Type)*; Model Type: TypeDef | Entity; types TypeDef: * Type "typedef" name=ID name: EString ("mapsto" mappedType=JAVAID)?; superEntity JAVAID: name=ID("." ID)*; TypeDef Entity Entity: mappedType attributes "entity" name=ID Attribute ("extends" superEntity=[Entity])? JAVAID name: EString "{" name: EString many: EBoolean (attributes+=Attribute)* "}"; type Attribute: type=[Type] (many?="*")? name=ID;
  • 68. grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals Meta model inference generate entity "http://www.xtext.org/example/Entity" entity Rules -> Classes Model: (types+=Type)*; Model Type: TypeDef | Entity; types TypeDef: * Type "typedef" name=ID name: EString ("mapsto" mappedType=JAVAID)?; superEntity JAVAID: name=ID("." ID)*; TypeDef Entity Entity: mappedType attributes "entity" name=ID Attribute ("extends" superEntity=[Entity])? JAVAID name: EString "{" name: EString many: EBoolean (attributes+=Attribute)* "}"; type Attribute: type=[Type] (many?="*")? name=ID;
  • 69. grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals Meta model inference generate entity "http://www.xtext.org/example/Entity" entity Model: (types+=Type)*; Model Type: TypeDef | Entity; types TypeDef: * Type "typedef" name=ID name: EString ("mapsto" mappedType=JAVAID)?; superEntity JAVAID: name=ID("." ID)*; TypeDef Entity Entity: mappedType attributes "entity" name=ID Attribute ("extends" superEntity=[Entity])? JAVAID name: EString "{" name: EString many: EBoolean (attributes+=Attribute)* "}"; type Attribute: type=[Type] (many?="*")? name=ID;
  • 70. grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals Meta model inference generate entity "http://www.xtext.org/example/Entity" entity Alternatives -> Hierarchy Model: (types+=Type)*; Model Type: TypeDef | Entity; types TypeDef: * Type "typedef" name=ID name: EString ("mapsto" mappedType=JAVAID)?; superEntity JAVAID: name=ID("." ID)*; TypeDef Entity Entity: mappedType attributes "entity" name=ID Attribute ("extends" superEntity=[Entity])? JAVAID name: EString "{" name: EString many: EBoolean (attributes+=Attribute)* "}"; type Attribute: type=[Type] (many?="*")? name=ID;
  • 71. grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals Meta model inference generate entity "http://www.xtext.org/example/Entity" entity Model: (types+=Type)*; Model Type: TypeDef | Entity; types TypeDef: * Type "typedef" name=ID name: EString ("mapsto" mappedType=JAVAID)?; superEntity JAVAID: name=ID("." ID)*; TypeDef Entity Entity: mappedType attributes "entity" name=ID Attribute ("extends" superEntity=[Entity])? JAVAID name: EString "{" name: EString many: EBoolean (attributes+=Attribute)* "}"; type Attribute: type=[Type] (many?="*")? name=ID;
  • 72. grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals Meta model inference generate entity "http://www.xtext.org/example/Entity" entity Assignment -> Feature Model: (types+=Type)*; Model Type: TypeDef | Entity; types TypeDef: * Type "typedef" name=ID name: EString ("mapsto" mappedType=JAVAID)?; superEntity JAVAID: name=ID("." ID)*; TypeDef Entity Entity: mappedType attributes "entity" name=ID Attribute ("extends" superEntity=[Entity])? JAVAID name: EString "{" name: EString many: EBoolean (attributes+=Attribute)* "}"; type Attribute: type=[Type] (many?="*")? name=ID;
  • 73. grammar org.xtext.example.Entity with org.eclipse.xtext.common.Terminals Meta model inference generate entity "http://www.xtext.org/example/Entity" entity Model: (types+=Type)*; Model Type: TypeDef | Entity; types TypeDef: * Type "typedef" name=ID name: EString ("mapsto" mappedType=JAVAID)?; superEntity JAVAID: name=ID("." ID)*; TypeDef Entity Entity: mappedType attributes "entity" name=ID Attribute ("extends" superEntity=[Entity])? JAVAID name: EString "{" name: EString many: EBoolean (attributes+=Attribute)* "}"; type Attribute: type=[Type] (many?="*")? name=ID;
  • 76. Poll "Simple poll" question "What's your name?" name question "How do you feel today?" howareyou () "Fine" fine () "Great" great () "Bad" bad () "Not too bad" not2bad question "What's your favourite food?" food [] "Pizza" pizza [] "Pasta" pasta [] "Sushi" sushi [] "Mexican" mexican
  • 81. Tooltips Scoping Outline Label Provider Validation Hyperlinking / Navigation AST Code Formatting Content Assist Folding Quick Fix Datatype Converter Parser Syntax Highlighting
  • 82. Tooltips Scoping Outline Hyperlinking / Navigation AST Code Formatting Content Assist Folding Quick Fix Datatype Converter Parser Syntax Highlighting
  • 83. Tooltips Scoping Outline Label Provider Validation Hyperlinking / Navigation AST Code Formatting Content Assist Folding Quick Fix Datatype Converter Parser Syntax Highlighting
  • 86. Use a DSL to develop your tools
  • 88. Heiko Sven Moritz Peter Dennis Jan Patrick Sebastian Michael Knut Behrens Efftinge Eysholdt Friese Hübner Köhnlein Schönbach Zarnekow Clay Wannheden Individual

Editor's Notes

  • #4: itemis = IT + Themis Themis, goddess of justice order knows the future
  • #10: connect people share contact details your resume on the web (endorsements, who you know, what you&amp;#x2019;ve done)
  • #11: connect people / friends &amp;#x201C;friend&amp;#x201D; someone / &amp;#x201C;write on their wall&amp;#x201D; share photos fun-oriented
  • #12: connect people everybody can have their say
  • #18: Java = GPL You can do everything with Java But is it a good idea to do everything with Java?
  • #38: concise precise wouldn&amp;#x2019;t change anything
  • #40: ANT, built on a single transatlantic flight using XML to avoid writing own parser leverage XML parser today, we&amp;#x2019;d do it differently
  • #41: ANT, built on a single transatlantic flight using XML to avoid writing own parser leverage XML parser today, we&amp;#x2019;d do it differently
  • #45: It&amp;#x2019;s relatively easy to write an internal DSL
  • #46: Syntax of host language is the limiting factor for implementing internal DSLs
  • #50: External DSLs are very flexible - you can exactly adjust them to your needs
  • #51: You can choose the syntax of your DSL to your liking
  • #52: However, building external DSLs is complicated
  • #56: Java = GPL You can do everything with Java But is it a good idea to do everything with Java?
  • #121: Newsgroup Foren Prof. Support