| Crates.io | tree-sitter-r |
| lib.rs | tree-sitter-r |
| version | 1.2.0 |
| created_at | 2021-08-31 13:53:23.887376+00 |
| updated_at | 2025-06-05 19:20:08.189527+00 |
| description | R grammar for tree-sitter |
| homepage | |
| repository | https://github.com/r-lib/tree-sitter-r |
| max_upload_size | |
| id | 445103 |
| size | 4,247,816 |
An R grammar for tree-sitter.
This grammar is available as an R package.
You'll also want the R package providing bindings to tree-sitter itself.
This grammar is available as a Rust crate on crates.io.
This section describes known deviations from the R grammar.
]] as a literal tokenThe 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.