Xtext Webinar

Post on 11-May-2015

10,169 views 1 download

Tags:

description

Sven and I are going to classify Xtext compared to other concepts and frameworks and demonstrate its capabilities with a refined version of an example I presented in London the week before. After that we discuss the versatile possibilities for extending and customizing the framework and finish with an exciting outlook.

transcript

Eclipse Live Webinar on

Sven Efftinge, Heiko Behrens itemis

http://live.eclipse.org/node/705

What is Xtext?

DSLs - An Example

Underlying Technology

Advanced Topics

Questions & Answers

Agenda

What is

?

A Language Framework

Yet another Parser Generator?

JavaCC

Yet another Parser Generator?

JavaCCNo, it’s more than that!

How does Xtext relate to ...

IDE Meta-tooling Platform (IMP)

Dynamic Language Toolkit (DLTK)

How does Xtext relate to ...

IDE Meta-tooling Platform (IMP)

Dynamic Language Toolkit (DLTK)Xtext is more than that!

Is it a language workbench?

JetBrains Meta Programming System

Intentional Domain Workbench Microsoft Oslo

Is it a language workbench?

JetBrains Meta Programming System

Intentional Domain Workbench Microsoft Oslo

Yes, but it’s completely

text-based and open source!

Xtext is a complete environment for development of textual - programming languages and - domain-specific languages.

It is implemented in Java and is based on Eclipse, EMF, and Antlr.

Domain-Specific Language (DSL)

A DSL is a formal, processable language targeting at a specific viewpoint or

aspect of a software system.

Its semantics, flexibility and notation is designed in order to support working

with that viewpoint as good as possible.

Rd2-c2

,rook at d2 moves to c2.

Rd2-c2

Queen to c7.“”

Check.

Moves in Chess:

!ook at a1 moves to a5.

"ishop at c8 captures knight at h3.

# b1 x c3

$2 - g4

Piece

Piece

Piece

Square

Square

Square

Square

Action

Action

Action

Action

Destination

Destination

Destination

Destination

Rook a1 move a5

Bishop c8 capture h3 Knight

Knight b1 capture c3 Queen

Pawn g2 move g4

SourceDestinationPiece

Move

WhitePlayerBlackPlayer

Game«enum»

Piece*

"ishop at c8 captures knight at h3

" c8 x h3

Model (textfile)

White: "Mayfield"

Black: "Trinks"

pawn at e2 moves to e4

pawn at f7 moves to g5

K b1 - c3

f7 - f5

queen at d1 moves to h5

// 1-0

DEMO

Underlying Technology

Superclass

Subclass Class

ecore meta modelLL(*) Parser editor

Model

Grammar

Generator

Runtime

Java Persistence API (JPA)package templates;

import java.io.Serializable;

import java.util.*;

import javax.persistence.*;

@SuppressWarnings("serial")

@Entity

public class Customer implements Serializable {

! private Long id;

! private String name;

! private Address address;

! private Set<Order> orders = new HashSet<Order>();

! // No-arg constructor

! public Customer() {

! }

! @Id

! public Long getId() {

! ! return id;

! }

! public void setId(Long id) {

! ! this.id = id;

! }

! public String getName() {

! ! return name;

! }

! public void setName(String name) {

! ! this.name = name;

! }

! public Address getAddress() {

! ! return address;

! }

! public void setAddress(Address address) {

! ! this.address = address;

! }

! @OneToMany

! public Collection<Order> getOrders() {

! ! return orders;

! }

! public void setOrders(Set<Order> orders) {

! ! this.orders = orders;

! }

}

entity Customer {

! property name : String

! property address : Address

! property orders : Order[]

}

DEMO

Superclass

Subclass Class

ecore meta modelLL(*) Parser editor

Model

Grammar

Generator

Runtime

Generator Fragments

Composable

Code Generator

! generator is composed of “fragments”

! fragments can contribute to:

! Manifest.MF

! plugin.xml

! Guice modules

! Add your own fragments

Superclass

Subclass Class

ecore meta modelLL(*) Parser editor

Model

Grammar

Generator

Runtime

Googl

e G

uic

e

licensed by http://www.wordle.net/

licensed by http://www.wordle.net/

MyCustomLabelProvider

Dependency Injection with Googlee

!No dependency to concrete implementation

!No explicit construction

!Easy testing

!Easy composition

Configuration of Components in Xtext

/**

* used to register components to be used within the IDE.

*/

public class DomainmodelUiModule

! ! extends GeneratedDomainmodelUiModule {

!

! @Override

! public Class<? extends ILabelProvider> bindILabelProvider() {

! ! return MySpecialLabelProvider.class;

! }

}

DEMO

Advanced Topics

Integration with EMFmodeling

P R O J E C T

e c l i p s e

GMF EditorCode GeneratorAny EMF-based

Component

<<abstract>>

ResourceXMIResource XMI

XtextResource

Parser SerializerLinker

ScopeProviderValueConverter Formatter

XtextResource Text

Working with Xtext// initialization and setup (only needed in standalone mode)

new EntityStandaloneSetup().createInjectorAndDoEMFRegistration();

// standard EMF API usage

ResourceSet resourceSet = new ResourceSet();

Resource resource = resourceSet.getResource(uriToModelFile, true);

Model model = (Model) resource.getContents().get(0);

// print the name of all types to the console

for (Type type : model.getElements()) {

System.out.println(type.getName());

}

Eclipse Helios

•Model Index

•Grammar Mixins

•Base Language

•UI Features

Questions & Answers