All Projects → smacker → go-tree-sitter

smacker / go-tree-sitter

Licence: MIT license
Golang bindings for tree-sitter https://github.com/tree-sitter/tree-sitter

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to go-tree-sitter

tree-sitter.el
An Emacs dynamic module exposing tree-sitter.
Stars: ✭ 59 (-56.93%)
Mutual labels:  tree-sitter, binding
ruby-tree-sitter
Ruby bindings to tree-sitter
Stars: ✭ 48 (-64.96%)
Mutual labels:  tree-sitter, binding
rust-tree-sitter
Rust bindings to Tree-sitter
Stars: ✭ 29 (-78.83%)
Mutual labels:  tree-sitter, binding
haskell-tree-sitter
Haskell bindings for tree-sitter
Stars: ✭ 123 (-10.22%)
Mutual labels:  tree-sitter, binding
unifiedjs.github.io
Site for unified
Stars: ✭ 37 (-72.99%)
Mutual labels:  syntax-tree
kosmikoa.nvim
A dark color scheme for Neovim with support for LSP, Treesitter. This mirror is deprecated. Use the repo at https://sr.ht/~novakane/kosmikoa.nvim/
Stars: ✭ 23 (-83.21%)
Mutual labels:  tree-sitter
crystal-cassandra
A Cassandra driver for Crystal
Stars: ✭ 20 (-85.4%)
Mutual labels:  binding
pybrood
Another BWAPI Python binding made with pybind11
Stars: ✭ 15 (-89.05%)
Mutual labels:  binding
Wires
Light binding library for Xamarin
Stars: ✭ 34 (-75.18%)
Mutual labels:  binding
langua
A suite of language tools
Stars: ✭ 29 (-78.83%)
Mutual labels:  syntax-tree
tree-sitter-comment
Tree-sitter grammar for comment tags like TODO, FIXME(user).
Stars: ✭ 86 (-37.23%)
Mutual labels:  tree-sitter
MarkdownSyntax
☄️ A Type-safe Markdown parser in Swift.
Stars: ✭ 65 (-52.55%)
Mutual labels:  syntax-tree
tree-sitter-java
Java grammar for tree-sitter
Stars: ✭ 73 (-46.72%)
Mutual labels:  tree-sitter
tree-sitter-css
CSS grammar for Tree-sitter
Stars: ✭ 57 (-58.39%)
Mutual labels:  tree-sitter
tree-sitter-elixir
ananthakumaran.in/tree-sitter-elixir
Stars: ✭ 43 (-68.61%)
Mutual labels:  tree-sitter
tree-sitter-hcl
A tree-sitter grammar for HCL (HashiCorp Configuration Language), used by projects such as Terraform.
Stars: ✭ 65 (-52.55%)
Mutual labels:  tree-sitter
tree-sitter-regex
Tree-sitter parser for regular expressions
Stars: ✭ 42 (-69.34%)
Mutual labels:  tree-sitter
unicorn-net
WIP .NET binding/wrapper for the Unicorn engine written in C#
Stars: ✭ 44 (-67.88%)
Mutual labels:  binding
Witch-Android
View-data binding library for Android.
Stars: ✭ 25 (-81.75%)
Mutual labels:  binding
unist-util-map
utility to create a new tree by mapping all nodes
Stars: ✭ 30 (-78.1%)
Mutual labels:  syntax-tree

go tree-sitter

Build Status GoDoc

Golang bindings for tree-sitter

Usage

Create a parser with that grammar:

import (
	sitter "github.com/smacker/go-tree-sitter"
	"github.com/smacker/go-tree-sitter/javascript"
)

parser := sitter.NewParser()
parser.SetLanguage(javascript.GetLanguage())

Parse some code:

sourceCode := []byte("let a = 1")
tree := parser.Parse(nil, sourceCode)

Inspect the syntax tree:

n := tree.RootNode()

fmt.Println(n) // (program (lexical_declaration (variable_declarator (identifier) (number))))

child := n.NamedChild(0)
fmt.Println(child.Type()) // lexical_declaration
fmt.Println(child.StartByte()) // 0
fmt.Println(child.EndByte()) // 9

If your source code changes, you can update the syntax tree. This will take less time than the first parse.

// change 1 -> true
newText := []byte("let a = true")
tree.Edit(sitter.EditInput{
    StartIndex:  8,
    OldEndIndex: 9,
    NewEndIndex: 12,
    StartPoint: sitter.Point{
        Row:    0,
        Column: 8,
    },
    OldEndPoint: sitter.Point{
        Row:    0,
        Column: 9,
    },
    NewEndPoint: sitter.Point{
        Row:    0,
        Column: 12,
    },
})

// check that it changed tree
assert.True(n.HasChanges())
assert.True(n.Child(0).HasChanges())
assert.False(n.Child(0).Child(0).HasChanges()) // left side of the tree didn't change
assert.True(n.Child(0).Child(1).HasChanges())

// generate new tree
newTree := parser.Parse(tree, newText)

Development

Check if any updates for vendored files are available:

./vendor.sh check-updates

Update vendor files:

  • modify grammars array in vendor.sh
  • run ./vendor.sh download. (This script requires Bash v5, not the v3 of recent Mac OS.)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].