36
1 Extending Java And Developing DSLs With JetBrains MPS Konstantin Solomatov JetBrains Lead Developer for JetBrains MPS Project

Mps Presentation

Embed Size (px)

Citation preview

Page 1: Mps Presentation

1

Extending JavaAnd Developing DSLsWith JetBrains MPSKonstantin SolomatovJetBrainsLead Developer for JetBrains MPS Project

Page 2: Mps Presentation

Agenda

Extending languages. Why bother? Problems and solutions

Composability Language support

MPS’ approach Idea behind it Hands-on demo

MPS & domain-specific languages

2

Page 3: Mps Presentation

Why Bother?

Specific domains = specific entities Drawbacks of general-purpose languages:

Limited set of generic constructs Domains are described too verbosely Low code maintainability

Domain-specific extensions Higher abstraction level Higher maintainability

3

Page 4: Mps Presentation

Implicit Language Extensions

Domain-specific constructs in Java: synchronized block in Java enhanced for in Java typesafe enums in Java

Desired constructs: closures yield better support for regexps whatever else you are missing

4

Page 5: Mps Presentation

Language Extensions

Existing extensions Cover domain-specific needs Are built into existing languages

Further extensions Hard to integrate Too long to wait until JCP accepts them Risks of incompatibility

5

Page 6: Mps Presentation

MPS DEMO

Closure & UI Language samples.

6

Page 7: Mps Presentation

Agenda

Extending Languages. Why bother? Problems and Solutions

Composability Language support

MPS’ Approach Idea behind it Hands-on Demo

MPS & Domain-Specific Languages

7

Page 8: Mps Presentation

Composability

Definition:

Components are composable when they can be used together even if created by different parties

8

Page 9: Mps Presentation

ComposabilityDesired Goal

Java Libraries

Hibernate Spring Joda Time

Java Extensions

DB Language DI Language Dates Language

9

Page 10: Mps Presentation

ComposabilityLibraries vs. Extensions Libraries are composable:

Java + Hibernate => OK Java + Spring => OK Java + Hibernate, Spring => OK

Language extensions are not Java + extension A => OK Java + extension B => OK Java + extensions A, B => possible ambiguity

10

Page 11: Mps Presentation

ComposabilityGrammar Ambiguity Sample With String Interpolation Extension “A”:

int resultsCount = <some_code>;string s = “Found ${resultCount}

results”; Extension “B”:

int resultCount = <some_code>;string t = “Found {resultCount} results”;

“A” + “B” => ambiguity for the compiler:

string a = “Account balance is ${balance}”;

11

Page 12: Mps Presentation

Language SupportRequirements Generic infrastructure

Abstract grammar Type system Compiler Etc.

IDE infrastructure Editor Error highlighting Refactoring Version control Etc.

12

Page 13: Mps Presentation

Language SupportProblems Time- and resource-consuming task

Complicated algorithms for processing code Highly qualified developers required

Resulting infrastructure composability Type systems to be compatible with different

extensions Refactorings should support potential extensions Etc.

13

Page 14: Mps Presentation

Existing SolutionsPros & Cons

ComposabilityLanguage

Infrastructure

LISP Yes No

Internal DSLs in Ruby / Groovy Yes No

XText Framework No Yes

14

Page 15: Mps Presentation

Common Problem

Existing solutions provide: Either composable language extensions Or a decent infrastructure Not both

15

Page 16: Mps Presentation

Agenda

Extending Languages. Why bother? Problems and Solutions

Composability Language support

MPS’ Approach Idea behind it Hands-on Demo

MPS & Domain-Specific Languages

16

Page 17: Mps Presentation

Our Solution to the Problem

JetBrains MPS

Workbench for defining and extending languages

IDE for new languages and extensions

17

Page 18: Mps Presentation

Idea Behind It

Text-based grammars lead to ambiguities

Another approach needed

MPS works with Abstract Syntax Tree directly

18

Page 19: Mps Presentation

Idea Behind ItEditing Abstract Syntax Tree Former attempts

Diagram-based editing Limited domain of application

MPS solution Keeps user in habitual environment Supports text-like editing

19

Page 20: Mps Presentation

Idea Behind ItProjectional Editor

20

Each node of a syntax tree has its projection in the MPS Editor

Page 21: Mps Presentation

Idea Behind ItProjectional Editor

21

Each node – in a dedicated cell A node is shown in its text/symbol representation Instantly synchronized editor and syntax tree

Page 22: Mps Presentation

Idea Behind It Projection vs. Text Text-like projectional editor Has its pros & cons Reasonable learning curve: approx. 2 weeks

22

Page 23: Mps Presentation

MPS DEMO

Projectional editor in use.

23

Page 24: Mps Presentation

Idea Behind ItLanguage Support User-defined language infrastructure

Abstract grammar Type system Editor Compiler Etc.

Programming assistance Completion Find usages Rename Etc.

24

Page 25: Mps Presentation

Idea Behind It Existing Languages & Extensions Java™ re-implemented with MPS + Extensions

Collections language Dates language Closures language Regexp language Etc.

Language definition languages Implemented with themselves i.e. bootstrapped

Misc languages (XML, etc.)

25

Page 26: Mps Presentation

Hands-On DemoGoal

Java

ReadWriteLock l = …l.readLock().lock();try { //code} finally {

l.readLock().unlock();

}

Java + Extension

ReadWriteLock l = …read (l) { //code}

26

Page 27: Mps Presentation

Hands-On DemoWorkflow We will define

Structure Editor Typesystem Generator

27

Page 28: Mps Presentation

MPS DEMO

Adding lock statement to Java

28

Page 29: Mps Presentation

Agenda

Extending Languages. Why bother? Problems and Solutions

Composability Language support

MPS’ Approach Idea behind it Hands-on Demo

MPS & Domain-Specific Languages

29

Page 30: Mps Presentation

Domain-Specific Languages MPS suits nicely for creating DSLs

Common language parts can be reused(e.g., expression language)

You can embed general-purpose languages (e.g., Java) inside DSLs

30

Page 31: Mps Presentation

Domain-Specific LanguagesExample

31

Page 32: Mps Presentation

Existing Applications

Charisma – bug tracking system Completely developed with MPS Used internally EAP program

Languages for Web Development DNQ Webr Spring language

32

Page 33: Mps Presentation

Licensing/Pricing

Almost fully open-sourced Apache 2.0 License

MPS is absolutely FREE

33

Page 34: Mps Presentation

Q & A

34

Page 35: Mps Presentation

More info

http://www.jetbrains.com/mps - MPS pagehttp://blogs.jetbrains.com/mps - MPS blog

35

Page 36: Mps Presentation

36

Konstantin [email protected]

Lead Developer for JetBrains MPS Projecthttp://www.jetbrains.com/mps

Thank You