logo资料库

Implementing Domain-Specific Languages with Xtext and Xtend.pdf

第1页 / 共342页
第2页 / 共342页
第3页 / 共342页
第4页 / 共342页
第5页 / 共342页
第6页 / 共342页
第7页 / 共342页
第8页 / 共342页
资料共342页,剩余部分请下载后查看
Cover
Copyright
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Table of Contents
Preface
Chapter 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
Chapter 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
Chapter 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
Chapter 4: Validation
Validation in Xtext
Default validators
Custom validators
Quickfixes
Textual modification
Model modification
Quickfixes for default validators
Summary
Chapter 5: Code Generation
Introduction to code generation
Writing a code generator in Xtend
Integration with the Eclipse build mechanism
Standalone command-line compiler
Summary
Chapter 6: Customizations
Dependency injection
Google Guice in Xtext
Customizations of IDE concepts
Labels
The Outline view
Customizing other aspects
Custom formatting
Other customizations
Summary
Chapter 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
Chapter 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
Chapter 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
Chapter 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
Chapter 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
Chapter 13: 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
Bibliography
Index
Implementing Domain-Specific Languages with Xtext and Xtend Learn how to implement a DSL with Xtext and Xtend using easy-to-understand examples and best practices Lorenzo Bettini BIRMINGHAM - MUMBAI
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 (suresh.mogre.99@gmail.com)
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 science. His research interests cover design, theory, and the implementation of programming languages (in particular, object-oriented languages and network-aware languages). He has been using Xtext since version 0.7. He has used Xtext and Xtend for implementing many Domain Specific Languages and Java-like programming languages. He is also the author of about 60 papers published in international conferences and international journals. You can contact him at http://www.lorenzobettini.it.
Acknowledgement First of all, I would like to thank the main reviewers of this book, Jan Koehnlein, Henrik Lindberg, Pedro J. Molina, and Sebastian Zarnekow. Their constructive criticism, extensive suggestions, and careful error reporting helped extremely in improving the book. I also thank the additional reviewers, Marian Edu, Mayur Hule, and Neeshma Ramakrishnan. I'm also grateful to all the people from Packt I dealt with, Shiksha Chaturvedi, Amber Dsouza, James Jones, James Keane, Anita Nayak, Hardik Patel, Neeshma Ramakrishnan, and Sonali S. Vernekar. This book would not have been possible without the efforts that all the skilled Xtext developers have put in this framework. Most of them are always present in the Xtext forum and are very active in providing help to the users. Many other people not necessarily involved with Xtext development are always present in the forum and are willing to provide help and suggestions in solving typical problems about Xtext. They also regularly write on their own blogs about examples and best practices with Xtext. Most of the contents in this book is inspired by the material found on the forum and on such blogs. The list would be quite long, so I will only mention the ones with whom I interacted most: Meinte Boersma, Christian Dietrich, Moritz Eysholdt, Peter Friese, Dennis Huebner, Dr. Jan Koehnlein, Henrik Lindberg, Ed Merks, Alexander Nittka, Karsten Thoms, Hallvard Trætteberg, and Sebastian Zarnekow. A very special thanks to Sven Efftinge, the project lead for Xtext and Xtend, for creating Xtext. I'm also grateful to itemis Schweiz for sponsoring the writing of this book, and in particular, I'm thankful to Serano Colameo. Last but not least, a big thank you to my parents for always supporting me through all these years. A warm thank you to my Silvia, the "rainbow" of my life, for being there and for not complaining about all the spare time that this book has stolen from us.
About the Reviewers Dr. Jan Koehnlein is a core committer of the Xtext project and the Xtend language. He has several years of experience in model-driven software development and on the Eclipse platform. Jan is currently working as a consultant and software architect for itemis in Germany. Henrik Lindberg has worked for many companies since the early 80s, and he has had the opportunity to work with most aspects of software development from operating systems to applications as a developer, architect, CTO, and founder. He is currently CTO and founder of Cloudsmith Inc, a Puppet Labs Inc. partner specializing in services and tools for the creation, testing, and deployment of software stacks in local and cloud infrastructures. Prior to Cloudsmith, he ran the BEA/JRockit development office (now Oracle's JVM division). Henrik always had a passion for computer languages and parser technology, and he has worked with Eclipse Xtext on several projects, most recently the Puppet Language IDE called Geppetto. He is an Eclipse committer on Eclipse p2 and leads the Eclipse Buckminster and b3 projects. He is a frequent contributor to the Xtext forum. You can contact him on Twitter as @hel and also on the Eclipse and Puppet IRCs with the tag helindbe as well as on the Eclipse forums. I would like to thank Carl Barks and The Junior Woodchucks Guidebook that in an early Swedish edition contained a section with the Woodchucks Crypto—this inspired me to invent several written and spoken languages that I tried to teach my friends. This had limited success, we were after all only 7 years old.
Pedro J. Molina is a practitioner and researcher in the field of model-driven development. From his masters thesis in 1998 to his PhD in 2004, he worked on the research of conceptual user interface patterns for code generation on business applications and published more than 20 papers and 2 books. Within industry, he has been working for CARE Technologies developing commercial code generators and doing consultancy and software architecture for Capgemini. Nowadays, he is the chief architect officer for Icinetic, a firm building modeling and code generation tools with a strong focus on architecture. Pedro has been taking part in the program committee for Code Generation Conference for the last 7 years and keeps up-to-date with industrial MDD efforts. He maintains a blog: The Metalevel, where he talks about MDD and code-generation at http://pjmolina.com/metalevel.
分享到:
收藏