embedding languages without breaking tools

45
Embedding Languages without Breaking Tools Lukas Renggli, Tudor Gîrba, Oscar Nierstrasz CHOOSE Swiss Group for Object-Oriented Systems and Environments

Upload: lukas-renggli

Post on 13-Dec-2014

4.269 views

Category:

Technology


1 download

DESCRIPTION

Domain-specific languages (DSLs) are increasingly used as embedded languages within general-purpose host languages. DSLs provide a compact, dedicated syntax for specifying parts of an application related to specialized domains. Unfortunately, such language extensions typically do not integrate well with the development tools of the host language. Editors, compilers and debuggers are either unaware of the extensions, or must be adapted at a non-trivial cost. We present a novel approach to embed DSLs into an existing host language by leveraging the underlying representation of the host language used by these tools. Helvetia is an extensible system that intercepts the compilation pipeline of the Smalltalk host language to seamlessly integrate language extensions. We validate our approach by case studies that demonstrate three fundamentally different ways to extend or adapt the host language syntax and semantics.

TRANSCRIPT

Page 1: Embedding Languages Without Breaking Tools

Embedding Languages without Breaking Tools

Lukas Renggli, Tudor Gîrba, Oscar Nierstrasz

CHOOSE Swiss Group forObject-OrientedSystems and Environments

Page 2: Embedding Languages Without Breaking Tools

Marco Zanoli, cc-by-sa, 2.5, www.wikipedia.de, 2006

Page 3: Embedding Languages Without Breaking Tools

Marco Zanoli, cc-by-sa, 2.5, www.wikipedia.de, 2006

Page 4: Embedding Languages Without Breaking Tools

Marco Zanoli, cc-by-sa, 2.5, www.wikipedia.de, 2006

Page 5: Embedding Languages Without Breaking Tools

§

§§

Marco Zanoli, cc-by-sa, 2.5, www.wikipedia.de, 2006

Page 6: Embedding Languages Without Breaking Tools

Language Engineering

Page 7: Embedding Languages Without Breaking Tools

Multiple Context Dependent Languages

Page 8: Embedding Languages Without Breaking Tools

Homogeneous Data Abstraction

Page 9: Embedding Languages Without Breaking Tools

Homogeneous Tool Integration

Page 10: Embedding Languages Without Breaking Tools

Existing Host Language

Page 11: Embedding Languages Without Breaking Tools

Context Specific Languages

with Homogeneous Tool Integration

Page 12: Embedding Languages Without Breaking Tools

Package Name

x = 1

y = 1 (2, 1)

(2, 2)(1, 2)

x = 2

y = 2

Page 13: Embedding Languages Without Breaking Tools

aBuilder row grow.aBuilder row fill.

aBuilder column grow.aBuilder column fill.

