Implementing Domain-Specific Languages with Xtext and Xtend
eBook - ePub

Implementing Domain-Specific Languages with Xtext and Xtend

  1. 342 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Implementing Domain-Specific Languages with Xtext and Xtend

Book details
Book preview
Table of contents
Citations

About This Book

In Detail

Xtext is an open source Eclipse framework for implementing domain-specific languages together with its IDE functionalities. It lets you implement languages really quickly, and, most of all, it covers all aspects of a complete language infrastructure, starting from the parser, code generator, interpreter, and more.

"Implementing Domain-Specific Languages with Xtext and Xtend" will teach you how to develop a DSL with Xtext, an Eclipse framework for implementing domain-specific languages. The chapters are like tutorials that describe the main concepts of Xtext such as grammar definition, validation, code generation, customizations, and many more, through uncomplicated and easy-to-understand examples.

Starting with briefly covering the features of Xtext that are involved in a DSL implementation, including integration in an IDE, the book will then introduce you to Xtend as this language will be used in all the examples throughout the book. We then proceed by explaining the main concepts of Xtext, such as validation, code generation, and customizations of runtime and UI aspects. By the end of the book, you will have learned how to test a DSL implemented in Xtext with Junit, in order to follow a test-driven development strategy that will help the developer implement maintainable code that is much faster and cleaner.

A test-driven approach is used throughout the book when presenting advanced concepts such as type checking and scoping. The book also shows you how to build and release a DSL so that it can be installed in Eclipse, and gives you hints on how to build the DSL headlessly in a continuous integration server.

"Implementing Domain-Specific Languages with Xtext and Xtend" aims to complement the official Xtext documentation to explain the main concepts through simplified examples and to teach the best practices for a DSL implementation in Xtext. It is a Beginner's Guide which should set you up for professional development DSL and its Eclipse IDE tooling.

Approach

A step-by-step guide that enables you to quickly implement a DSL with Xtext and Xtend in a test-driven way with the aid of simplified examples.

Who this book is for

This book is for programmers who want to learn about Xtext and how to use it to implement a DSL (or a programming language) together with Eclipse IDE tooling. It assumes that the user is familiar with Eclipse and its functionality. Existing basic knowledge of a compiler implementation would be useful, though not strictly required, since the book will explain all the stages of the development of a DSL.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Implementing Domain-Specific Languages with Xtext and Xtend by Lorenzo Bettini in PDF and/or ePUB format, as well as other popular books in Computer Science & Open Source Programming. We have over one million books available in our catalogue for you to explore.

Information

Year
2013
ISBN
9781782160304
Edition
1

Implementing Domain-Specific Languages with Xtext and Xtend


Table of Contents

