Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jimhester/rtreesitter
R bindings to the Tree-sitter parsing library
https://github.com/jimhester/rtreesitter
r tree-sitter
Last synced: 16 days ago
JSON representation
R bindings to the Tree-sitter parsing library
- Host: GitHub
- URL: https://github.com/jimhester/rtreesitter
- Owner: jimhester
- License: other
- Created: 2020-11-20T14:57:59.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-03T22:29:57.000Z (over 2 years ago)
- Last Synced: 2024-06-11T18:20:13.584Z (5 months ago)
- Topics: r, tree-sitter
- Language: Rust
- Homepage: https://jimhester.github.io/rtreesitter/
- Size: 606 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# rtreesitter
[![Codecov test coverage](https://codecov.io/gh/jimhester/rtreesitter/branch/main/graph/badge.svg)](https://codecov.io/gh/jimhester/rtreesitter?branch=main)
[![R-CMD-check](https://github.com/jimhester/rtreesitter/workflows/R-CMD-check/badge.svg)](https://github.com/jimhester/rtreesitter/actions)rtreesitter provides R bindings to the [tree-sitter](https://tree-sitter.github.io/tree-sitter/) parsing library.
## Installation
You can install the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("remotes")
remotes::install_github("jimhester/rtreesitter")
```## Usage
```bash
mkdir vendor
cd vendor
git clone https://github.com/jimhester/tree-sitter-r
git clone https://github.com/tree-sitter/tree-sitter-python
git clone https://github.com/tree-sitter/tree-sitter-javascript
git clone https://github.com/tree-sitter/tree-sitter-go
``````{r}
library(rtreesitter)lib_dir <- file.path(tempdir(), "rtreesitter")
lib <- file.path(lib_dir, "languages.so")repos <- c(
"tree-sitter/tree-sitter-python",
"tree-sitter/tree-sitter-javascript",
"jimhester/tree-sitter-r"
)
for (repo in repos) {
processx::run("git", c("clone", "--depth=1", sprintf("https://github.com/%s", repo), file.path(lib_dir, basename(repo))))
}build_library(lib, file.path(lib_dir, basename(repos)))
p_r <- rts_parser$new("tree_sitter_R")
p_r$parse("x <- function(x) 1")p_py <- rts_parser$new("tree_sitter_python")
p_py$parse("
def foo():
if bar:
baz()
")p_js <- rts_parser$new("tree_sitter_javascript")
p_js$parse('
let name = "world";
alert("hello " + name);')
```