Skip to main content

Grammar for code tags like TODO:, FIXME(user): for the tree-sitter parsing library

Project description

tree-sitter-comment

CI

Tree-sitter grammar for comment tags like TODO:, FIXME(user):, etc. Useful to be embedded inside comments.

Check the playground at https://stsewd.dev/tree-sitter-comment/.

Syntax

Since comment tags aren't a programming language or have a standard, I have chosen to follow popular conventions for the syntax.

Comment tags

  • Comment tags can contain:
    • Upper case ascii letters
    • Numbers (can't start with one)
    • -, _ (they can't start or end with these characters)
  • Optionally can have an user linked to the tag inside parentheses ()
  • The name must be followed by : and a whitespace

URIs

  • http and https links are recognized

If you think there are other popular conventions this syntax doesn't cover, feel free to open a issue.

Examples

TODO: something needs to be done
TODO(stsewd): something needs to be done by @stsewd

XXX: fix something else.
XXX:    extra white spaces.

(NOTE: this works too).

NOTE-BUG (stsewd): tags can be separated by `-`
NOTE_BUG: or by `_`.

This will be recognized as a URI
https://github.com/stsewd/

FAQ

Can I match a tag that doesn't end in :, like TODO?

This grammar doesn't provide a specific token for it, but you can match it with this query:

("text" @todo
 (#eq? @todo "TODO"))

Can I highlight references to issues, PRs, MRs, like #10 or !10?

This grammar doesn't provide a specific token for it, but you can match it with this query:

("text" @issue
 (#match? @issue "^#[0-9]+$"))

;; NOTE: This matches `!10` and `! 10`.
("text" @symbol . "text" @issue
 (#eq? @symbol "!")
 (#match? @issue "^[0-9]+$"))

I'm using Neovim and don't see all tags highlighted

To avoid false positives, Neovim doesn't highlight all tags, but a list of specific ones, see the list at queries/comment/highlights.scm.

If you want your tag highlighted, you can extend the query locally, see :h treesitter-query. Or if you think it's very common, you can suggest it upstream.

Why C?

Tree-sitter is a LR parser for context-free grammars, that means it works great for grammars that don't require backtracking, or to keep a state for whitespaces (like indentation). For these reasons, parsing languages that need to keep a state or falling back to a general token, it requires some manual parsing in C.

Projects using this grammar

Other grammars

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_comment-0.3.0.tar.gz (14.9 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_comment-0.3.0-cp310-abi3-win_arm64.whl (11.6 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_comment-0.3.0-cp310-abi3-win_amd64.whl (12.9 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_comment-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl (21.8 kB view details)

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

tree_sitter_comment-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (23.0 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_comment-0.3.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.5 kB view details)

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

tree_sitter_comment-0.3.0-cp310-abi3-macosx_11_0_arm64.whl (10.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_comment-0.3.0-cp310-abi3-macosx_10_9_x86_64.whl (10.0 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_comment-0.3.0.tar.gz.

File metadata

  • Download URL: tree_sitter_comment-0.3.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tree_sitter_comment-0.3.0.tar.gz
Algorithm Hash digest
SHA256 89e4d2df4cfba95fae72c69f0c7571ebeb1b39e709b24151b4816e71a6079a07
MD5 d552d466ee93f290b2dc6505b53fdd57
BLAKE2b-256 0540a2a2fb87508a8eb0b27b657a6584090fedd0337f174275627b6f2b7dfec6

See more details on using hashes here.

File details

Details for the file tree_sitter_comment-0.3.0-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_comment-0.3.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 0e063c5e5afb99c0b25480e76450664373bbc06572ecad038b640bb32aa2c58f
MD5 f39f41eb7a2f338fdc8456da58da4e7d
BLAKE2b-256 b4a657646ba7504990a467343d2af5eb105e699f6cceb73721dffdaeaf55f8ee

See more details on using hashes here.

File details

Details for the file tree_sitter_comment-0.3.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_comment-0.3.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 89acd198c7602dcdb2df7dcb93afd13a24957ad52e8f7e8f592baf4ae7a8b80a
MD5 dda43b0bb90541e9f3898a602ae1814a
BLAKE2b-256 e2ff74b995c85af195c7a427d8479326daa5be8d4934792dc5534ce7d439336f

See more details on using hashes here.

File details

Details for the file tree_sitter_comment-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_comment-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e05e791513073bdf4205e46b94fc246ed4802ea116ce5fd82b9084c641ae5531
MD5 9973cd1e4ef875b60ff40e0527cc185c
BLAKE2b-256 c2a7621b9b19a799cc0276fb9ef6b0b1e17bce74a170e41fe382df8b931bd220

See more details on using hashes here.

File details

Details for the file tree_sitter_comment-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_comment-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8aa53341821ccda6277762e652c5c779d7ecd4ea93d28f769142f8fef766eeae
MD5 b42cae53565d9370f2841078c9be691d
BLAKE2b-256 13fd58c6a7f1a8fc10625945e1fecfd9c180a415a5e79073058901e2c5312c55

See more details on using hashes here.

File details

Details for the file tree_sitter_comment-0.3.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_comment-0.3.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5cc4f782432526bc2466caa38e39b20003f6c18018caf062d9b69b77a2a215dd
MD5 1a84980f51d75d47558f2c19779bb937
BLAKE2b-256 1beb41258c6c7c5a0403784c290c3c1caf5bcd8789c6a35cbc00c5f7b9d3f4db

See more details on using hashes here.

File details

Details for the file tree_sitter_comment-0.3.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_comment-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 335eadac6d4b341a62ddb460d1c9fa3ea5c914083fabea4c59d43d6024bcb465
MD5 4ad2bf6f0a39c0c2475d656d73af6be7
BLAKE2b-256 c162de9e6bfa2c0f4f8943d15b0b0cb638cb56a2e1932cdec5ff23d9424751c7

See more details on using hashes here.

File details

Details for the file tree_sitter_comment-0.3.0-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_comment-0.3.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 12b50167e7454fd5189d6f73cc483306b2a8ba165947255a0c1e828dca6448ea
MD5 91fc1de379eb032b97c855e32c42058e
BLAKE2b-256 cf0ab021d8a7bd3fd1ecd008f9acc25d19329517091353892b0262ec95089c84

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