tree-sitter-go

repository·master·Indexed 19 days ago

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

A Go grammar implementation for the tree-sitter incremental parsing engine. It provides a concrete syntax tree (CST) for the Go programming language to enable high-fidelity syntax analysis, code navigation, and structural transformations. Includes JavaScript bindings for use in Node.js and Bun environments.

Tokens
361
Snippets
1
Records
3
Agent score
15%

What's inside tree-sitter-go

  1. Use tree-sitter-go in Node.js or Bun

    master

    The tree-sitter-go package provides JavaScript bindings to use the Go grammar in Node.js or Bun environments. It automatically selects the correct prebuilt binary based on your platform and architecture.

    In Node.js, it uses node-gyp-build to locate the appropriate .node binary. In Bun, it is designed to be statically analyzable for bun build --compile to ensure the .node file is correctly bundled.

    const Parser = require('tree-sitter');
    const Go = require('tree-sitter-go');
    
    const parser = new Parser();
    parser.setLanguage(Go);
    
    // Now you can parse Go code
    const tree = parser.parse('package main');