Top Banner
Eclipse Live Webinar on Sven Efftinge, Heiko Behrens itemis http://live.eclipse.org/node/705
37

Xtext Webinar

May 11, 2015

Download

Technology

Heiko Behrens

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.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Xtext Webinar

Eclipse Live Webinar on

Sven Efftinge, Heiko Behrens itemis

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

Page 2: Xtext Webinar

What is Xtext?

DSLs - An Example

Underlying Technology

Advanced Topics

Questions & Answers

Agenda

Page 3: Xtext Webinar

What is

?

Page 4: Xtext Webinar

A Language Framework

Page 5: Xtext Webinar

Yet another Parser Generator?

JavaCC

Page 6: Xtext Webinar

Yet another Parser Generator?

JavaCCNo, it’s more than that!

Page 7: Xtext Webinar

How does Xtext relate to ...

IDE Meta-tooling Platform (IMP)

Dynamic Language Toolkit (DLTK)

Page 8: Xtext Webinar

How does Xtext relate to ...

IDE Meta-tooling Platform (IMP)

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

Page 9: Xtext Webinar

Is it a language workbench?

JetBrains Meta Programming System

Intentional Domain Workbench Microsoft Oslo

Page 10: Xtext Webinar

Is it a language workbench?

JetBrains Meta Programming System

Intentional Domain Workbench Microsoft Oslo

Yes, but it’s completely

text-based and open source!

Page 11: Xtext Webinar

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.

Page 12: Xtext Webinar

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.

Page 13: Xtext Webinar

Rd2-c2

Page 14: Xtext Webinar

,rook at d2 moves to c2.

Rd2-c2

Queen to c7.“”

Check.

Page 15: Xtext Webinar

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

Page 16: Xtext Webinar

Rook a1 move a5

Bishop c8 capture h3 Knight

Knight b1 capture c3 Queen

Pawn g2 move g4

SourceDestinationPiece

Move

WhitePlayerBlackPlayer

Game«enum»

Piece*

Page 17: Xtext Webinar

"ishop at c8 captures knight at h3

" c8 x h3

Page 18: Xtext Webinar

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

Page 19: Xtext Webinar

DEMO

Page 20: Xtext Webinar

Underlying Technology

Page 21: Xtext Webinar

Superclass

Subclass Class

ecore meta modelLL(*) Parser editor

Model

Grammar

Generator

Runtime

Page 22: Xtext Webinar

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[]

}

Page 23: Xtext Webinar

DEMO

Page 24: Xtext Webinar

Superclass

Subclass Class

ecore meta modelLL(*) Parser editor

Model

Grammar

Generator

Runtime

Generator Fragments

Page 25: Xtext Webinar

Composable

Code Generator

! generator is composed of “fragments”

! fragments can contribute to:

! Manifest.MF

! plugin.xml

! Guice modules

! Add your own fragments

Page 26: Xtext Webinar

Superclass

Subclass Class

ecore meta modelLL(*) Parser editor

Model

Grammar

Generator

Runtime

Googl

e G

uic

e

Page 27: Xtext Webinar

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

Page 28: Xtext Webinar

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

MyCustomLabelProvider

Page 29: Xtext Webinar

Dependency Injection with Googlee

!No dependency to concrete implementation

!No explicit construction

!Easy testing

!Easy composition

Page 30: Xtext Webinar

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;

! }

}

Page 31: Xtext Webinar

DEMO

Page 32: Xtext Webinar

Advanced Topics

Page 33: Xtext Webinar

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

Page 34: Xtext Webinar

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());

}

Page 35: Xtext Webinar

Eclipse Helios

•Model Index

•Grammar Mixins

•Base Language

•UI Features

Page 36: Xtext Webinar
Page 37: Xtext Webinar

Questions & Answers