Skip to main content

Tree-Sitter parser for Ada

The grammar is adapted from the work done by Stephen Leak for the Emacs ada-mode. It was translated (partially for now) to tree-sitter syntax, and slightly changed to reduce some conflicts. Tree-sitter doesn't need a full syntax tree, so we can take some shortcuts in the grammar.

Installation

You will need neovim at least version 8.0 (not tested with earlier version).

Installation is very manual at this stage, until we can integrate this package inside nvim-treesitter itself. At the moment, assuming you are using lua configuration and Packer for your package management:

-- file: ~/.config/nvim/init.lua

--  Merge this with any existing Packer configuration you might already
--  have. This loads packer itself, then loads the new `ada.nvim` package.
require('packer').startup(function(use)
    use(require('mytreesitter.nvim'))
end)

Then create a new file to setup treesitter (or merge with an existing configuration of course).

--  file: ~/.config/nvim/mytreesitter.nvim

return {
   'nvim-treesitter/nvim-treesitter',
   requires = {
      'nvim-treesitter/nvim-treesitter-textobjects'
   },
   run=function()
      require('nvim-treesitter.install').update({ with_sync = true })
   end,
   config=function()

      --  Add support for our Ada parser

      local parsers = require "nvim-treesitter.parsers"
      local parser_config = parsers.get_parser_configs()
      parser_config.ada = {
         install_info = {
            url = "https://github.com/briot/tree-sitter-ada",
            files = {"src/parser.c"},
            generate_requires_npm = false,
            requires_generate_from_grammar = false,
         },
         filetype = "ada",
       }
   end,
}

Finally, we need to install the Ada parser with:

   :PackerSync                          " to install treesitter itself
   :TSInstall ada                       " to install Ada support

However, the above part only installs the parser itself (to generate a syntax tree from your source files). We now need to install queries, i.e. pattern matching against that tree to provide various capabilities like syntax highlighting, folding, indentation, smart textobject selection,...

For this, and until we can merge with nvim-treesitter itself, you will have to clone this github repository, then copy the queries/ directory to

  ~/.local/share/nvim/site/pack/packer/start/nvim-treesitter/queries/

Usage

Syntax highlighting

The above default configuration will replace the default regular expressions-based syntax highlighting in vim. Instead, the highlighting is based on the tree build every time you type something.

The default highlighting looks pretty much like the one from the standard Ada mode. However, the tree-based approach potentially opens the door for smart highlighting, like "Use a different background color for a subprogram specification", "show constant definitions in blue" or other high-level approaches.

WIP: document how users can do this in their own configuration files.
The current approach is to modify queries/highlights.scm

Potentially (though it seems to be disabled in neovim at the moment), the highlighting can also get smarter. Going back to the "show constants in blue" example above, the queries/locals.scm file adds a simple approach so that references to those constants can point to the definition, and therefore use the same blue highlighting.

Because neovim also has support for language servers (LSP), it is likely better to rely on the language server here.

Block folding

If you press za now, this will toggle the folding of the "current block". This is defined in queries/folds.scm, and currently knows about package specifications, package bodies, subprograms bodies, if statements and loops. Other semantic blocks could be added.

Smart Selection

The file queries/textobjects.scm defines a function textobjects, so that you can now use commands like

  • vaf (v)isually select (a) (f)unction or subprogram
  • vif (v)isually select (i)nside a (f)unction or subprogram
  • vai (v)isually select (a) (i)f statement (or loop)
  • vii (v)isually select (i)nside an (i)f statement (or loop)

Development

Execute the following commands:

   npm install
   npm run test

Documentation

The grammar itself is fully described in the file grammar.js. When it processes it, TreeSitter generates src/grammar.json, which can be converted to a EBNF format via https://github.com/mingodad/plgh/blob/main/json2ebnf.js and rendered into a diagram on https://www.bottlecaps.de/rr/ui if you prefer graphical visualization (you can also copy-paste from issue #1 a pre-processed version of grammar.json).

Metadata

Release files for tree-sitter-ada 0.9.1

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

Source distribution (sdist)

