Skip to main content

tree-sitter-d2

Build Test

Table of Contents

Description

Tree Sitter grammar for d2lang (github). It's not yet finished, but usable for everyday cases with support for latest features like globs, filters and variables.

The goal is to provide a better experience for existing keywords, code blocks injections, folds, etc.

  • Better parsing of modern structures - The latest supported version of d2 is v0.7.0.
  • Built with nvim-treesitter in mind - We respect and follow its highlight groups.
  • Keywords - All keywords from the documentation are treated as such. (Open an issue if any are missing.)
  • Tests - We aim to cover all edge cases and examples from the documentation, resulting in more robust parsing. Currently, we have more than 100 tests. (This will be reduced later when the grammar becomes stable.)

I've never done anything remotely close to parsing grammar, so there could be some bad patterns and simply bad code. Feel free to open issues.

Installation

Neovim

via lazy.nvim

{
  "ravsii/tree-sitter-d2",
  dependencies = { "nvim-treesitter/nvim-treesitter" },
  build = "make nvim-install",
},

And then :TSInstall d2. After reloading Neovim everything should be working.

Helix

Fortunately Helix has its own guide on how to add new languages and grammars.

A quick example for installing d2 would be:

  1. Add a new language to languages.toml
[[language]]
name = "d2"
scope = "source.git"
file-types = ["d2"]
comment-token = "#"
roots = [""]
indent = { tab-width = 2, unit = "  " }

[[grammar]]
source = { git = "https://github.com/ravsii/tree-sitter-d2", rev = "main" }
name = "d2"
  1. hx --grammar fetch && hx --grammar build
  2. Add your queries to ~/.config/helix/runtime/queries/d2
~/.config/helix/runtime/queries/d2
├── highlights.scm
├── injections.scm
└── locals.scm

Other editors

If you're using some other editor that uses tree-sitter, please open an issue. Would be great if you could also provide instructions for others how to install it.

Showcase

Tokyo Night Storm theme with CaskaydiaCove font.

Props to Neovim's Tokyo Night theme for supporting pretty much every highlighting group.

https://github.com/user-attachments/assets/a9bd20d0-eb6c-43c2-8e58-7d211d350025

Contribution

See CONTRIBUTION.md

Comparison

Actually, there's another tree-sitter-d2 by pleshevskiy. My project's initial goal was to fix issues his grammar had, but later I realized that his grammar is not maintained and lacks many features d2 has added since then.

Here's a list of comparisons as of v0.2 version of this project, both using Tokyonight Storm theme.

Please note that:

  • On the left is our project using Neovim, on the right is pleshevskiy's grammar using Helix (I was unable to install pleshevskiy's grammar in Neovim)
  • Some examples are my random homework, thus being in Russian, please don't try to make sense of them. Thanks! :D

Better consistency overall

cmp1 cmp2

Better handling of foreign languages

cmpru1 cmpru2

Metadata

Release files for tree-sitter-d2 0.7.2

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-d2 0.7.2
File Size Uploaded Provenance Actions
tree_sitter_d2-0.7.2.tar.gz 33.9 kB Without provenance Details for tree_sitter_d2-0.7.2.tar.gz

Built distributions (wheels)

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

Total release size: 347.9 kB

Release files / tree_sitter_d2-0.7.2.tar.gz

Download URL tree_sitter_d2-0.7.2.tar.gz
Size 33.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6330479065e55bea8dc12291260d4d6cb4f01c6379c6cf6a5b53bfb1558a3426
BLAKE2b-256 checksum
How to use checksums
0fc9cab3185367c986df772ee440081cd11567fd64138a9cb1b9e8c4caee4a54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / tree_sitter_d2-0.7.2-cp39-abi3-win_arm64.whl

Download URL tree_sitter_d2-0.7.2-cp39-abi3-win_arm64.whl
Size 27.4 kB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
9d2beb6355b53ae621e17e0f34118436cb5670a303fded9dc177dcc52555133d
BLAKE2b-256 checksum
How to use checksums
597e4850e8ba85b40d9c825c0987315ba49a7327a0c02552b39b597e1c970353
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / tree_sitter_d2-0.7.2-cp39-abi3-win_amd64.whl

Download URL tree_sitter_d2-0.7.2-cp39-abi3-win_amd64.whl
Size 28.4 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
0645bc540a5d8a7e5e8ef01a0c991737904b0ecf44939115f7fd6a24107a77cf
BLAKE2b-256 checksum
How to use checksums
57e08dfa7756489043733fbdb31170eb0456f5c4bf3bb0d9e2cacfa1a95e7266
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / tree_sitter_d2-0.7.2-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_d2-0.7.2-cp39-abi3-musllinux_1_2_x86_64.whl
Size 50.3 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
83221c765d529e649d28f3834a9cdec660f609366f37ead725a55dbd61f8fd3c
BLAKE2b-256 checksum
How to use checksums
b70224f90d1396275ccc77a8196405bb927c73e3c98eff5f71b42baa238c7aa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / tree_sitter_d2-0.7.2-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_d2-0.7.2-cp39-abi3-musllinux_1_2_aarch64.whl
Size 49.0 kB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
a5b7cfb57d87bca314ab4bc9ce0024458b9622e7f085e6145f9a2d48fb2920fa
BLAKE2b-256 checksum
How to use checksums
67a490601fdf9e9c57168ff019a9a4d82e213472c8a9ae5ec1fd66d9175a9fed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / tree_sitter_d2-0.7.2-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_d2-0.7.2-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 50.3 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
112d0cc24d68d8ba587bf8b6558959b4c855d7c379137428f1348e29a8ac69fb
BLAKE2b-256 checksum
How to use checksums
5182d7a2789861f4b454ebb01b50820e80185e51a8475e0a4b7c7cda809984ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / tree_sitter_d2-0.7.2-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL tree_sitter_d2-0.7.2-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 51.4 kB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 abi3
SHA-256 checksum
How to use checksums
bbe07f8195976340547a54f6280d89ab6158cd7b4b84bff47ccdee5f709d91f4
BLAKE2b-256 checksum
How to use checksums
3049a7ff02a3dc1bb843c06917041e78821e74bce9bb4a7fbc494e34b8cb99c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / tree_sitter_d2-0.7.2-cp39-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_d2-0.7.2-cp39-abi3-macosx_11_0_arm64.whl
Size 28.5 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
bd70799263ad55d82dc3abc61a458246115a80b6a1b9b7fc0daa036d696f031e
BLAKE2b-256 checksum
How to use checksums
dbcc202f9d535b9d01f080c33f6fc90ca6849a01fcc282731e41d6d452d748a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / tree_sitter_d2-0.7.2-cp39-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_d2-0.7.2-cp39-abi3-macosx_10_9_x86_64.whl
Size 28.5 kB
Tags CPython 3.9 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
9fbb134314bd25388f1b7f996277e0af5fa6d016677f60e13f8a5bdc14dc8775
BLAKE2b-256 checksum
How to use checksums
6cce2abef9c9526ecb1dd3603e44c55ebd3a656abe8cd90f265f8aa44cc5d4f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for tree-sitter-d2 0.7.2

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