Skip to main content

tree-sitter-groovy

CI CodeQL npm crates.io PyPI

Tree-sitter grammar for Apache Groovy — the JVM scripting language used in Jenkins pipelines, Gradle build files, and Spock test specifications.

Published as: @dekobon/tree-sitter-groovy on npm, dekobon-tree-sitter-groovy on crates.io and PyPI, github.com/dekobon/tree-sitter-groovy as a Go module / Swift package. The unscoped name belongs to the upstream comparison grammar linked below; the C library (no naming conflict) still ships as libtree-sitter-groovy.

This grammar is purpose-built for Groovy (it does not extend the tree-sitter-java grammar). It synthesises the best ideas from the two existing community grammars while closing every operator and statement gap they left open:

  • amaanq/tree-sitter-groovy — clean precedence table and shebang handling, but mis-shapes Groovy-specific syntax (Elvis ?:, safe navigation ?., spread operators, regex =~ / ==~, traits, exclusive ranges, identity === / !==, spaceship <=>, etc.) as Java-shaped parse trees.
  • murtaza64/tree-sitter-groovy — purpose-built for Groovy, broad operator coverage and slashy strings, but has open bugs around empty block comments, multi-catch, multi-assignment, enums, switch-arrow, and a pipeline-at-EOF constraint.

The full design is in SPECIFICATION.md.

Status

Fully functional Groovy 2.x--4.x parser with complete operator coverage, GString interpolation, generics, closures, command chains, and six language bindings. See Known limitations for deferred items.

Operator coverage

Every Groovy operator emits a distinct named node so downstream tooling can identify each by node kind alone — no MISSING-child inspection, no tree-shape heuristics. This is the contract that closes dekobon/big-code-analysis#246 (Elvis short-circuit counting) and dekobon/big-code-analysis#247 (all Groovy-specific operator gaps).

Category Operators
Arithmetic + - * / % ** ++ --
Relational < <= > >= == != <=> (spaceship)
Identity === !==
Regex =~ (find) ==~ (match)
Logical && || ! ==> (implication)
Bitwise & | ^ ~ << >> >>>
Conditional ? : (ternary) ?: (Elvis)
Assignment = += -= *= /= %= **= <<= >>= >>>= &= ^= |= ?= (Elvis assign)
Range .. ..< <.. <..<
Member access . ?. ??. (safe chain dot) *. (spread-dot) .& (method pointer) .@ (direct field) :: (method reference)
Subscript [] ?[] (safe index)
Spread *args *: (spread-map)
Membership in !in instanceof !instanceof
Coercion as

Editor support

Tree-sitter queries (queries/groovy/highlights.scm, folds.scm, indents.scm, injections.scm) are provided for editor integration. Slashy and dollar-slashy string bodies inject as regex for nested regex highlighting.

Recognized file extensions: .groovy, .gradle, .gvy, .gy, and Jenkinsfile.

Filetype detection

The repo ships ftdetect/groovy.lua and ftplugin/groovy.lua for Neovim. Neovim's built-in filetype detection already maps *.groovy, *.gradle, and the bare filename Jenkinsfile to filetype groovy; the shipped ftdetect/groovy.lua fills the gaps by mapping:

  • *.gvy and *.gy — declared in tree-sitter.json but not in Neovim's defaults.
  • *.jenkinsfile — uncommon (the canonical name is Jenkinsfile) but declared in tree-sitter.json and used by some teams as an editor-detection hook.
  • Jenkinsfile.* variants (Jenkinsfile.ci, Jenkinsfile.release, …) — common in repos with multiple pipelines, not handled by Neovim's built-in detection.

The existing ftplugin/groovy.lua then calls vim.treesitter.start(). Highlighting only renders once the parser binary and queries/groovy/highlights.scm are registered with nvim-treesitter (or equivalent) — without that, the start() call is a no-op and the buffer falls back to non-treesitter highlighting.

For files that don't match any of those (e.g. a hand-named build-pipeline with no extension), opt in with one of:

  • Modeline at the top of the file: // vim: set filetype=groovy :

  • Per-project autocmd in .nvim.lua (sourced after :cd into the project via Neovim's 'exrc'). Note vim.fn.getcwd() is evaluated when the autocmd is defined, so this snippet belongs in a per-project config, not a global init.lua:

    vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
      pattern = vim.fn.getcwd() .. "/jenkins/*",
      callback = function() vim.bo.filetype = "groovy" end,
    })
    

Other editors follow the same pattern: rely on built-in detection for the common extensions and override per-directory or via a header comment for the rest.

Building

npm install
make build
make test

Bindings

Available bindings: C, Go, Node.js, Python, Rust, Swift. See bindings/ for binding-specific READMEs and tests.

For Rust consumers:

[dependencies]
dekobon-tree-sitter-groovy = "0.1"
tree-sitter = "0.25"
let mut parser = tree_sitter::Parser::new();
let language = dekobon_tree_sitter_groovy::LANGUAGE;
parser.set_language(&language.into()).expect("Error loading Groovy parser");
let tree = parser.parse(source, None).unwrap();

Known limitations

These are documented in detail in docs/divergences-from-spec.md.

  • Groovy 5 contextual keywords (val, async, await, defer) are not yet exposed as keyword tokens. They parse as plain identifiers, matching Groovy 2.x--4.x compiler behavior.
  • Typed local declarations require an initializer -- String x is ambiguous with String(x) (method call). Use String x = ... or def x instead.
  • Leading-operator line continuation -- a\n+ b greedily joins as a + b rather than splitting into two statements. Idiomatic Groovy places continuation operators at the end of the previous line.

Contributing

See CONTRIBUTING.md for how to build, test, and submit changes. AGENTS.md covers project conventions (commit messages, versioning, validation gates) and SPECIFICATION.md is the authoritative grammar design document.

Acknowledgements

We are grateful for the work done in the murtaza64/tree-sitter-groovy and amaanq/tree-sitter-groovy. These projects served as inspiration for some of the approaches in this project

License

Dual-licensed under Apache License 2.0 or MIT.

Metadata

Release files for dekobon-tree-sitter-groovy 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dekobon-tree-sitter-groovy 0.3.0
File Size Uploaded
dekobon_tree_sitter_groovy-0.3.0.tar.gz 391.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for dekobon-tree-sitter-groovy 0.3.0
File
dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-win32.whl CPython 3.11 abi3 Windows x86-32 Details
dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details
dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl CPython 3.11 abi3 Linux glibc 2.5+ x86-64, Linux glibc 2.28+ x86-64 Details
dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details

Total release size: 1.0 MB

Release files / dekobon_tree_sitter_groovy-0.3.0.tar.gz

Download URL dekobon_tree_sitter_groovy-0.3.0.tar.gz
Size 391.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4d7e90588589dcb2dcf28605d7cd18956b02b3fa6a560db3b922c1543fd4b25a
BLAKE2b-256 checksum
How to use checksums
0439483424ea78d13e8ce4e47ae0454ab123473b8c1dd119e10f0904333dd896
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-win_amd64.whl

Download URL dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-win_amd64.whl
Size 119.1 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
ef370d8f34a4e4bd0206ecdbfcad8fcdffca92b765cc5470d4359add95ee373f
BLAKE2b-256 checksum
How to use checksums
fc71ae659c994e74c547c6d869176b02f062a2e4b4844dc82d05a29bde0e52fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-win32.whl

Download URL dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-win32.whl
Size 118.6 kB
Tags CPython 3.11 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
2af3cc69289a72b2108a3a950206cf211190a830115dfdeb6891a12bedda33c6
BLAKE2b-256 checksum
How to use checksums
105ed5494c63ec40feecade4a72fb7eb630940a8376c2bb34a77fda9c07d2d0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-musllinux_1_2_x86_64.whl
Size 144.7 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
ad4bb94bc7b5703d220af6dfc75d723b2658ad0307313a1f48bedd31d7e921d7
BLAKE2b-256 checksum
How to use checksums
85f582ca99ee2739f7273d800b68398afc9814bbc7b9642ba47bf1f7f9be3792
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 145.8 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 abi3
SHA-256 checksum
How to use checksums
079857c5ae742162ba1c39560a3ef024821f4fbd88a9f8a4211b54083e0ebceb
BLAKE2b-256 checksum
How to use checksums
c927f7f4a7cc6d4f69193616979e10c6e733ce68248851b5d447c2e5f843a540
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL dekobon_tree_sitter_groovy-0.3.0-cp311-abi3-macosx_11_0_arm64.whl
Size 126.5 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b345f3c68d8d018e3b3f7c276e182a7ce90d402f18e31144cea45ab44a91a50c
BLAKE2b-256 checksum
How to use checksums
cd76f2f8300c9c32dd275ffb10cf61b84787cd7422054772f90c2425c08ac9d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

6 release files

0.2.2

6 release files

0.2.1

6 release files

0.2.0

8 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page