tree-sitter | An incremental parsing system for programming tools | Parser library

 by   tree-sitter Rust Version: v0.20.8 License: MIT

kandi X-RAY | tree-sitter Summary

kandi X-RAY | tree-sitter Summary

tree-sitter is a Rust library typically used in Utilities, Parser applications. tree-sitter has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

An incremental parsing system for programming tools
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              tree-sitter has a medium active ecosystem.
              It has 12127 star(s) with 790 fork(s). There are 129 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 362 open issues and 698 have been closed. On average issues are closed in 57 days. There are 82 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of tree-sitter is v0.20.8

            kandi-Quality Quality

              tree-sitter has 0 bugs and 0 code smells.

            kandi-Security Security

              tree-sitter has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              tree-sitter code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              tree-sitter is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              tree-sitter releases are available to install and integrate.
              It has 496 lines of code, 2 functions and 47 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of tree-sitter
            Get all kandi verified functions for this library.

            tree-sitter Key Features

            No Key Features are available at this moment for tree-sitter.

            tree-sitter Examples and Code Snippets

            No Code Snippets are available at this moment for tree-sitter.

            Community Discussions

            QUESTION

            Module compiled against a different NODE_MODULE_VERSION when developing an extension for vscode
            Asked 2022-Mar-23 at 22:45

            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 or npm 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 and node-gyp rebuild --target=(my node version) from the node_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:45

            As 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.

            Source https://stackoverflow.com/questions/71527006

            QUESTION

            gyp ERR! stack Error: Cannot find module 'psl'
            Asked 2021-Nov-08 at 11:17

            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:17

            I 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 :)

            Source https://stackoverflow.com/questions/69882267

            QUESTION

            tree-sitter match for similar structures
            Asked 2021-Aug-02 at 20:09

            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:09

            I solved this by using a choice of the two conflicting keys, something like this:

            Source https://stackoverflow.com/questions/68606558

            QUESTION

            Why installation of dbt fails? - Failed building wheel for tree-sitter
            Asked 2021-Jun-08 at 13:11

            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:11

            The 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.

            Source https://stackoverflow.com/questions/67887293

            QUESTION

            How to do case-insensitive query in tree-sitter
            Asked 2021-Jun-02 at 21:37

            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.

            Example

            Here 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:37

            Change 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:

            Source https://stackoverflow.com/questions/67550226

            QUESTION

            In a tree-sitter grammar, how do I match strings except for reserved keywords in identifiers?
            Asked 2021-Apr-20 at 12:23

            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:23

            There 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:

            Source https://stackoverflow.com/questions/66733619

            QUESTION

            In a tree-sitter grammar, is it possible for operator precedence/associativity conflict to cause a runtime parse failure?
            Asked 2021-Apr-04 at 13:50

            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:50

            You 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:

            Source https://stackoverflow.com/questions/66932531

            QUESTION

            Compiled against different NODE_MODULE_VERSION - Tree-sitter parser, ATOM package
            Asked 2020-Oct-27 at 15:14

            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:14

            I managed to resolve the issue. Apparently or not so apparently you should:

            Source https://stackoverflow.com/questions/64479973

            QUESTION

            How to get the values from nodes in tree-sitter?
            Asked 2020-Aug-28 at 16:19

            If I have a simple grammar in tree-sitter:

            ...

            ANSWER

            Answered 2020-Aug-28 at 16:19

            Tree-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:

            Source https://stackoverflow.com/questions/63635500

            QUESTION

            How do I use the node-tree-sitter module from typescript?
            Asked 2020-Jul-29 at 20:54

            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:54

            The 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:

            Source https://stackoverflow.com/questions/63103217

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install tree-sitter

            You can download it from GitHub.
            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

            DocumentationRust bindingWASM bindingCommand-line interface
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/tree-sitter/tree-sitter.git

          • CLI

            gh repo clone tree-sitter/tree-sitter

          • sshUrl

            git@github.com:tree-sitter/tree-sitter.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Parser Libraries

            marked

            by markedjs

            swc

            by swc-project

            es6tutorial

            by ruanyf

            PHP-Parser

            by nikic

            Try Top Libraries by tree-sitter

            py-tree-sitter

            by tree-sitterC

            node-tree-sitter

            by tree-sitterC++

            tree-sitter-javascript

            by tree-sitterJavaScript

            tree-sitter-rust

            by tree-sitterJavaScript

            tree-sitter-typescript

            by tree-sitterJavaScript