aBuilder x: 1 y: 1 add: (LabelShape new text: [ :each | each name ]; borderColor: #black; borderWidth: 1; yourself).aBuilder x: 1 y: 2 w: 2 h: 1 add: (RectangleShape new borderColor: #black; borderWidth: 1; width: 200; height: 100; yourself)

Package Name

x = 1

y = 1 (2, 1)

(2, 2)(1, 2)

x = 2

y = 2

Page 14: Embedding Languages Without Breaking Tools

row = grow.row = fill.

column = grow.column = fill.

(1 , 1) = label text: [ :each | each name ]; borderColor: #black; borderWidth: 1.

(1 , 2) - (2 , 1) = rectangle borderColor: #black; borderWidth: 1; width: 200; height: 100.

Package Name

x = 1

y = 1 (2, 1)

(2, 2)(1, 2)

x = 2

y = 2

Page 15: Embedding Languages Without Breaking Tools

AST Transformation

Page 16: Embedding Languages Without Breaking Tools

➊ Pidginsyntax ‧ vocabulary ‧ semantics

Page 17: Embedding Languages Without Breaking Tools

row = grow.row = fill.

column = grow.column = fill.

(1 , 1) = label text: [ :each | each name ]; borderColor: #black; borderWidth: 1.

(1 , 2) - (2 , 1) = rectangle borderColor: #black; borderWidth: 1; width: 200; height: 100.

Package Name

x = 1

y = 1 (2, 1)

(2, 2)(1, 2)

x = 2

y = 2

Page 18: Embedding Languages Without Breaking Tools

shape { cols: #grow, #fill; rows: #grow, #fill;}label { position: 1 , 1; text: [ :each | each name ]; borderColor: #black; borderWidth: 1;}rectangle { position: 1 , 2; colspan: 2; borderColor: #black; borderWidth: 1; width: 200; height: 100;}

Package Name

x = 1

y = 1 (2, 1)

(2, 2)(1, 2)

x = 2

y = 2

Page 19: Embedding Languages Without Breaking Tools

Custom ParserAST Transformation

Page 20: Embedding Languages Without Breaking Tools

➋ Creolesyntax ‧ vocabulary ‧ semantics

Page 21: Embedding Languages Without Breaking Tools

shape { cols: #grow, #fill; rows: #grow, #fill;}label { position: 1 , 1; text: [ :each | each name ]; borderColor: #black; borderWidth: 1;}rectangle { position: 1 , 2; colspan: 2; borderColor: #black; borderWidth: 1; width: 200; height: 100;}

Package Name

x = 1

y = 1 (2, 1)

(2, 2)(1, 2)

x = 2

y = 2

Page 22: Embedding Languages Without Breaking Tools

➌ Argotsyntax ‧ vocabulary ‧ semantics

Page 23: Embedding Languages Without Breaking Tools

Transactional Memory

Object Relationships

Page 24: Embedding Languages Without Breaking Tools

How does Helvetia work?

Page 25: Embedding Languages Without Breaking Tools

Traditional Smalltalk Compiler

Smalltalk

Parser

Semantic

Analysis

Bytecode

Generation

Executable

Code

Source

Code

<parse> <transform> <attribute> <bytecode>

Rules

Page 26: Embedding Languages Without Breaking Tools

Traditional Smalltalk Compiler

Smalltalk

Parser

Semantic

Analysis

Bytecode

Generation

Executable

Code

Source

Code

<parse> <transform> <attribute> <bytecode>

Rules

Page 27: Embedding Languages Without Breaking Tools

Traditional Smalltalk Compiler

Smalltalk

Parser

Semantic

Analysis

Bytecode

Generation

Executable

Code

Source

Code

<parse> <transform> <attribute> <bytecode>

Rules

Page 28: Embedding Languages Without Breaking Tools

... ...<complete> <highlight>

Traditional Smalltalk Compiler

Smalltalk

Parser

Semantic

Analysis

Bytecode

Generation

Executable

Code

Source

Code

<parse> <transform> <attribute> <bytecode>

Rules

Page 29: Embedding Languages Without Breaking Tools

<complete> <highlight>

Traditional Smalltalk Compiler

Smalltalk

Parser

Semantic

Analysis

Bytecode

Generation

Executable

Code

Source

Code

<parse> <transform> <attribute> <bytecode>

Rules

Pidgin path

Creole path

Argot path

... ...

Page 30: Embedding Languages Without Breaking Tools

‣ Conditional RuleReflection

‣ Source RuleParser, Regex

‣ AST RuleTree Matcher

Rule Types

Page 31: Embedding Languages Without Breaking Tools

Rule Actions

‣ Transformations

‣ Code blocks

‣ Call other rules

Page 32: Embedding Languages Without Breaking Tools

...<complete> <highlight>

Traditional Smalltalk Compiler

Smalltalk

Parser

Semantic

Analysis

Bytecode

Generation

Executable

Code

Source

Code

<parse> <transform> <attribute> <bytecode>

Rules

Page 33: Embedding Languages Without Breaking Tools

IV + VII = XI

Page 34: Embedding Languages Without Breaking Tools

Assignments and Swapping

Automaton

Asynchronous Calls

Brainfuck

Functional Language

Grammar Definition

Mondrian

Object Relationships

Pattern Matching

Positional Arguments

Quasiquoting and Unquoting

Regular Expression

Roman Numbers

SQL

Schematic Tables

String Interpolation

Transactional Memory

Tuple Spaces

[http://scg.unibe.ch/research/helvetia/examples]

Page 35: Embedding Languages Without Breaking Tools

Existing Host Language

Page 36: Embedding Languages Without Breaking Tools

Multiple ContextDependent Languages

Page 37: Embedding Languages Without Breaking Tools

Homogeneous Data Abstraction

Page 38: Embedding Languages Without Breaking Tools

Homogeneous Tool Integration

Page 40: Embedding Languages Without Breaking Tools

Traditional Smalltalk Compiler

Smalltalk

Parser

Semantic

Analysis

Bytecode

Generation

Executable

Code

Source

Code

<parse> <transform> <attribute> <bytecode>

Rules

Pidgin path

Creole path

Page 41: Embedding Languages Without Breaking Tools

Marco Zanoli, cc-by-sa, 2.5, www.wikipedia.de, 2006

Page 42: Embedding Languages Without Breaking Tools

Marco Zanoli, cc-by-sa, 2.5, www.wikipedia.de, 2006Marco Zanoli, cc-by-sa, 2.5, www.wikipedia.de, 2006

Page 43: Embedding Languages Without Breaking Tools

LanguageChange

LanguageConcern

LanguageScope

LanguageBox

*

*

*

*

L. Renggli, M. Denker, O. Nierstrasz. Language Boxes: Bending the Host Language with Modular Language Changes. In SLE 2009, Denver, Colorado, October 5-6, 2009, LNCS 5969 p. 274—293, Springer, 2009.

Page 44: Embedding Languages Without Breaking Tools