Crates.io | tree-sitter-comment |
lib.rs | tree-sitter-comment |
version | 0.1.0 |
source | src |
created_at | 2023-06-04 02:41:54.250943 |
updated_at | 2023-06-04 02:41:54.250943 |
description | Grammar for code tags like TODO:, FIXME(user): for the tree-sitter parsing library |
homepage | https://stsewd.dev/tree-sitter-comment/ |
repository | https://github.com/stsewd/tree-sitter-comment |
max_upload_size | |
id | 881958 |
size | 57,378 |
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/.
Since comment tags aren't a programming language or have a standard, I have chosen to follow popular conventions for the syntax.
-
, _
(they can't start or end whit these characters)()
:
and a whitespaceIf you think there are other popular conventions this syntax doesn't cover, feel free to open a issue.
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/
:
, 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"))
#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]+$"))
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.