tree-sitter | An incremental parsing system for programming tools | Parser library
kandi X-RAY | tree-sitter Summary
kandi X-RAY | tree-sitter Summary
An incremental parsing system for programming tools
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of tree-sitter
tree-sitter Key Features
tree-sitter Examples and Code Snippets
Community Discussions
Trending Discussions on tree-sitter
QUESTION
I'm trying to use node's tree-sitter package in my vscode extension, but I get the following error:
Activating extension 'extension name' failed: The module '.../node_modules/tree-sitter/build/Release/tree_sitter_runtime_binding.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 93. This version of Node.js requires NODE_MODULE_VERSION 89. Please try re-compiling or re-installing the module (for instance, using
npm rebuild
ornpm install
)..
From what I understand, the NODE_MODULE_VERSION is the version of node's ABI. However, I couldn't even find a release of node that has NODE_MODULE_VERSION 89 in the official website.
What I've tried:- Deleting the node_modules folder and reinstalling the packages.
- Running
npm rebuild tree-sitter --update-binary
from the top directory. - Rebuilding the tree-sitter package with
node-gyp rebuild
andnode-gyp rebuild --target=(my node version)
from thenode_modules/tree-sitter
directory. - Switching node versions using nvm.
None of that helped. I understand from here that changing node versions won't help, as I confirmed when I tried
console.log(process.version); // v14.16.0
console.log(process.versions.modules); // 89
This gave the same output no matter which node version I used. I also tried rebuilding the tree-sitter package using that node version node-gyp rebuild --target=14.16.0
, but I get the same error, however this time it says the module was compiled using NODE_MODULE_VERSION 83, which is consistent with what node's site says.
How do I resolve this error? Any help is appreciated.
...ANSWER
Answered 2022-Mar-23 at 22:45As I suspected, the version of node ABI used by vscode extensions is the ABI version used by vscode's internal electron. According to this source
Native Node.js modules are supported by Electron, but since Electron has a different application binary interface (ABI) from a given Node.js binary (due to differences such as using Chromium's BoringSSL instead of OpenSSL), the native modules you use will need to be recompiled for Electron...
This explains why I couldn't find NODE_MODULE_VERSION 89 in node's site.
Next, I checked what version of electron my build of vscode uses. To do this, I simply checked the package.json that came with vscode (/usr/lib/code/package.json
on linux, I guess that it is inside the folder vscode is installed on on windows).
Next, following the instructions from electron's site, rebuild the module using the package electron-rebuild
. To specify a target version, simply run
./node_modules/.bin/electron-rebuild -v [version]
However, I have no source for this but it seems that tree-sitter does not currently support newer versions of electron, so the build fails. This seems to be because of a change in V8's API (according to this).
The author linked his solution here. I copied his changes and the build succeeded.
Note that I had to replace the existing node addon with the newly built one.
QUESTION
I'm trying to run an existing project but I keep getting this error: error logs image
when I try to run "npm i", can someone please explain what this error is about or guide me through the steps to solve it?
TIA
in case you can't see the logs:
npm ERR! code 7 npm ERR! path C:\Users\Kumail\Documents\XORD\alon\alon\node_modules\tree-sitter-c npm ERR! command failed npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@7.1.2 npm ERR! gyp info using node@14.17.6 | win32 | x64 npm ERR! gyp info find Python using Python version 3.7.3 found at "C:\Users\Kumail\Anaconda3\python.exe" npm ERR! gyp ERR! UNCAUGHT EXCEPTION npm ERR! gyp ERR! stack Error: Cannot find module 'psl' npm ERR! gyp ERR! stack Require stack: npm ERR! gyp ERR! stack - C:\Users\Kumail\AppData\Roaming\npm\node_modules\npm\node_modules\request\node_modules\tough-cookie\lib\pubsuffix-psl.js npm ERR! gyp ERR! stack - C:\Users\Kumail\AppData\Roaming\npm\node_modules\npm\node_modules\request\node_modules\tough-cookie\lib\cookie.js npm ERR! gyp ERR! stack - C:\Users\Kumail\AppData\Roaming\npm\node_modules\npm\node_modules\request\lib\cookies.js npm ERR! gyp ERR! stack - C:\Users\Kumail\AppData\Roaming\npm\node_modules\npm\node_modules\request\index.js npm ERR! gyp ERR! stack - C:\Users\Kumail\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\install.js npm ERR! gyp ERR! stack - C:\Users\Kumail\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\node-gyp.js npm ERR! gyp ERR! stack - C:\Users\Kumail\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js npm ERR! gyp ERR! stack at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15) npm ERR! gyp ERR! stack at Function.Module._load (internal/modules/cjs/loader.js:745:27) npm ERR! gyp ERR! stack at Module.require (internal/modules/cjs/loader.js:961:19) npm ERR! gyp ERR! stack at require (internal/modules/cjs/helpers.js:92:18) npm ERR! gyp ERR! stack at Object. (C:\Users\Kumail\AppData\Roaming\npm\node_modules\npm\node_modules\request\node_modules\tough-cookie\lib\pubsuffix-psl.js:32:11) npm ERR! gyp ERR! stack at Module._compile (internal/modules/cjs/loader.js:1072:14) npm ERR! gyp ERR! stack at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10) npm ERR! gyp ERR! stack at Module.load (internal/modules/cjs/loader.js:937:32) npm ERR! gyp ERR! stack at Function.Module._load (internal/modules/cjs/loader.js:778:12) npm ERR! gyp ERR! stack at Module.require (internal/modules/cjs/loader.js:961:19) npm ERR! gyp ERR! System Windows_NT 10.0.19042 npm ERR! gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\Kumail\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild" npm ERR! gyp ERR! cwd C:\Users\Kumail\Documents\XORD\alon\alon\node_modules\tree-sitter-c npm ERR! gyp ERR! node -v v14.17.6 npm ERR! gyp ERR! node-gyp -v v7.1.2 npm ERR! gyp ERR! Node-gyp failed to build your package. npm ERR! gyp ERR! Try to update npm and/or node-gyp and if it does not help file an issue with the package author.
npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Kumail\AppData\Local\npm-cache_logs\2021-11-08T10_21_18_719Z-debug.log
...ANSWER
Answered 2021-Nov-08 at 11:17I can't comment because I don't have enough reputation but try running npm install psl
and then npm install
because the error mentions a package called psl doesn't exist when the code is asking for it. It could be a missing dependency for one of the libraries you have. Let me know how that goes :)
QUESTION
I'm trying to create a tree-sitter for a Minecraft function grammar.
The structure of the language looks like this:
...ANSWER
Answered 2021-Aug-02 at 20:09I solved this by using a choice
of the two conflicting keys, something like this:
QUESTION
I'm trying to install dbt tool to Window 10. There is Python 3.9 and also VS2019 installed.(I don't know why required)
I'm getting strange errors and wondering errors and what should be done:
Command:
...ANSWER
Answered 2021-Jun-08 at 13:11The current development version of dbt (develop
branch, or installable as v0.20.0rc1
) requires two new dependencies:
tree-sitter==0.19.0
tree-sitter-jinja2==0.1.0a1
The first of these, tree-sitter
, requires you to have a C compiler installed on your system. Check out the related issue on GitHub: https://github.com/fishtown-analytics/dbt/issues/3433
We're going to think about how we can make this installation experience smoother. In the meantime, you can install GCC and then try installing dbt from source again.
QUESTION
I'm working on trying to create and use tree-sitter grammar in a language server I am implementing in order to support features like finding all references of a variable. Given the grammar I would be able to write a query to find all of the references to a variable with a specific name (ex. myVar
). However, the language I am writing a language server for uses case insensitive variables (ex. myVar
can be referenced as MYVAR
, MyVaR
, myvar
, etc.).
How would I be able to write a tree-sitter query to match a pattern where a token must case-insensitively match a particular string?
I could write the query to not filter by the variable name and implement my own filtering of the results, but I was wondering if there was a way to handle this within the query itself rather than implementing custom filtering code.
ExampleHere is a simplified example case to show what I mean.
Given the following grammar, I want to query for all of the set_statements
that set a new value to the variable myVar
.
ANSWER
Answered 2021-Jun-02 at 21:37Change your query to match a regular expression matching all possible upper/lower combinations of an identifier, in this case myvar
.
If you change find_variable.query to use match with a regular expression for all case combinations:
QUESTION
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 regex for variable names, function names, etc.:
/\w*[A-Za-z]\w*/
How do I keep this from matching a reserved keyword like IF
or ELSE
or something like that? So this expression would produce an error:
int IF = 5;
while this would not:
int x = 5;
ANSWER
Answered 2021-Apr-20 at 12:23There is a pull request pending since 2019 to add an EXCLUDE feature, but this is not currently implemented as of time of writing this (April 2021 - if some time has passed and you're reading this, please do re-check this!). And since treesitter also does not support negative lookbehind in its regular expressions, this has to be handled at the semantic level. One thing you can do to make this check easier is to enumerate all your reserved words then add them as an alternative to your identifier regex:
QUESTION
Consider an infix operator like subset (⊂). The subset operator is not associative, because its result (a boolean) is not itself a set and so cannot be fed into one or another side of the subset operator. Consider:
...ANSWER
Answered 2021-Apr-04 at 13:50You are correct this should be handled at the semantic level. So ⊂ should be marked left-associative in the grammar for parsing purposes, even though it is not. For the string S ⊂ T ⊂ M
it will then be parsed as:
QUESTION
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 tree-sitter documentation many guides I read - I've done the following:
Added D:\path-to-project\node_modules.bin to PATH
...ANSWER
Answered 2020-Oct-27 at 15:14I managed to resolve the issue. Apparently or not so apparently you should:
QUESTION
If I have a simple grammar in tree-sitter:
...ANSWER
Answered 2020-Aug-28 at 16:19Tree-sitter's syntax tree doesn't store copies of the input text. So to get the text of a particular token, you would have to use the ranges that Tree-sitter gives you to compute slices of your original source code.
In the python binding, this looks like this:
QUESTION
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 node-tree-sitter sample javascript code in typescript?
...ANSWER
Answered 2020-Jul-29 at 20:54The tree-sitter
module doesn't have a separate @types/tree-sitter
module (like some other modules) but instead bundles a tree-sitter.d.ts
type definition file with the tree-sitter
module itself. You can find this file in your node_modules/tree-sitter
directory. TypeScript finds this file automatically when you import tree-sitter
. Thus you can rewrite the sample JavaScript code in TypeScript as follows:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install tree-sitter
Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page