Domain specific languages in eclipse with Xtext (Zeus, UGent)

19
Domain Specific Languages in Eclipse with Xtext redefine.digital.design: Helping you deal with complexity in VHDL and Verilog. Dr. Ir. Hendrik Eeckhaut

Transcript of Domain specific languages in eclipse with Xtext (Zeus, UGent)

Page 1: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Domain Specific Languages in Eclipse with Xtext

redefine.digital.design: Helping you deal with complexity in VHDL and Verilog.

Dr. Ir. Hendrik Eeckhaut

Page 2: Domain specific languages in eclipse with Xtext (Zeus, UGent)

About

CTO at Sigasi @heeckhau

Sigasi Studio: Eclipse based IDE forVHDL and Verilog (digital hardware design)

Page 3: Domain specific languages in eclipse with Xtext (Zeus, UGent)

• Domain Specific Languages (DSL)

• Xtext

• Demo

Overview

Page 4: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Domain specific language

“A domain-specific language (DSL) isa computer language

specialized to a particular application domain”

Examples:

●Regular expressions: ^com.sigasi.*$

●SQL: SELECT * FROM table_name

https://en.wikipedia.org/wiki/Domain-specific_language

Page 5: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Cold beer

● Optimize energy efficiency● Lots of variants (size, components)● Cooling algorithms

○ Straight forward○ Exceptions and interactions○ Different for variants

Page 6: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Refrigerator control

Refrigerator description

Cooling algorithm

Code Generation

C-code

Documentation

Domain specificsimulator

http://www.voelter.de/data/presentations/RefrigeratorsAndDSLs.pdf

● Understand ?

● Validate ?

● Modify ?

● Develop ?

Page 7: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Why DSLs

DSLs allow to express solutions at theabstraction level of the problem domain.

⇒ Domain experts can understand, validate, modify and develop DSL programs

Page 8: Domain specific languages in eclipse with Xtext (Zeus, UGent)

How ?

Language definition (BNF)

Lexer and Parser

Abstract Syntax Tree

Linking, scoping, types

Validation

Code generator, interpreter

Page 9: Domain specific languages in eclipse with Xtext (Zeus, UGent)

DSL Development Framework

Full DSL infrastructure (parser, linker, …)

Define DSL with a grammar language

+ Rich editing support for Eclipse, IntelliJ IDEA and web browser

Page 10: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Rich editing

●Syntax coloring

●Type time validation

●Content assist (autocomplete)

●Code formatting

●Find references

●Rename

●Outline

●Hovers

●...

Page 11: Domain specific languages in eclipse with Xtext (Zeus, UGent)

How

Language definition (BNF)

Lexer and Parser

Abstract Syntax Tree

Linking, scoping, types

Validation

Code generator, interpreter

→ Xtext grammar

→ ANTLR

→ Eclipse EMF

(partially generated)Java

Page 12: Domain specific languages in eclipse with Xtext (Zeus, UGent)

To good to be true?

●Xtext contains default implementations for linking, validation, …

●Can be fully customized

●Wired together with Dependency Injection (Google Guice)

Page 13: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Demo

Small DSL to model entities and properties1. datatype String2. 3. entity Blog {4. title: String5. many posts: Post6. }7. 8. entity HasAuthor {9. author: String10. }11. 12. entity Post extends HasAuthor {13. title: String14. content: String15. many comments: Comment16. }17. 18. entity Comment extends HasAuthor {19. content: String20. }

Page 14: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Demo

1. datatype String2. 3. entity Blog {4. title: String5. many posts: Post6. }7. 8. entity HasAuthor {9. author: String10. }11. 12. entity Post extends HasAuthor {13. title: String14. content: String15. many comments: Comment16. }17. 18. entity Comment extends HasAuthor {19. content: String20. }

elements : Type(datatype or entity)

features : Feature

Domainmodel

Page 15: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Demo

1. datatype String2. 3. entity Blog {4. title: String5. many posts: Post6. }7. 8. entity HasAuthor {9. author: String10. }11. 12. entity Post extends HasAuthor {13. title: String14. content: String15. many comments: Comment16. }17. 18. entity Comment extends HasAuthor {19. content: String20. }

Page 16: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Live Demo

Page 17: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Why Xtext

Very mature and complete system

Statically typed AST model

Open Source

Page 18: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Outro

DSLs?

●Very powerful

●Lots of work

Xtext

●Recommended DSL development framework

Sigasi is hiring: www.sigasi.com/careers

Page 19: Domain specific languages in eclipse with Xtext (Zeus, UGent)

Hands on

Download Eclipse IDE for Java and DSL Developershttps://www.eclipse.org/downloads/

Start 15 Minutes tutorial from

https://eclipse.org/Xtext/documentation/102_domainmodelwalkthrough.html