Tree-sitter is a parser generator tool and an incremental parsing library. Use this tag for questions about how to write or compile grammars and how to use Tree-sitter's API.
Questions tagged [treesitter]
81 questions
2
votes
1 answer
Highlight TODO permanently in vim(nvim)/treesitter
I'm trying to highlight TODO comment while using treesitter.
I have already read github issue of treesitter and installed TSInstall comment.
and running :hi link @text.note Todo temporarily works but when I exit the vim page and reopen it, it seems…

z2ouu
- 41
- 1
- 10
2
votes
0 answers
How do you debug a Bazel sandboxing failure?
Repo with full code example.
When I try to run a test with Bazel involving the tree-sitter binary, I get an Operation not permitted error without any further information.
❯ bazel test --test_output=errors --verbose_failures --sandbox_debug…

typesanitizer
- 2,505
- 1
- 20
- 44
2
votes
3 answers
Custom Injections in Neovim Treesitter with Tagged Template Literals
I'm trying to write a custom injection for Neovim's Treesitter that will highlight tagged template literals as SQL code.
The code in question looks like this:
import sql from "postgres"
const query = sql` SELECT * FROM my_table`
I'd like to tell…

Harrison Cramer
- 3,792
- 9
- 33
- 61
2
votes
1 answer
Walk through all tree nodes?
I'm using py-tree-sitter and this code to walk the entire node tree in sequence (code is from this github issue: https://github.com/tree-sitter/py-tree-sitter/issues/33#issuecomment-864557166):
def traverse_tree(tree: Tree):
cursor =…

Matic Kukovec
- 354
- 2
- 9
2
votes
1 answer
How do I extract the first argument from a function in tree-sitter
Given that I have the code below in JavaScript/Typescript:
findOne('testing', () => {
});
findLegacy('testing2', () => {
});
findOne('testing3', () => {
});
I want to match the first argument of every function call using a tree-sitter…

filype
- 8,034
- 10
- 40
- 66
2
votes
1 answer
Nvim-treesitter colors doesnt pass to :TOhtml
I'm trying to understand how I can copy code from Neovim as RTF.
So far I figured the easiest way is to convert the code to HTML and then convert the HTML to RTF, so using the :TOhtml is supposed to convert the given range to HTML and color it…

Noam E
- 121
- 1
- 1
- 4
2
votes
1 answer
Tree-sitter, how to use a "catch all" rule correctly?
I have a grammar like this:
terminator = '\n';
module.exports = grammar({
name: 'sciname',
rules: {
source_file: ($) => repeat($._sci_name),
_sci_name: ($) => seq($.uninomial, optional($.tail), terminator),
_uninomial: ($) =>…

dimus
- 8,712
- 10
- 45
- 56
2
votes
1 answer
Unable to encode precedence of block rule over statement rule in tree-sitter
I am trying to encode simple grammar which covers both plain statements and also statements enclosed with a block. Block has special keyword for it. I have specified block rule precedence over zero, but tree-sitter still doesn't match it. Even it…

Dims
- 47,675
- 117
- 331
- 600
2
votes
1 answer
Compiled against different NODE_MODULE_VERSION - Tree-sitter parser, ATOM package
I have created a tree-sitter parser that is parsing some legacy SAP language we use in order to make a package compatible for ATOM.
I will be very literate in my actions taken, as I am not very confident where I messed up.
According to the…

l000p
- 176
- 1
- 11
2
votes
1 answer
How to get the values from nodes in tree-sitter?
If I have a simple grammar in tree-sitter:
rules: {
expr: $ => choice(
/[0-9]+/,
prec.right(seq($.expr, /[+-]/, $.expr)),
)
}
And an input:
3+4
I get the followng CST:
(start [0, 0] - [0, 3]
(expr [0, 0] - [0, 3]
…

Rip
- 73
- 2
- 8
2
votes
1 answer
How do you package a tree-sitter grammar for consumption?
Say you want to write a program that consumes a tree-sitter grammar you've written, using the node-tree-sitter package. How do you package the grammar you've written for consumption? What is the minimal set of files that must be included in the node…

ahelwer
- 1,441
- 13
- 29
1
vote
1 answer
neovim (AstroNvim) treesitter/highlighter error on comment-lines
I've just installed astronvim and have the following issue: when there is any comment in the file (python #, lua --, etc.), treesitter/highlighter displays the following error:
Some extra-information:
I have no extra configure. Just gruvbox theme…

Dmitriy Lunev
- 177
- 2
- 12
1
vote
0 answers
How can I configure treesitter to use a different compiler and avoid crashing when opening bash files in LunarVim?
I am trying to run LunarVim on a server which is quite old. The installed gcc on the system is causing issues because it is older (GCC 4.9), specifically with treesitter. I don't have admin access on the system to update it. I compiled a newer…

nmello
- 11
- 3
1
vote
0 answers
How to add tree-sitter python grammar to tree-sitter?
I am not accustomed to build files or those stuff. Please guid me through the https://pypi.org/project/tree-sitter/
Can you please let me know how to add the python grammar.
I tried to follow the instructions, but I am not getting it.

AKT TARAFDER
- 11
- 2
1
vote
2 answers
How do I fix "Failed to execute C/C++ compiler" error when building helix grammer?
Problem:
When I run the hx -g build command to build the tree-sitter grammars Helix throws the following error:
Building 123 grammars
123 grammars failed to build
Failure 0/123: Failed to execute C/C++ compiler
Failure 1/123: Failed to…

Hammad Majid
- 11
- 1
- 5