Implementing Domain-Specific Languages with Xtext and Xtend
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Implementing a DSL
Domain Specific Languages
So, why should you create a new language?
Implementing a DSL
Parsing
The Abstract Syntax Tree (AST)
IDE integration
Syntax highlighting
Background parsing
Error markers
Content assist
Hyperlinking
Quickfixes
Outline
Automatic build
Summarizing DSL implementation
Enter Xtext
Installing Xtext
Let's try Xtext
The aim of this book
Summary
2. Creating Your First Xtext Language
A DSL for entities
Creating the project
Xtext projects
Modifying the grammar
Let's try the Editor
The Xtext generator
The Eclipse Modeling Framework (EMF)
Improvements to the DSL
Dealing with types
Summary
3. The Xtend Programming Language
An introduction to Xtend
Using Xtend in your projects
Xtend – a better Java with less "noise"
Extension methods
The implicit variable – it
Lambda expressions
Multi-line template expressions
Additional operators
Polymorphic method invocation
Enhanced switch expressions
Debugging Xtend code
Summary
4. Validation
Validation in Xtext
Default validators
Custom validators
Quickfixes
Textual modification
Model modification
Quickfixes for default validators
Summary
5. Code Generation
Introduction to code generation
Writing a code generator in Xtend
Integration with the Eclipse build mechanism
Standalone command-line compiler
Summary
6. Customizations
Dependency injection
Google Guice in Xtext
Customizations of IDE concepts
Labels
The Outline view
Customizing other aspects
Custom formatting
Other customizations
Summary
7. Testing
Introduction to testing
Junit 4
The ISetup interface
Implementing tests for your DSL
Testing the parser
Testing the validator
Testing the formatter
Testing code generation
Test suite
Testing the UI
Testing the content assist
Testing workbench integration
Testing the editor
Other UI testing frameworks
Testing and modularity
Clean code
Summary
8. An Expression Language
The Expressions DSL
Creating the project
Digression on Xtext grammar rules
The grammar for the Expressions DSL
Left recursive grammars
Associativity
Precedence
The complete grammar
Forward references
Typing expressions
Type provider
Validator
Writing an interpreter
Using the interpreter
Summary
9. Type Checking
SmallJava
Creating the project
SmallJava grammar
Rules for declarations
Rules for statements and syntactic predicates
Rules for expressions
The complete grammar
Utility methods
Testing the grammar
First validation rules
Checking cycles in class hierarchies
Checking member selections
Checking return statements
Checking for duplicates
Type checking
Type provider for SmallJava
Type conformance (subtyping)
Expected types
Checking type conformance
Checking method overriding
Improving the UI
Summary
10. Scoping
Cross-reference resolution in Xtext
Containments and cross-references
The index
Qualified names
Exported objects
The linker and the scope provider
Component interaction
Custom scoping
Scope for blocks
Scope for inheritance and member visibility
Visibility and accessibility
Filtering unwanted objects from the scope
Global scoping
Packages and imports
The index and the containers
Checking duplicates across files
Providing a library
Default imports
Using the library outside Eclipse
Using the library in the type system and scoping
Dealing with super
What to put in the index?
Additional automatic features
Summary
11. Building and Releasing
Release engineering
Headless builds
Target platforms
Continuous integration
Introduction to Buckminster
Installing Buckminster
Using the Xtext Buckminster wizard
Building the p2 repository from Eclipse
Customizations
Defining the target platform
Build headlessly
Maintaining the examples of this book
Summary
12. Xbase
Getting introduced with Xbase
The Expressions DSL with Xbase
Creating the project
The IJvmModelInferrer interface
Code generation
Debugging
The Entities DSL with Xbase
Creating the project
Defining attributes
Defining operations
Imports
Customizations
Summary
13. Bibliography
Index

Implementing Domain-Specific Languages with Xtext and Xtend

Copyright © 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: August 2013
Production Reference: 1140813
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78216-030-4
www.packtpub.com
Cover Image by Suresh Mogre ()

Credits

Author
Lorenzo Bettini
Reviewers
Dr. Jan Koehnlein
Henrik Lindberg
Pedro J. Molina
Sebastian Zarnekow
Acquisition Editor
James Jones
Lead Technical Editor
Neeshma Ramakrishnan
Technical Editors
Dipika Gaonkar
Anita Nayak
Sonali S. Vernekar
Project Coordinators
Shiksha Chaturvedi
Hardik Patel
Proofreader
Paul Hindle
Indexer
Rekha Nair
Graphics
Sheetal Aute
Ronak Dhruv
Abhinash Sahu
Production Coordinator
Aparna Bhagat
Kirtee Shingan
Cover Work
Aparna Bhagat

About the Author

Lorenzo Bettini is an assistant professor (Researcher) in computer science at Dipartimento di Informatica, UniversitĂ  di Torino, Italy. Previously, he was a Postdoc and a contractual researcher at Dipartimento di Sistemi e Informatica, UniversitĂ  di Firenze, Italy.
He has a Masters Degree in computer science and a PhD in theoretical computer...

Table of contents

  1. Implementing Domain-Specific Languages with Xtext and Xtend