This chapter covers the syntax of the Groovy programming language. The grammar of the language derives from the Java grammar, but enhances it with specific constructs for Groovy, and allows certain simplifications.

Comments

Single line comment

Multiline comment

JavaDoc comment

Shebang line

Keywords

Identifiers

Normal identifiers

Identifiers start with a letter, a dollar or an underscore. They cannot start with a number.

A letter can be in the following ranges:

  • a to z (lowercase ascii letter)

  • A to Z (uppercase ascii letter)

  • \u00C0 to \u00D6

  • \u00D8 to \u00F6

  • \u00F8 to \u00FF

  • \u0100 to \uFFFE

Then following characters can contain letters and numbers.

Here are a few examples of valid identifiers (here, variable names):

def name
def item3
def with_underscore
def $dollarStart

But the following ones are invalid identifiers:

def 3tier
def a+b
def a#b

Quoted identifiers

Strings

Single quoted string

Double quoted string

Triple single quoted string

Triple double quoted string

Slashy string

Dollar slashy string

Numbers

Integer literal

Floating point literal

Binary literal

Octal literal

Hexadecimal literal

Underscore in literal

Number type suffixes

Booleans

Arrays

Lists

Maps

String keys

Parenthesized keys