Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to Xbase

948 views

Published on

Xtext makes it easy to define domain specific languages, but making your DSL a first class programming artifact with support for expressions and integration with Java is a hard thing if you do it from scratch. The Xbase library is an integral part of the Xtext framework. Xbase implements the bridge from DSLs to Java. It greatly simplifies your language implementation, if you want to run your DSL on the JVM. Xbase consists of a very powerful Java-like expression grammar and implements all the necessary infrastructure to link your DSL against existing Java types, compile it to executable code and validate it against the JVM specific constraints. In this session I want to explain how Xbase works under the covers and dive into its APIs. You will see, how to enhance your language and make it highly expressive and powerful without introducing an artificial gap to the Java platform. If you want your DSL to be a first class programming artifact, come to this session and see how to benefit best from Xbase.

  • Be the first to comment

Introduction to Xbase

  1. 1. Introduction to Xbase Holger Schill
  2. 2. What is
  3. 3. public class Customer implements Serializable { private String name; private Address address; private List<Phone> phones; public String getName() { return name; } public void setName(String name) { this.name = name; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } public List<Phone> getPhones() { return phones; } public void setPhones(List<Phone> phones) { this.phones = phones; } } bean Customer {
 name: String
 address: Address
 phones: Phone*
 }
  4. 4. @Entity public class Customer implements Serializable { @Id private String name; private Address address; private List<Phone> phones; public String getName() { return name; } public void setName(String name) { this.name = name; } @Column(name="ADDR", nullable=false) public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } @OneToMany public List<Phone> getPhones() { return phones; } public void setPhones(List<Phone> phones) { this.phones = phones; } } bean Customer {
 name: String
 address: Address
 phones: Phone*
 }
  5. 5. Grammar grammar org.xtext.example.BeanDsl with org.eclipse.xtext.xbase.Xbase generate beanDsl "http://www.xtext.org/example/BeanDsl" Root: beans+=Bean*; Bean: 'bean' name=ID '{' property+=Property* '}' ; Property: name=ID ':' (simpleType=TYPE | reference=[Bean]) list?='*'? ; enum TYPE: String | Int ;
  6. 6. Editor and much more…
  7. 7. Wouldn’t it be cool when…
  8. 8. Expressions would be directly in the DSL…
  9. 9. …with a typesystem
  10. 10. and debugging support
  11. 11. Typesystem Compiler / Interpreter Complex Syntax Expressions Debugging
  12. 12. Xbase Reusable expression language Access to Java-elements Typesystem Compiled to Java Interpreter …
  13. 13. Core Principles Common (JVM) Type Model DSLs with Expressions Scoping Validation ... Generator Java
  14. 14. DSL .class FileAST Type Model .java File (references) Core Principles
  15. 15. DSL .class FileAST .java File (references) Core Principles
  16. 16. .class File Derived Java
 Types
 .java File DSL AST Core Principles
  17. 17. DSL .class File .java File AST Derived Java
 Types
 Core Principles
  18. 18. DSL .java File .class File .java File Core Principles
  19. 19. DEMO
  20. 20. What about new Expressions
  21. 21. Create a new ParserRule Weave it into the Expression Tree Convince Antlr Compute the type for it Implement a compiler Ingredients
  22. 22. Create a new ParserRule Weave it into the Expression Tree Convince Antlr Compute the type for it Implement a compiler Ingredients Justkidding:-)
  23. 23. Extending the Xbase Type System Sebastian Zarnekow Today 13:00 - 13:50
  24. 24. THANKS

×