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.0.tar.gz (350.4 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.0-cp38-abi3-win_amd64.whl (113.8 kB view details)

Uploaded CPython 3.8+Windows x86-64

dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-win32.whl (113.1 kB view details)

Uploaded CPython 3.8+Windows x86

dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-musllinux_1_2_x86_64.whl (139.5 kB view details)

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

dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-musllinux_1_2_i686.whl (139.3 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (139.9 kB view details)

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

dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (140.5 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-macosx_11_0_arm64.whl (119.9 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7144385c8319c85b406d188f81d497c6599619593605b6d24df290e69f834aeb
MD5 218886b01f056cc22a19acc8f2ce21d4
BLAKE2b-256 f309b643d458b44e7a3d8bfea96af8a64789ff195557f6b57ea24284c46feed3

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.0.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.0-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c3d3542dc6d49982999da7fad33b710e0cbed48e69634fb16a9a7a8c93c57f5d
MD5 e3641fb42dc71ca4d045c9d7a896c36c
BLAKE2b-256 e2f6841169c752832d28c87aacf7057b7943d940947d26cd95065c33fa0c53ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.0-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.0-cp38-abi3-win32.whl.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 19b327863078faf0fe5902b0c5be613f8313c05cb81c081e421811970e31e943
MD5 770e4ea73bfb7e61c6b2ca697de61113
BLAKE2b-256 d2f73604b19a576a24d251e257b0616c163262307e305d3746de8e1452381ddd

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.0-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.0-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0b23b6f6d412c37d422768b29fc92b21570baea53621683f59eae19ba70d35a5
MD5 d64091ed970a9dd946b02c8e9f4e67d4
BLAKE2b-256 cdf029e648ca3d0251dfc48ab3df5b2020af83480c5cb0bf38607b6d64ae0cac

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.0-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.0-cp38-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 127650e50febb3596e756b9928698333227545af881fb6b168b83d0854f43af9
MD5 aaf8445aee09f174df85d331577bbcd3
BLAKE2b-256 ba02defb3295dc57cd98b202ea5e3bbaf120f07a292da5576960ab6c0f6dad06

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-musllinux_1_2_i686.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.0-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f71ceeaf2199e78ad5b9bc0eab8fab04bec430024415b6b38a9a788a50d44ca
MD5 22dd56b51ce6e61d645e3761ac6508c0
BLAKE2b-256 b855450feb0bdf8def06a89dad243b6672b9e44695187c33a5922dc19a42ca2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_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.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 78e99349da4159ec21dfc18125fd59425f98fb24526bfaa3da5662bf704e862f
MD5 4c042597986a767b8a46ada243c1cea1
BLAKE2b-256 9ad03b124d6f10f6c5f5c19fa1c32d7081484f137e554449f28719ce6f41caba

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.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.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dekobon_tree_sitter_groovy-0.2.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e66c7b9029131e95a4723203a182577b244e603460ee27780508a0e412ab482d
MD5 62c5593f4ec5a35ea042bccd577a46bb
BLAKE2b-256 9b2d2eb2e7b22101dc7bc249904c92d4127051bf81bd5a62ee1427e7cfb36cab

See more details on using hashes here.

Provenance

The following attestation bundles were made for dekobon_tree_sitter_groovy-0.2.0-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