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.2.0.tar.gz (14.8 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.2.0-cp310-abi3-win_arm64.whl (11.5 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_comment-0.2.0-cp310-abi3-win_amd64.whl (12.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_comment-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl (22.6 kB view details)

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

tree_sitter_comment-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (23.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_comment-0.2.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.3 kB view details)

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

tree_sitter_comment-0.2.0-cp310-abi3-macosx_11_0_arm64.whl (10.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_comment-0.2.0-cp310-abi3-macosx_10_9_x86_64.whl (10.2 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tree_sitter_comment-0.2.0.tar.gz
  • Upload date:
  • Size: 14.8 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.2.0.tar.gz
Algorithm Hash digest
SHA256 f43f42e11752565cd088dd6de3293b5334722533666edfc0fc820ac567f2e61d
MD5 c9f2e63d4ae1b0abbdc746920ed5ad9a
BLAKE2b-256 1815319d183a63b762f3f2b049a11755c223a9f0dfa5378dfc3983705d2d9754

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_comment-0.2.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 7b9e9a8cf3d5534264e98bb477bbd573557d5a4d4843c0a4f0782af4e6c5b2fc
MD5 0ffe5efdc3f29d594fe04a2ebf7c4079
BLAKE2b-256 7e1d3b95432cb5bb2a2c6766748f72df95a1008681afdbbba6b999603abc30d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_comment-0.2.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 50b79de98e18fbff90f52b397e50435caed12f25856aa62382cce4db3c008fe0
MD5 36f22a9e1b45a3c0a0d647ed99e7a61b
BLAKE2b-256 c0622b9006bddaf1eb9301cb0be401e1b6e5f501003616a84fbad027525362f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_comment-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f742279ce31cdecfbcc7ef384611af7cf71a778ba5418b87b86230918b1ba9ca
MD5 d9287bf2847375e1b496f3d9a3965991
BLAKE2b-256 aac7fb053d351ab107e3ab3d2f7a382c3d97455f1a4d2eec1ffe698ceb564b7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_comment-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6202d5c36a5ee8c2a2ec9d6466ee8b28b35bd7301dc8c4ec8b3427e6f546ffc6
MD5 47f68708a8202e5641334f66c1a7f94a
BLAKE2b-256 fa0b94fa24d7ec04400454cfd24a6d892e65c2d80b369093c70169048d70eb75

See more details on using hashes here.

File details

Details for the file tree_sitter_comment-0.2.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.2.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9a1a00a2ec4caa9c21ed093e7f5b2e59920613d49ee56198d2b092f5d992b490
MD5 4a77f851096403222f8795d321712fb5
BLAKE2b-256 f31bf9c59b9ad7c0616a711d105c274fe1840bc53ebc6070bc6bee278c52b0b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_comment-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3b1ebda92a964dc5c2ff1b146ef71d5c9308f95312203b396b89ceebe4b4e052
MD5 65eae0ce87e9ef8e03c7781ba7fe4730
BLAKE2b-256 f6b209537b6c8a036737358a5b17194ccfa4f03780f5c377755d43b9e02e50fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_comment-0.2.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a93115b331ac9fdc336684b0bfc4a91aab5f526d32c0537cafb55f3ff1e8591c
MD5 c6878ab6f32320078dbf22d4cccf23ac
BLAKE2b-256 8bdcb7920fad496fb355ec43bf88b0f6657f62f5162cd95acbecf4ad5fbd6785

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