Your SlideShare is downloading. ×
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
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

Pragmatic DSL Design with Xtext, Xbase and Xtend 2

15,100

Published on

Tutorial at EclipseCon 2011 (Santa Clara) …

Tutorial at EclipseCon 2011 (Santa Clara)
Sven Efftinge, Jan Koehnlein, Sebastian Zarnekow

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

No Downloads
Views
Total Views
15,100
On Slideshare
0
From Embeds
0
Number of Embeds
24
Actions
Shares
0
Downloads
384
Comments
0
Likes
19
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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. Pragmatic DSL Design withSven Efftinge (itemis) / Sebastian Zarnekow (itemis) / Jan Köhnlein (itemis)
    • 2. The plan for today :
    • 3. The plan for today :1. Xtext 2.0 What is Xtext and what’s new in 2.0? Hands-On : Develop a DSL.
    • 4. The plan for today :1. Xtext 2.0 What is Xtext and what’s new in 2.0? Hands-On : Develop a DSL.2. Xbase What’s that and why should I care? Hands-On : Play with it and integrate it in a DSL.
    • 5. The plan for today :1. Xtext 2.0 What is Xtext and what’s new in 2.0? Hands-On : Develop a DSL.2. Xbase What’s that and why should I care? Hands-On : Play with it and integrate it in a DSL.3. Xtend Yet another language? Are you serious? Hands-On :Write a codegenerator with Xtend.
    • 6. What is ?
    • 7. Eclipse Project
    • 8. IDE Framework
    • 9. Language Framework
    • 10. (Domain-Specific)Language Framework
    • 11. UsersUsers
    • 12. Eclipse IDE Framework (JFace Text, etc.)
    • 13. Java Development Tools (JDT)Eclipse IDE Framework (JFace Text, etc.)
    • 14. Java Development Tools (JDT)Eclipse IDE Framework (JFace Text, etc.)
    • 15. Java Development Tools (JDT)Eclipse IDE Framework (JFace Text, etc.) Eclipse Modeling Framework (EMF)
    • 16. Java Development Tools (JDT) Antlr Parser GeneratorEclipse IDE Framework (JFace Text, etc.) Eclipse Modeling Framework (EMF)
    • 17. is Highly Adaptable
    • 18. Advanced Language-Specific Editing Features by Default
    • 19. Advanced Language-Specific Editing Features by Default Syntax Coloring
    • 20. Advanced Language-Specific Editing Features by Default Syntax Coloring Wizards
    • 21. Advanced Language-Specific Editing Features by DefaultContent Assist Syntax Coloring Wizards
    • 22. Advanced Language-Specific Editing Features by DefaultContent Assist Syntax Coloring Code Folding Wizards
    • 23. Advanced Language-Specific Editing Features by DefaultContent Assist Find References Syntax Coloring Code Folding Wizards
    • 24. Advanced Language-Specific Editing Features by Default Global IndexingContent Assist Find References Syntax Coloring Code Folding Wizards
    • 25. Advanced Language-Specific Editing Features by Default Go To Declaration Global IndexingContent Assist Find References Syntax Coloring Code Folding Wizards
    • 26. Advanced Language-Specific Editing Features by Default Go To Declaration Global IndexingContent Assist Find References Syntax Coloring Code Folding Wizards Bracket Matching
    • 27. Advanced Language-Specific Editing Features by Default Go To Declaration Global IndexingContent Assist Find References Syntax Coloring Auto Editing Code Folding Wizards Bracket Matching
    • 28. Advanced Language-Specific Editing Features by Default Go To Declaration Global IndexingContent Assist Find References Syntax ColoringIncremental Builders Auto Editing Code Folding Wizards Bracket Matching
    • 29. Advanced Language-Specific Editing Features by Default Go To Declaration Global IndexingContent Assist Outline View Find References Syntax ColoringIncremental Builders Auto Editing Code Folding Wizards Bracket Matching
    • 30. Advanced Language-Specific Editing Features by Default Go To Declaration Global IndexingContent Assist Outline View Find ReferencesIncremental Builders Validation Syntax Coloring Auto Editing Code Folding Wizards Bracket Matching
    • 31. Advanced Language-Specific Editing Features by Default Go To Declaration Template Proposals Global IndexingContent Assist Outline View Find ReferencesIncremental Builders Validation Syntax Coloring Auto Editing Code Folding Wizards Bracket Matching
    • 32. Advanced Language-Specific Editing Features by Default Go To Declaration Template Proposals Global IndexingContent Assist Outline View Quick Fixes Find ReferencesIncremental Builders Validation Syntax Coloring Auto Editing Code Folding Wizards Bracket Matching
    • 33. Advanced Language-Specific Editing Features by Default Refactoring Go To Declaration Template Proposals Global IndexingContent Assist Outline View Quick Fixes Find ReferencesIncremental Builders Validation Syntax Coloring Auto Editing Code Folding Wizards Bracket Matching
    • 34. Advanced Language-Specific Editing Features by Default Refactoring Go To Declaration Template Proposals Global IndexingContent Assist Outline View Quick Fixes Find ReferencesIncremental Builders Validation Syntax Coloring Rich Hovers Auto Editing Code Folding Wizards Bracket Matching
    • 35. ... but there is a problem with external DSLs
    • 36. What aboutExpressions?
    • 37. Expressions are complicated !
    • 38. Protected Regions
    • 39. Protected Regions• generated and manually written code mixed up
    • 40. Protected Regions• generated and manually written code mixed up• manual deletion of artifacts
    • 41. Protected Regions• generated and manually written code mixed up• manual deletion of artifacts• platform dependent information
    • 42. Protected Regions• generated and manually written code mixed up• manual deletion of artifacts• platform dependent information• information is spreaded!
    • 43. Generation Gap Pattern
    • 44. Generation Gap Pattern technically required type hierarchies
    • 45. Generation Gap Pattern technically required type hierarchies additional complexity
    • 46. Generation Gap Pattern technically required type hierarchies additional complexity platform dependent information
    • 47. Generation Gap Pattern technically required type hierarchies additional complexity platform dependent information information spreaded!
    • 48. Black boxtarget language literals
    • 49. Black boxtarget language literals• bound to target platform
    • 50. Black boxtarget language literals• bound to target platform • no option for MDA friends
    • 51. Black boxtarget language literals• bound to target platform • no option for MDA friends• no tooling!
    • 52. Black boxtarget language literals• bound to target platform • no option for MDA friends• no tooling!• long turnarounds!
    • 53. base
    • 54. baseModern Expression Language
    • 55. baseModern Expression LanguageJVM-Integration
    • 56. baseModern Expression LanguageJVM-IntegrationStatically Typed
    • 57. baseModern Expression LanguageJVM-IntegrationStatically TypedHighly Reusable
    • 58. Your Language o.e.xtext.common.TerminalsEMF
    • 59. Your Language common.Types o.e.xtext.common.TerminalsJDT JVM EMF
    • 60. Your Language Xbase Ecore Xbase Grammar common.Types o.e.xtext.common.TerminalsJDT JVM EMF
    • 61. @Overrideprotected IScope createLocalVarScope(~) { if (context instanceof Operation) { IScope actualScope = super.createLocalVarScope(~); Operation operation = (Operation) context; return createScope(operation.getParams(), actualScope); } return super.createLocalVarScope(~);}
    • 62. Using Xbase
    • 63. Using XbaseMixin the Grammar
    • 64. Using XbaseMixin the GrammarJVM Model Inference
    • 65. Using XbaseMixin the GrammarJVM Model InferenceScoping
    • 66. Using XbaseMixin the GrammarJVM Model InferenceScopingType System
    • 67. Using XbaseMixin the GrammarJVM Model InferenceScopingType SystemCompiler / Interpreter
    • 68. A DSL for Generating Code
    • 69. Model Code Code Generator
    • 70. Model Code package base; public class Address { private String street; public String getStreet() { return street; } public void setStreet(String street) { this.street = street; } private String city; Code public String getCity() { return city; Generator } public void setCity(String city) { this.city = city; } private String state; public String getState() { return state; } public void setState(String state) { this.state = state; } private String postalCode; public String getPostalCode() { return postalCode; } public void setPostalCode(String postalCode) { this.postalCode = postalCode; } }
    • 71. BUT I CANDO THAT IN
    • 72. package example.codegen;import org.eclipse.xtext.common.types.JvmFormalParameter;import org.eclipse.xtext.common.types.JvmTypeReference;import org.eclipse.xtext.example.domainmodel.domainmodel.Entity;import org.eclipse.xtext.example.domainmodel.domainmodel.Feature;import org.eclipse.xtext.example.domainmodel.domainmodel.Operation;import org.eclipse.xtext.example.domainmodel.domainmodel.Property;public class JavaGenerator { public String compile(Entity e) { StringBuilder b = new StringBuilder(); b.append("package " + packageName(e) + "n"); b.append("n"); b.append("/**n"); b.append(" * Automatically generated. Direct modification is futile.n"); b.append(" */n"); b.append("public class ").append(e.getName()); if(e.getSuperType() != null) { b.append(" extends ").append(compile(e.getSuperType())); } b.append(" {n"); for(Feature f: e.getFeatures()) { if(f instanceof Property) feature((Property)f); else if(f instanceof Operation) feature((Operation)f); } b.append("}n"); return b.toString();
    • 73. package example.codegen;import org.eclipse.xtext.common.types.JvmFormalParameter;import org.eclipse.xtext.common.types.JvmTypeReference;import org.eclipse.xtext.example.domainmodel.domainmodel.Entity;import org.eclipse.xtext.example.domainmodel.domainmodel.Feature;import org.eclipse.xtext.example.domainmodel.domainmodel.Operation;import org.eclipse.xtext.example.domainmodel.domainmodel.Property;public class JavaGenerator { No Multiline public String compile(Entity e) { StringBuilder b = new StringBuilder(); String Literals b.append("package " + packageName(e) + "n"); b.append("n"); b.append("/**n"); b.append(" * Automatically generated. Direct modification is futile.n"); b.append(" */n"); b.append("public class ").append(e.getName()); if(e.getSuperType() != null) { b.append(" extends ").append(compile(e.getSuperType())); } b.append(" {n"); for(Feature f: e.getFeatures()) { if(f instanceof Property) feature((Property)f); else if(f instanceof Operation) feature((Operation)f); } b.append("}n"); return b.toString();
    • 74. public String compile(Entity e) { StringBuilder b = new StringBuilder(); b.append("package " + packageName(e) + "n"); b.append("n"); b.append("/**n"); b.append(" * Automatically generated. Direct modification is futile.n"); b.append(" */n"); b.append("public class ").append(e.getName()); if(e.getSuperType() != null) { b.append(" extends ").append(compile(e.getSuperType())); } b.append(" {n"); for(Feature f: e.getFeatures()) { if(f instanceof Property) feature((Property)f); Instanceof else if(f instanceof Operation) feature((Operation)f); Cascades } b.append("}n"); return b.toString(); } public String feature(Property property) { StringBuilder b = new StringBuilder(); String type = compile(property.getType()); String name = property.getName(); b.append("// property ").append(name).append("n"); b.append("private ").append(type).append(" ").append(name).append("n"); b.append("n"); b.append("public ").append(type).append("get").append(name).append("() {n"); b.append(" return ").append(name).append(";n");
    • 75. } b.append("}n"); return b.toString(); } public String feature(Property property) { StringBuilder b = new StringBuilder(); String type = compile(property.getType()); String name = property.getName(); b.append("// property ").append(name).append("n"); b.append("private ").append(type).append(" ").append(name).append("n"); b.append("n"); b.append("public ").append(type).append("get").append(name).append("() {n"); b.append(" return ").append(name).append(";n"); b.append("}n"); b.append("n"); b.append("public ").append("set").append(name) .append("(").append(type).append(" ").append(name).append("){n"); b.append(" this.").append(name).append(" = ").append(name).append(";n"); b.append("}n"); b.append("n"); return b.toString(); } Noisy String public String feature(Operation operation) { StringBuilder b = new StringBuilder(); Concatenation String name = operation.getName(); b.append("// operation ").append(name).append("n"); b.append(compile(operation.getType())).append(" ").append(name).append("("); boolean isFirst = true; for(JvmFormalParameter p: operation.getParams()) {
    • 76. Statically Typed
    • 77. Statically Xbase Typed Expressions
    • 78. « RICH STRINGS »
    • 79. POLYMORPHIC dispatch
    • 80. COMPILES TO
    • 81. DEPENDENCY@InjectION
    • 82. TOOLING
    • 83. Indigo - June 22nd

    ×