Skip to main content

Ada grammar for tree-sitter

Project description

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).

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

tree_sitter_ada-0.1.0.tar.gz (139.4 kB view details)

Uploaded Source

Built Distributions

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

tree_sitter_ada-0.1.0-cp310-abi3-win_arm64.whl (63.9 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_ada-0.1.0-cp310-abi3-win_amd64.whl (65.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_ada-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl (86.5 kB view details)

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

tree_sitter_ada-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl (87.1 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_ada-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (87.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

tree_sitter_ada-0.1.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (87.3 kB view details)

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

tree_sitter_ada-0.1.0-cp310-abi3-macosx_11_0_arm64.whl (64.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_ada-0.1.0-cp310-abi3-macosx_10_9_x86_64.whl (62.0 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_ada-0.1.0.tar.gz.

File metadata

  • Download URL: tree_sitter_ada-0.1.0.tar.gz
  • Upload date:
  • Size: 139.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tree_sitter_ada-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a6ae511f0b07dcc17f51489d3fb9d9701109f0be24626b9e5e366ed55876e5a4
MD5 749def02cea5f262f19c647b924db103
BLAKE2b-256 193001dd10a3406214169bdeedbf366f7ae68a4a94c98570400641ef98ee8a20

See more details on using hashes here.

File details

Details for the file tree_sitter_ada-0.1.0-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_ada-0.1.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 0f4bf4c56d8970723d592bb05e69c3fe0d62f4167d5b45ca9acecb9e552854d9
MD5 13136a397ed8b53c2205525ed9427a88
BLAKE2b-256 16e98136e62a525477425c03faa593fc04055ec0f8663ca0ae7bea27d780208b

See more details on using hashes here.

File details

Details for the file tree_sitter_ada-0.1.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_ada-0.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e4e5dd4219ebc7effb8e0d2e1f48b3bad0798996d881d5b7174e0cb7f41e9998
MD5 f10f939e64a2c09f4067b2622b92eccb
BLAKE2b-256 9d54633df85bfb0eb47ee643b9af4440514bac8436b08fd50589d31be5ae8a71

See more details on using hashes here.

File details

Details for the file tree_sitter_ada-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_ada-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 be5f3f4149faa32ba8ccdf55bc0180db347d0259fd4bdbc4325bfcc7929327ba
MD5 00981b5ac9f99986f663c9c5679d74dd
BLAKE2b-256 e3505678e902962860dac90d9c2171158a8dd74a9f1ad86bbc00af6b448999c9

See more details on using hashes here.

File details

Details for the file tree_sitter_ada-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_ada-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 60ff17286805fb8b96b6a2e7f34c24eeea2b6f73ebcac9b8fe059321a9a3ffdb
MD5 4968f243f5c6f881c08687d72366b934
BLAKE2b-256 e05a43a2c46a667f654082082d740c04a851522d546352c797fbb06c47d0b906

See more details on using hashes here.

File details

Details for the file tree_sitter_ada-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_ada-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 78b7856ac3dd09c91ec57b83927beded5428a9196cc5f50c6ecaf094f6dad300
MD5 d60331a2425a73c0361c1e1aa5ff7d87
BLAKE2b-256 ab98bac5cc7e6ac7cf509e2feadf365fe2354610a630ca89f58b4e8f2f4ca691

See more details on using hashes here.

File details

Details for the file tree_sitter_ada-0.1.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_ada-0.1.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 1072c727e2d5034eca561a5c61407a9772f723c5273b75af8a5207f6ff497936
MD5 44c1e2a32fe61174d302833084277984
BLAKE2b-256 3d789f8f8520fb9552e18f62beb47f4be1808f4524e6bca6a4701960ba0c588e

See more details on using hashes here.

File details

Details for the file tree_sitter_ada-0.1.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_ada-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6bc000417dd96e9cdac50cb57a16265cbb0bbd80cb845ba9c9cf9bf1027becc9
MD5 beb6556fd814830523ed6f98983f5bd4
BLAKE2b-256 be83f2f8071a57c173910ff0fe621cf67f03c439e620ea903fb18eca77cf5e5d

See more details on using hashes here.

File details

Details for the file tree_sitter_ada-0.1.0-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_ada-0.1.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ecb251b474e6e4db846c496e6c419a08b8496619d778199441a37dae45066691
MD5 c1095160b97f9333ebbad85254580e1a
BLAKE2b-256 40222eee221e9531ff80d181c8c8a7e68bbe6c2d7e7fdfff396ce9f4caf79418

See more details on using hashes here.

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