Source distribution for tree-sitter-ada 0.9.1
File Size Uploaded Provenance Actions
tree_sitter_ada-0.9.1.tar.gz 143.4 kB Without provenance Details for tree_sitter_ada-0.9.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for tree-sitter-ada 0.9.1
File Actions
tree_sitter_ada-0.9.1-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details for tree_sitter_ada-0.9.1-cp310-abi3-win_arm64.whl
tree_sitter_ada-0.9.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for tree_sitter_ada-0.9.1-cp310-abi3-win_amd64.whl
tree_sitter_ada-0.9.1-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for tree_sitter_ada-0.9.1-cp310-abi3-musllinux_1_2_x86_64.whl
tree_sitter_ada-0.9.1-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for tree_sitter_ada-0.9.1-cp310-abi3-musllinux_1_2_aarch64.whl
tree_sitter_ada-0.9.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64, Linux glibc 2.28+ ARM64 Details for tree_sitter_ada-0.9.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
tree_sitter_ada-0.9.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl CPython 3.10 abi3 Linux glibc 2.5+ x86-64, Linux glibc 2.28+ x86-64 Details for tree_sitter_ada-0.9.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
tree_sitter_ada-0.9.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for tree_sitter_ada-0.9.1-cp310-abi3-macosx_11_0_arm64.whl
tree_sitter_ada-0.9.1-cp310-abi3-macosx_10_9_x86_64.whl CPython 3.10 abi3 macOS 10.9+ x86-64 Details for tree_sitter_ada-0.9.1-cp310-abi3-macosx_10_9_x86_64.whl

Total release size: 754.9 kB

Release files / tree_sitter_ada-0.9.1.tar.gz

Download URL tree_sitter_ada-0.9.1.tar.gz
Size 143.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4d03b5903583c2f5f2b74c3fbba111fbd9ea45b75a2e485ac47ae72e4a1d646a
BLAKE2b-256 checksum
How to use checksums
118d492182aa32256db09f5482cfd9cd8d2ef90d92533a2cb4df25215ff6ecd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tree_sitter_ada-0.9.1-cp310-abi3-win_arm64.whl

Download URL tree_sitter_ada-0.9.1-cp310-abi3-win_arm64.whl
Size 66.0 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
444d9378a2ecf3a8ee4c9f03b90f280b42fafe8ce888c2133390f59fca2b2eb5
BLAKE2b-256 checksum
How to use checksums
f685d5cab1430cca7417c16bd6aa9f1650f5b14713ce5c5274eabfb0092abad9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tree_sitter_ada-0.9.1-cp310-abi3-win_amd64.whl

Download URL tree_sitter_ada-0.9.1-cp310-abi3-win_amd64.whl
Size 66.0 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
54dd3ce8c64eddb41a46a9b6eabeb32dd9a022ff2fde96a60d87eeae6b824e9e
BLAKE2b-256 checksum
How to use checksums
acab18a13f7bfdbd636c9976d068d72227a5923855adadc39bda69106118085e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tree_sitter_ada-0.9.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_ada-0.9.1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 86.5 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
56bcec618e60462fb55594a9f1ef6b72a32fa7f5824fa82114c834c3ae7d3ba5
BLAKE2b-256 checksum
How to use checksums
227e99f55a9d1770b24df5b67d22ebeb9a46967c41d7f424076ef1b0b806363b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tree_sitter_ada-0.9.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_ada-0.9.1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 87.9 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
5f992466326723495f052d544b0bf06925768ee192c57f4b038ebc550ae45c7c
BLAKE2b-256 checksum
How to use checksums
55423920be3e3cf39af98d007efaf5a265e414d63e23e44755378d3fcf3c25e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tree_sitter_ada-0.9.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_ada-0.9.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 88.7 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
5d315186b963e557cf1494cb09708ab9a7a822b1b0c23bd76ecf2d09bbf7393a
BLAKE2b-256 checksum
How to use checksums
37c476ca23807d90893e2cd653bc6bc2bbb0c0fc16f2dd921abe1b6543eb8025
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tree_sitter_ada-0.9.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL tree_sitter_ada-0.9.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 87.2 kB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 abi3
SHA-256 checksum
How to use checksums
cf1e8d98bda5785a526af74a2e0fba755af1f97bf1ec785d0f739e2c281f4948
BLAKE2b-256 checksum
How to use checksums
462d1edcde638777e48ec2a2e7cf7c4535af239071840b505f2574dd43eaf517
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tree_sitter_ada-0.9.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_ada-0.9.1-cp310-abi3-macosx_11_0_arm64.whl
Size 65.9 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7df7827fb93a94c43055da3ca2cadf37c2e2ff3ce49c9423fc5e53bb52b73312
BLAKE2b-256 checksum
How to use checksums
7ddc82ff6ff931fae48641a8c887070e2b28659f7c29ab549db7bbf1297d8928
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tree_sitter_ada-0.9.1-cp310-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_ada-0.9.1-cp310-abi3-macosx_10_9_x86_64.whl
Size 63.2 kB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
e406d78968a1aaaa8b71e7efd841c5ea69b1d9a8fb626b154babc09b816b26ec
BLAKE2b-256 checksum
How to use checksums
49504b868c6cfeb9684f86ab605dd2a849f800dec30de8c8d2323a9be93db01c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for tree-sitter-ada 0.9.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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