7 releases (4 stable)

1.2.0 Jun 5, 2025
1.1.0 Sep 6, 2024
1.0.1 Jun 14, 2024
0.19.5 Feb 28, 2022
0.19.3 Aug 31, 2021

#247 in Parser implementations

Download history 211/week @ 2025-03-10 237/week @ 2025-03-17 218/week @ 2025-03-24 642/week @ 2025-03-31 1347/week @ 2025-04-07 1665/week @ 2025-04-14 1379/week @ 2025-04-21 1147/week @ 2025-04-28 1208/week @ 2025-05-05 1368/week @ 2025-05-12 1324/week @ 2025-05-19 1074/week @ 2025-05-26 1317/week @ 2025-06-02 1210/week @ 2025-06-09 1323/week @ 2025-06-16 755/week @ 2025-06-23

4,623 downloads per month
Used in 4 crates (2 directly)

MIT license

4MB
148K SLoC

C 148K SLoC // 0.0% comments JavaScript 455 SLoC // 0.3% comments Scheme 110 SLoC // 0.1% comments Rust 51 SLoC // 0.1% comments

tree-sitter-r

An R grammar for tree-sitter.

R package

This grammar is available as an R package.

You'll also want the R package providing bindings to tree-sitter itself.

Rust bindings

This grammar is available as a Rust crate on crates.io.

References

Known deviations

This section describes known deviations from the R grammar.

]] as a literal token

The following is valid R syntax, note how ]] has been split over multiple lines.

x[["a"]
]

This applies to ]], but not to [[, for example, this is not valid R syntax:

x[
["a"]]

The technical reason for this is that in the grammar R treats [[ as a single token, but ]] is treated as two individual ] tokens. Treating ]] as two individual ] tokens allows whitespace, newlines, and even comments to appear between the two ] tokens:

x[["a"] # comment
]

While we'd like to precisely support the R grammar, it is also extremely useful to treat all of (, ), [, ], [[, and ]] as literal tokens when using the tree-sitter grammar. This allows you to treat call, subset, and subset2 nodes in the same way, since they all have exactly the same node structure.

Because treating ]] as a literal token is so useful, and because we've never seen any R code "in the wild" written this way, this grammar does not allow whitespace, newlines, or comments between the two ] tokens.

Dependencies