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
7
votes
1 answer
In a tree-sitter grammar, how do I match strings except for reserved keywords in identifiers?
This might be related to me not understanding the Keyword Extraction feature, which from the docs seems to be about avoiding an issue where no space exists between a keyword and the following expression. But say I have a fairly standard identifier…

ahelwer
- 1,441
- 13
- 29
6
votes
1 answer
Can I load a C++ shared library built with address sanitizer from Rust?
In tree-sitter, grammars are compiled from C and C++ to shared libraries. These libraries are then dynamically loaded by the tree-sitter CLI, which is a rust program. The tree-sitter CLI is usually responsible for compiling the grammar, although it…

ahelwer
- 1,441
- 13
- 29
6
votes
1 answer
Using tree-sitter as compiler's main parser
Can a parser, generated by tree-sitter, be used both for both syntax highlighting and compiler itself? If not - why?
It would be counterproductive to write 2 different parsers and maintain them.
Note: I haven't used tree-sitter yet, but consider…

gavrilikhin.d
- 554
- 1
- 7
- 20
5
votes
2 answers
How to install nvim-treesitter on Apple Silicon (M1 Max)? Getting error: Cannot install tree-sitter-cli for architecture arm64
I'm trying to set up nvim on my MBP, and everything went well except for the last step, which is installing nvim-treesitter, after a short installing routine it throws this error:
nvim-treesitter[phpdoc]: Error during `npm install` (required for…

flppv
- 4,111
- 5
- 35
- 54
5
votes
4 answers
nvim_treesitter installation on windows
bad English (sorry).
I'm trying to get nvim_treesitter to work on my windows machine, on my Linux one it worked great but now when I try on windows the :checkhealth nvim_treesitter gives:
health#nvim_treesitter#check
Installation
ERROR: tree-sitter…

Noam E
- 121
- 1
- 1
- 4
4
votes
0 answers
How to syntax highlight for nvim treesitter when there are multiple captures?
I am using NVIM v0.8.0-1210-gd367ed9b2 and I am trying to perform syntax highlighting for haskell in using treesitter. I would like the identifier for a function and its identifier for a function in a type definition to be highlighted differently,…

James L
- 63
- 2
4
votes
2 answers
How to fix NeoSolarized red coloured brackets
I have switched over to using NeoVim and the colorscheme which I have decided to use is NeoSolarized, as well as this I also installed treesitter to improve the syntax highlighting, and I have installed the c++ parser successfully by running…

Ali Awan
- 180
- 10
4
votes
1 answer
YAML indenting with neovim and treesitter?
I've recently upgraded to neovim 0.5.0, and I've been experimenting at replacing older syntax and indenting plugins with treesitter. I'm having some problems getting things to work correctly when editing YAML files.
I have the following in my…

larsks
- 277,717
- 41
- 399
- 399
3
votes
1 answer
Syntax Highlighting For Python Docstrings in Neovim Treesitter
I'm using Treesitter with Neovim v0.8.2 and Python. With a default configuration of those 3, python docstrings are highlighted as strings, and I'd like to highlight them as comments.
I've tried creating a ~/.config/nvim/after/syntax/python.vim file…

davem
- 53
- 4
3
votes
1 answer
how to convert antlr4 grammar file to tree-sitter grammar file?
Does anyone know of any tool(s) that can convert ANTLR v4 grammar files (.g4 extension) to tree-sitter grammar files (.js extension)? It would also be fine if I had to chain a couple conversion tools together. For example, going from foo.g4 (antlr4)…

errantepiphany
- 31
- 3
3
votes
1 answer
Syntax highlighting in Astro Nvim
I installed the Astro Vim package. Syntax highlighting should work out of the box, but it doesn't. As soon as I write :setfiletype javascript highlighting works immediately. Is there any way to enable automatic file type detection? I executed the…

IcyKit
- 31
- 4
3
votes
1 answer
Treesitter config not working with neovim api. Throws error "attempt to call field 'nvim_create_augroup' (a nil value)"?
I get an error message from treesitter config every time opening a file in neovim and the syntax highlighting does not work.
After going through the neovim API doc i tried the following test command:
:lua vim.api.nvim_create_augroup("MyGroup",…

MonkyPython
- 33
- 1
- 5
3
votes
0 answers
How do I match the string value only in tree-sitter?
Given that I have the code below in JavaScript/Typescript:
findOne('testing', () => {
});
findLegacy('testing2', () => {
});
findOne('testing3', () => {
});
I want to match the string value only using a tree-sitter query.
Here's where I got to,…

filype
- 8,034
- 10
- 40
- 66
3
votes
1 answer
How do I use the node-tree-sitter module from typescript?
From looking at pull requests & issues I see there are typescript definitions (possibly currently out of date) in the node-tree-sitter module; how do I access these definitions from typescript, and what would be the equivalent of the following…

ahelwer
- 1,441
- 13
- 29
2
votes
1 answer
Fetch function names from a file using tree-sitter-javascript
Using tree-sitter-javascript library, I'm trying to fetch all function names from a Javascript code (in string format) and storing it in a functionNames array.
const Parser = require('tree-sitter');
const JavaScript =…

Aadesh
- 403
- 3
- 13