Skip to main content

Apache Groovy grammar for tree-sitter (dekobon fork)

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dekobon_tree_sitter_groovy-0.2.2.tar.gz (391.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-win_amd64.whl (119.7 kB view details)

Uploaded CPython 3.8+Windows x86-64

dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-win32.whl (119.0 kB view details)

Uploaded CPython 3.8+Windows x86

dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-musllinux_1_2_x86_64.whl (144.7 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (145.8 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-macosx_11_0_arm64.whl (126.5 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file dekobon_tree_sitter_groovy-0.2.2.tar.gz.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.2.tar.gz
Algorithm Hash digest
SHA256 37135bfeb372ab9a08d74e9062f39b9729f676ca4fb0cf0f5b483542b88e1c58
MD5 07c9033f20b31553762e99e85d54d1c7
BLAKE2b-256 c93af4c35c68d113850d0f821be32950effcadf82f2501a12a26a4522077c7c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.2.tar.gz:

Publisher: release.yml on dekobon/tree-sitter-groovy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 65672fa9417dd30ef9e8bda6ddef14d08e0e715468d9ff629d898c44439e78c5
MD5 cd3e40cdb7789da6b3189807dfee2f66
BLAKE2b-256 fdeb96eda2740c13d2206c6b9a130d07170b64f2b99ac9e8d88f185be530f489

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-win_amd64.whl:

Publisher: release.yml on dekobon/tree-sitter-groovy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-win32.whl.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 5863599d9f7dcfb899a053b0cffa0702d7fb46b3d26698d0796fa7c0a9a51ce4
MD5 35a9072e20ae1d17a6dea6e77674e895
BLAKE2b-256 f4a21c864020c564a85db8a046565733c980cfdd1662fad3a60510ac483394c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-win32.whl:

Publisher: release.yml on dekobon/tree-sitter-groovy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e736d8ea5f966a47d0957d8a8f305544649d2b6222c13ab74936b3c974326e02
MD5 43ecfc9a579685f252cb8bf5ed5fd204
BLAKE2b-256 8a96d672a891ea613afc3a70e2a309464d04ca0a4ddc7cb4dbb02d0aa39983cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on dekobon/tree-sitter-groovy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 70443e0265fe4da37c1ea5fa72303c77bd229371387f73f1e8ba87ba8854d674
MD5 bf362677084f0f9edeb722f2f57e4ffc
BLAKE2b-256 506fbdce2a3fef93cded4c6318db4529c4e1d3db9bab92802b5245dcf617f01f

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: release.yml on dekobon/tree-sitter-groovy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cd877037312551c792fbd1b0f1668523cdc93f24a9816860e9c348c60774cc74
MD5 c2c3073a10b2afb73bb0ab465dc8f15d
BLAKE2b-256 fd7a2d75b3cac1c50b3e49547c74c9cc5a68244490585909de854a2644640252

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.2-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on dekobon/tree-sitter-groovy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page