The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

bonsaisitter

Bindings to the tree-sitter parsing library for R. The API mirrors the treesitter package, so bonsaisitter:: can stand in for treesitter:: in existing code. The package depends on nothing beyond base R.

bonsaisitter is the runtime only. Grammars come from separate packages:

Language Package Where
R treesitter.r CRAN
Python treesitter.python GitHub, drat
C++ treesitter.cpp GitHub, drat
Go treesitter.go GitHub, drat
Rust treesitter.rust GitHub, drat
JavaScript treesitter.javascript GitHub, drat

Installation

install.packages("bonsaisitter")

Development builds and the grammar packages that are not on CRAN are in the cornball.ai drat repository:

install.packages(c("bonsaisitter", "treesitter.python"),
                 repos = "https://cornball-ai.github.io/drat")

Usage

library(bonsaisitter)

lang <- treesitter.r::language()
tree <- text_parse("x <- f(1, 2)", lang)
root <- tree_root_node(tree)

node_type(root)
#> [1] "program"

q <- query(lang, "(call function: (identifier) @fn)")
vapply(query_captures(q, root)$node, node_text, character(1))
#> [1] "f"

cursor <- tree_walk(tree)
cursor$goto_first_child()
node_type(cursor$node())
#> [1] "binary_operator"

Differences from treesitter

Extras

License

MIT, copyright cornball.ai. The bundled tree-sitter sources are MIT, copyright Max Brunsfeld; every holder is listed in inst/COPYRIGHTS.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.