Feature: support for Ada
Description
The Ada programming language is widely used in the avionics (DO-178C) and space industries. The following features would be a nice additions for StrictDoc:
- language-aware traceability for Ada
- support for the test report integration for tools like GNATtest
Problem
Solution
Additional Information
Hi @bw-bott,
This is a very nice feature request. The shortest path for implementing this will be to figure out whether there is a good tree-sitter grammar for the Ada language. If there is one then an implementation, could be mostly copy-and-pasted by similarity with the existing C/C++ and Python source code readers (they are based on the relevant tree-sitter grammars). If there is no such grammar, we would then need a capable general Python parser for Ada that understands its functions, comments and maybe other high-level syntactical constructs.
How strong is this user need? Would you be open to contributing this work yourself, or would you prefer that it is implemented by someone else, such as the core team or other contributors?
Hi @stanislaw
The shortest path for implementing this will be to figure out whether there is a good tree-sitter grammar for the Ada language.
forgive my ignorance, but I don't know what is a tree-sitter grammar.
How strong is this user need? Would you be open to contributing this work yourself, or would you prefer that it is implemented by someone else, such as the core team or other contributors?
Currently, the need is not so strong. We would like to do some experimentation in Ada on our job and we would like to manage it with StrictDoc, but it is something we will start in the coming weeks/months.
There's the Tree-Sitter parser for Ada, I'm not sure if you're referring to something like that.
but I don't know what is a tree-sitter grammar.
The existing source code parsers for Python/C/Robot are based on tree-sitter-based libraries:
- https://github.com/strictdoc-project/strictdoc/blob/main/strictdoc/backend/sdoc_source_code/reader_c.py
- https://github.com/strictdoc-project/strictdoc/blob/main/strictdoc/backend/sdoc_source_code/reader_robot.py
- https://github.com/strictdoc-project/strictdoc/blob/main/strictdoc/backend/sdoc_source_code/reader_python.py
Indeed, it looks like briot/tree-sitter-ada could do the job but it needs to be tried by someone. I will see if I could quickly create a basic MVP, maybe over this weekend, maybe not. Depending on how well the tree-sitter-ada is packaged, it could be a quick and easy win.
@haxtibal It looks like we need to add something similar for Ada, like you did for Robot here: https://github.com/Hubro/tree-sitter-robot/pull/10.
Could you summarize in this thread how you came up with that large diff – was it auto-generated, or did you have to manually create all those different language files?
@haxtibal It looks like we need to add something similar for Ada, like you did for Robot here: Hubro/tree-sitter-robot#10.
Could you summarize in this thread how you came up with that large diff – was it auto-generated, or did you have to manually create all those different language files?
It was mostly auto-generated. I tried to be explicit about what I did in the PR commit messages, reading them should give you a good idea.
Basically, running tree-sitter init generates binding code for various languages, including python (the essential for us). It also generates language specific build instructions in package.json, Cargo.toml and so on. Binding code is created from templates and only depends on project meta you have to enter (e.g. author name, name of the parser, ...) but not on the actual grammar.js. So it's easy to add them to a project in hindsight. However build instructions may need manual merge. E.g. tree-sitter-ada already has a package.json, so one needs to merge this with the auto-generated package.json.
After that, one should probably regenerate and update parser code. Because, if the tree-sitter version got bumped to >= 0.22 to be able to use tree-sitter init, the generated parser code will also be different. See tree-sitter-robot 380e40c.
Once the code is prepared, the project will also need to update github actions:
- test the new bindings, see e.g. tree-sitter-robot c8e15b4 and tree-sitter-robot f1fe163
- publish releases for the new bindings to crates.io, pypi, and so on. See tree-sitter-robot 70536bc and tree-sitter-robot ad5bcfb
There was as pitfall since py-tree-sitter did not understand the latest parser ABI version, so we had to downgrade with Hubro/tree-sitter-robot#11. But looks like tree-sitter/py-tree-sitter#333 got resolved very recently, so this may no longer be an issue.
If you're very indifferent on when this is done I could also offer to help creating the ada PR, but I'm short on time, could take several weeks until I get to it.
Hey @haxtibal, thanks a lot for sharing these instructions. I feel like I could also implement the Ada support now that you explained it but I am also blocked by working on the other things related to StrictDoc in July.
Let's agree that whoever gets to work on this first should report to this issue that the work has started.
@haxtibal @bw-bott
@stanislaw @bw-bott
I've started to work on bindings for the ada parser. It's not submitted upstream yet, but you can already play with it by cloning my fork and building it locally:
git clone -b tdmg/new_bindings https://github.com/haxtibal/tree-sitter-ada.git
cd tree-sitter-ada/
python -m build --wheel
python -m venv venv && . venv/bin/activate
pip install tree-sitter dist/tree_sitter_ada-0.1.0-cp310-abi3-linux_x86_64.whl
This minimal Python program works then
from tree_sitter import Language, Parser
import tree_sitter_ada
ada_language = Language(tree_sitter_ada.language())
parser = Parser(ada_language)
hello_world = """
with Ada.Text_IO;
procedure My_Hello_World is
begin
Ada.Text_IO.Put_Line ("Hello, World!");
end My_Hello_World;
"""
tree = parser.parse(bytes(hello_world, "utf8"))
Hello, after much help from your team, tree-sitter-ada is now published on Pypi, which I understand was the blocking point for you. Enjoy
Thanks a lot, @briot!
I have a couple of work items in my queue before I can get to integrating tree-sitter-ada with StrictDoc. If anyone else in this thread is willing to complete the integration before I get to it, you are very welcome, just let us know.
Hi, I develop Ada software following DO-178 level A. Strictdoc is awesome. If I understand correctly, without this feature for Ada it is not possible to link a requirement to a subprogram in a source file, and strictdoc won't be able to detect functions and evaluate "Functions covered by requirements" in source coverage report, right ?
Hello @oappere,
Thanks for asking. This ticket is precisely about parsing Ada source code into functions and source code comments with requirement markers. Thanks to the previous work by @briot and @haxtibal, a good 50% is already complete.
Both @haxtibal and I were quite blocked by working on other StrictDoc tasks in Q4 2025. Now that work is over, and I think Tobias was planning to first implement the Rust support (AFAIK it is WIP), and then get to implementing the Ada parser.
During the holidays, I am resolving several open feature requests and bugs reported by the users and probably will not have bandwidth to do this work myself.