tree-sitter-python

repository·master·Indexed 20 days ago

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

A tree-sitter grammar implementation for the Python programming language that enables high-performance, incremental syntax tree generation. It provides a concrete grammar for parsing Python source code, compatible with core tree-sitter library bindings in Python, C++, JavaScript, and Rust.

Tokens
368
Snippets
1
Records
2
Agent score
19%

What's inside tree-sitter-python

  1. Use tree-sitter-python for Python parsing

    master
    tree-sitter-python provides a concrete grammar for parsing Python code using the tree-sitter incremental parsing framework. It allows developers to generate syntax trees for Python source code, which can be used for syntax highlighting, code analysis, refactoring tools, and more. The grammar is compatible with the core tree-sitter library across multiple language bindings including Python, C++, JavaScript, and Rust.
  2. Use the Node.js bindings for tree-sitter-python

    master

    The tree-sitter-python Node.js package provides the compiled bindings for the Python grammar. It is designed to work with standard Node.js environments via node-gyp-build and also provides support for Bun's static analysis during bun build --compile to ensure the .node binary is correctly located.

    To use this in a project, require the module as usual. The exported object contains the grammar implementation and, if available, nodeTypeInfo which maps node types to their definitions from src/node-types.json.

    const parser = require('tree-sitter-python');
    
    // The exported object contains the grammar bindings.
    // It may also contain nodeTypeInfo for inspecting node types.
    if (parser.nodeTypeInfo) {
      console.log('Node type information is available');
    }