https://github.com/v-analyzer/v-tree-sitter
V bindings for tree-sitter
https://github.com/v-analyzer/v-tree-sitter
binding tree tree-sitter vlang vlang-bindings vosca
Last synced: 5 months ago
JSON representation
V bindings for tree-sitter
- Host: GitHub
- URL: https://github.com/v-analyzer/v-tree-sitter
- Owner: v-analyzer
- License: mit
- Created: 2023-05-22T10:13:55.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-11T09:33:34.000Z (over 2 years ago)
- Last Synced: 2025-10-31T08:49:57.401Z (8 months ago)
- Topics: binding, tree, tree-sitter, vlang, vlang-bindings, vosca
- Language: C
- Homepage:
- Size: 699 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# V tree-sitter
[](https://github.com/spavn-analyzer/v-tree-sitter/actions/workflows/test_tree_sitter.yml)
V bindings for the
[tree-sitter](https://github.com/tree-sitter/tree-sitter)
parsing library.
## Installation
```sh
v install https://github.com/spavn-analyzer/v-tree-sitter
```
## Basic Usage
Create a parser with a grammar:
```v
import v_tree_sitter.tree_sitter
import v_tree_sitter.languages.tree_sitter_v as v
mut p := tree_sitter.new_parser[v.NodeType](v.type_factory)
p.set_language(v.language)
```
Parse some code:
```v
code := 'fn main() {}'
tree := p.parse_string(source: code)
```
Inspect the syntax tree:
```v skip
root := tree.root_node()
// (source_file (function_declaration name: (identifier) signature:
// (signature parameters: (parameter_list)) body: (block)))
println(root)
fc := root.first_child()?
if fc.type_name == .function_declaration {
if name_node := fc.child_by_field_name('name') {
println('Found function: ${name_node.text(rope)}') // Found function: main
println('Position: ${name_node.range()}')
println('Line: ${name_node.start_point().row}') // Line: 0
}
}
```
## Use old tree
```v
code := 'fn main() {}'
tree := p.parse_string(source: code, tree: old_tree.raw_tree)
```
## Examples
See examples in the `examples` directory.
## Project structure
- `examples` — examples of using the library
- `languages` — languages sources (only V for now)
- `lib` — tree-sitter C lib sources
- `tests` — tests for the bindings
- `tree_sitter` — bindings sources
## Updating tree-sitter
To update the tree-sitter lib, run:
```sh
v update_tree_sitter.vsh
```
## Authors
This project initially started by
[nedpals](https://github.com/nedpals)
and after that in 2023 it was heavily modified by the
[VOSCA](https://github.com/vlang-association).
## License
This project is under the **MIT License**.
See the
[LICENSE](https://github.com/vlang-association/spavn-analyzer/blob/master/tree_sitter/LICENSE)
file for the full license text.