SlideShare ist ein Scribd-Unternehmen logo
1 von 90
Downloaden Sie, um offline zu lesen
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
What is a DSL?
Domain
Language
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
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?
Demo 1
@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)
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
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
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
Twitter: @xtext
http://www.xtext.org

Weitere ähnliche Inhalte

Was ist angesagt?

Testing your javascript code with jasmine
Testing your javascript code with jasmineTesting your javascript code with jasmine
Testing your javascript code with jasmine
Rubyc Slides
 

Was ist angesagt? (20)

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

Ähnlich wie Building DSLs With Eclipse

Ähnlich wie Building DSLs With Eclipse (20)

Jazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipseJazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with Eclipse
 
Overcoming The Impedance Mismatch Between Source Code And Architecture
Overcoming The Impedance Mismatch Between Source Code And ArchitectureOvercoming The Impedance Mismatch Between Source Code And Architecture
Overcoming The Impedance Mismatch Between Source Code And Architecture
 
Spine JS
Spine JSSpine JS
Spine JS
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using Room
 
Grammarware Memes
Grammarware MemesGrammarware Memes
Grammarware Memes
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++
 
Domänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit XtextDomänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit Xtext
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
 
Paintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp KrennPaintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp Krenn
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Xtext Eclipse Con
Xtext Eclipse ConXtext Eclipse Con
Xtext Eclipse Con
 
Einführung in TypeScript
Einführung in TypeScriptEinführung in TypeScript
Einführung in TypeScript
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to Space
 
Prototype Framework
Prototype FrameworkPrototype Framework
Prototype Framework
 
Implementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord modelsImplementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord models
 
API first with Swagger and Scala by Slava Schmidt
API first with Swagger and Scala by  Slava SchmidtAPI first with Swagger and Scala by  Slava Schmidt
API first with Swagger and Scala by Slava Schmidt
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
 

Mehr von Peter Friese

Mehr von Peter Friese (20)

Building Reusable SwiftUI Components
Building Reusable SwiftUI ComponentsBuilding Reusable SwiftUI Components
Building Reusable SwiftUI Components
 
Firebase & SwiftUI Workshop
Firebase & SwiftUI WorkshopFirebase & SwiftUI Workshop
Firebase & SwiftUI Workshop
 
Building Reusable SwiftUI Components
Building Reusable SwiftUI ComponentsBuilding Reusable SwiftUI Components
Building Reusable SwiftUI Components
 
Firebase for Apple Developers - SwiftHeroes
Firebase for Apple Developers - SwiftHeroesFirebase for Apple Developers - SwiftHeroes
Firebase for Apple Developers - SwiftHeroes
 
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in Swift
 
Firebase for Apple Developers
Firebase for Apple DevelopersFirebase for Apple Developers
Firebase for Apple Developers
 
Building Apps with SwiftUI and Firebase
Building Apps with SwiftUI and FirebaseBuilding Apps with SwiftUI and Firebase
Building Apps with SwiftUI and Firebase
 
Rapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and FirebaseRapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and Firebase
 
Rapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and FirebaseRapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and Firebase
 
6 Things You Didn't Know About Firebase Auth
6 Things You Didn't Know About Firebase Auth6 Things You Didn't Know About Firebase Auth
6 Things You Didn't Know About Firebase Auth
 
Five Things You Didn't Know About Firebase Auth
Five Things You Didn't Know About Firebase AuthFive 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 High-Quality Apps for Google AssistantBuilding High-Quality Apps for Google Assistant
Building High-Quality Apps for Google Assistant
 
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google
 
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on GoogleBuilding Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google
 
What's new in Android Wear 2.0
What's new in Android Wear 2.0What's new in Android Wear 2.0
What's new in Android Wear 2.0
 
Google Fit, Android Wear & Xamarin
Google Fit, Android Wear & XamarinGoogle Fit, Android Wear & Xamarin
Google Fit, Android Wear & Xamarin
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android Wear
 
Google Play Services Rock
Google Play Services RockGoogle Play Services Rock
Google Play Services Rock
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android Wear
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

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
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. What is a DSL?
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 16.
  • 17.
  • 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();
  • 47.
  • 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?
  • 53.
  • 55.
  • 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)
  • 60.
  • 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;
  • 75.
  • 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
  • 77.
  • 78.
  • 79.
  • 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
  • 89.

Hinweis der Redaktion

  1. itemis = IT + Themis Themis, goddess of justice order knows the future
  2. connect people share contact details your resume on the web (endorsements, who you know, what you&amp;#x2019;ve done)
  3. connect people / friends &amp;#x201C;friend&amp;#x201D; someone / &amp;#x201C;write on their wall&amp;#x201D; share photos fun-oriented
  4. connect people everybody can have their say
  5. Java = GPL You can do everything with Java But is it a good idea to do everything with Java?
  6. concise precise wouldn&amp;#x2019;t change anything
  7. 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
  8. 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
  9. It&amp;#x2019;s relatively easy to write an internal DSL
  10. Syntax of host language is the limiting factor for implementing internal DSLs
  11. External DSLs are very flexible - you can exactly adjust them to your needs
  12. You can choose the syntax of your DSL to your liking
  13. However, building external DSLs is complicated
  14. Java = GPL You can do everything with Java But is it a good idea to do everything with Java?
  15. Newsgroup Foren Prof. Support