-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tree queries #16
Comments
Hi :) Your efforts are probably better spent on https://github.com/alaviss/tree-sitter-nim/tree/rewrite |
I saw that, I'll probably rewrite the queries for it once alaviss finishes (originally I wrote them for alaviss's first grammar). Yours is already quite comprehensive though, it looked like objects are the big thing missing? Did you manage to find any good documentation for tree-sitter when you were working on the grammar? I've been writing the queries by reading through other existing queries and grammars and sort of guessing how they should be written, for lack of anything better to base them off of: which hasn't worked terribly well. I've been having a particularly hard time with keywords: they have to line up with the grammar.js file somehow and I haven't quite figured out how. |
I've made issues describing the missing features. let a = (
echo "hi"
5
)
echo a
# prints
# hi
# 5 But there are also the arbitrary parentheses around expressions like let a = (1+1)*2 It's a pain to disambiguate those from tuples and function calls, but probably doable. Also another big issue is that the grammar.js is so big and complex now, that the resulting parser is absolutely enormous in size. What's pushed right now is 15MB large. When I added more things it grew to 28MB or something.
Can't say so. I haven't even written any queries myself. Your best bet is probably to take inspiration from preexisting code. The nvim-treesitter repo has a huge collection of queries you could probably learn a lot from those. |
TIL about par, I don't think I've ever seen that in practice. By any chance, do you know of a good way to throw this grammar at an example file to generate syntax trees like in |
Also, how do you build |
https://tree-sitter.github.io/tree-sitter/creating-parsers#command-parse This will parse the file and generate the AST. I don't know if this helps you but https://nim-lang.github.io/Nim/macros.html#treeRepr%2CNimNode This can give you the AST from parser of the Nim compiler If your questions was about good example files to parse: https://github.com/nim-lang/Nim/blob/devel/compiler/parser.nim How about this one?
https://tree-sitter.github.io/tree-sitter/creating-parsers#command-generate |
Thanks, I got tree-sitter dumping trees, which is pretty helpful. On further testing the highlighting doesn't work as well as I thought it did: there's a lot of edge cases, incorrect tree representations, and occasional errors (mostly around type declarations). It's still better than no highlighting though... |
If it's just about highlights in neovim, I am using this plugin atm: |
If you care enough you could make an issue listing the failing edge cases, and I could have a look at it |
I actually fixed some issues with the type descriptions etc. If you still find something, please report it. I tested it on various large files from the nim repo and it did everything except
Of course I expect there to be various bugs still. |
I'll open issues for any new problems I find 👍 |
Btw I have written some highlight queries that comply with the nvim tree sitter interface. Gonna push later |
Oh shoot, I wish I saw this earlier. I rewrote my Helix queries to work with object and concept types and generally be less jank (currently pushed at helix-editor/helix#6123). I have some known issues with my queries:
|
Mmm, note to self, helix and nvim-treesitter queries have reversed precedence (later entries override in nvim, vice versa for helix) |
Hi aMOPel, I've been working on some highlighting queries based off of this repository's grammar. They're currently in development over at helix-editor/helix#6123: once they're done I can PR them to this repo, neovim, and anywhere else that uses tree-sitter.
The text was updated successfully, but these errors were encountered: