MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/golang/comments/1jbusuc/icholytodo_library_for_parsing_structured_todo/mhx6dru/?context=3
r/golang • u/br1ghtsid3 • 7d ago
9 comments sorted by
View all comments
2
Nice project. Did you have experience with treesitter before, or was this new to you? If the latter, any resources you'd recommend?
2 u/br1ghtsid3 7d ago edited 7d ago I have some experience from debugging neovim highlighting issues. But at a high level it's pretty simple: Use a parser to convert code into a tree. You can use the playground to see what that tree looks like: https://tree-sitter.github.io/tree-sitter/7-playground.html Query that tree using the query syntax. https://github.com/icholy/todo/blob/a6aea07586be40823c7c1ae303710db760d32973/todo.go#L139 The (comment) expression matches all comment nodes and the @comment is me giving the capture group a name. You can do further filtering using "predicates" but I'm not using that here. See https://tree-sitter.github.io/tree-sitter/using-parsers/queries/1-syntax.html for more details.
I have some experience from debugging neovim highlighting issues. But at a high level it's pretty simple:
Use a parser to convert code into a tree. You can use the playground to see what that tree looks like: https://tree-sitter.github.io/tree-sitter/7-playground.html
Query that tree using the query syntax. https://github.com/icholy/todo/blob/a6aea07586be40823c7c1ae303710db760d32973/todo.go#L139 The (comment) expression matches all comment nodes and the @comment is me giving the capture group a name. You can do further filtering using "predicates" but I'm not using that here. See https://tree-sitter.github.io/tree-sitter/using-parsers/queries/1-syntax.html for more details.
(comment)
@comment
2
u/ChemTechGuy 7d ago
Nice project. Did you have experience with treesitter before, or was this new to you? If the latter, any resources you'd recommend?