Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Groovy for Domain-Specific Languages, Second Edition
  • Table Of Contents Toc
  • Feedback & Rating feedback
Groovy for Domain-Specific Languages, Second Edition

Groovy for Domain-Specific Languages, Second Edition

By : Dearle
4.7 (3)
close
close
Groovy for Domain-Specific Languages, Second Edition

Groovy for Domain-Specific Languages, Second Edition

4.7 (3)
By: Dearle

Overview of this book

The times when developing on the JVM meant you were a Java programmer have long passed. The JVM is now firmly established as a polyglot development environment with many projects opting for alternative development languages to Java such as Groovy, Scala, Clojure, and JRuby. In this pantheon of development languages, Groovy stands out for its excellent DSL enabling features which allows it to be manipulated to produce mini languages that are tailored to a project’s needs. A comprehensive tutorial on designing and developing mini Groovy based Domain Specific Languages, this book will guide you through the development of several mini DSLs that will help you gain all the skills needed to develop your own Groovy based DSLs with confidence and ease. Starting with the bare basics, this book will focus on how Groovy can be used to construct domain specific mini languages, and will go through the more complex meta-programming features of Groovy, including using the Abstract Syntax Tree (AST). Practical examples are used throughout this book to de-mystify these seemingly complex language features and to show how they can be used to create simple and elegant DSLs. Packed with examples, including several fully worked DSLs, this book will serve as a springboard for developing your own DSLs.
Table of Contents (14 chapters)
close
close
Free Chapter
1
1. Introduction to DSLs and Groovy
13
Index

Named parameters


We have touched upon the concept of named parameters already. In a previous chapter, we looked at how Groovy allows us to construct a POGO by using a default built-in constructor that accepts a Map argument. We can construct a POGO by passing an inline Map object to the constructor. Groovy uses the map object to initialize each property of the POGO in turn. The map is iterated and the corresponding setter is invoked for each map element that is encountered:

class POGO {
    def a = 0
    def b = 0
    def c = 0
}

given:
    def pogo1 = new POGO(a:1, b:2, c:3)
    def pogo2 = new POGO( b:2, c:3)
    def pogo3 = new POGO(b:2, a:3)
expect:
    pogo1.a == 1
    pogo1.b == 2
    pogo1.c == 3
and:
    pogo2.a == 0
    pogo2.b == 2
    pogo2.c == 3
and:
    pogo3.a == 3
    pogo3.b == 2

When we pass a Map object to a constructor, the parentheses [] can be left out. We can also list the property values in any order we like. If a property is excluded, the corresponding setter will...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech

Create a Note

Modal Close icon
You need to login to use this feature.
notes
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Delete Note

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Edit Note

Modal Close icon
Write a note (max 255 characters)
Cancel
Update Note

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY