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.
  • A { after new T(...) is always an anonymous class body -- Groovy instead calls a closure on the new object when the { starts a later line (outside parentheses and brackets) or cannot be a class body, so new ArrayList()\n{ list.add(1) } and new T() { x -> x } get an ERROR inside a class_body. Write new ArrayList().call { ... } to keep the call.
  • A { ... } straight after a field with no initializer is an instance initializer block -- int x { ... } parses with no ERROR. A record's compact constructor (public Name { ... }), which is unsupported, takes the same reading. After a field with an initializer a next-line { is that expression's trailing closure, as in Groovy: end the field with ; to get an initializer block.
  • sealed and trait are keywords where a class member can start -- a field or enum constant named sealed or trait is an ERROR when it follows a modifier (private boolean sealed) or opens the member (static trait = 1, enum E { trait }). boolean sealed and String trait, with no modifier, parse. record is not affected: it is a keyword only directly before a record header (record Name(), so private Record record and record.key() parse.

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.5.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.5.0
File Size Uploaded Provenance Actions
dekobon_tree_sitter_groovy-0.5.0.tar.gz 417.8 kB With provenance Details for dekobon_tree_sitter_groovy-0.5.0.tar.gz

Built distributions (wheels)

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

Total release size: 1.1 MB

Release files / dekobon_tree_sitter_groovy-0.5.0.tar.gz

Download URL dekobon_tree_sitter_groovy-0.5.0.tar.gz
Size 417.8 kB
Tags Source
SHA-256 checksum
How to use checksums
26850beeea47b45ad45c7d9496d7f60523f3d58cd990204d565be60d4c5876f0
BLAKE2b-256 checksum
How to use checksums
aaca3c9dc27ac5a963a10d5d50ac8c5efc9efccc9e4ec3fcace14ce2cba525ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 10, 2026.

Transparency log

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

Download URL dekobon_tree_sitter_groovy-0.5.0-cp311-abi3-win_amd64.whl
Size 128.5 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d0a7af363bb166941fcf2de2b7cf86bd5fa37ba3aee4c557c8e2703b789a2f81
BLAKE2b-256 checksum
How to use checksums
5c949074fdbd96fc943f4237ded504ab94410ee15fe4e73a3a4e6734de50f27e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 10, 2026.

Transparency log

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

Download URL dekobon_tree_sitter_groovy-0.5.0-cp311-abi3-win32.whl
Size 128.3 kB
Tags CPython 3.11 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
faf2619070d6f70215f662ac567c4eb631092365a3e887493060ee78ff6f7224
BLAKE2b-256 checksum
How to use checksums
e3e0066a73fe03ecaec28d155e957b654ed90cdd4d4110bce9c3d8fc7987b102
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 10, 2026.

Transparency log

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

Download URL dekobon_tree_sitter_groovy-0.5.0-cp311-abi3-musllinux_1_2_x86_64.whl
Size 155.9 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
d6e10527b37e2bc29a279709da859899e459ab71150b325ff2e15e5b4a727071
BLAKE2b-256 checksum
How to use checksums
22e6efa02728d271ea044eacc13305ed023d57993b28eb90eb01aedbd40d0392
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 10, 2026.

Transparency log

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

Download URL dekobon_tree_sitter_groovy-0.5.0-cp311-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 156.9 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
db2ca7e48150b666dad4cf2645d656c19a6941f63d06fac0e0a89c19c49fddba
BLAKE2b-256 checksum
How to use checksums
a42820230d2138eae221dd6dcf4eaa719ad1a7491f40b95dca35aab14d84b9ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 10, 2026.

Transparency log

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

Download URL dekobon_tree_sitter_groovy-0.5.0-cp311-abi3-macosx_11_0_arm64.whl
Size 136.9 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
050a774040ed6b56c861c4c41c87a1614a7aff8493c874c88a74a104f5729b78
BLAKE2b-256 checksum
How to use checksums
14b94d42c42ea0ba090f4157eea570a0d7152ddef5400c7ab2b168efc56c8a8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 10, 2026.

Transparency log

Security for dekobon-tree-sitter-groovy 0.5.0

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.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for dekobon_tree_sitter_groovy-0.5.0.tar.gz

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 Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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