@davisvaughan/tree-sitter-r

中文文档
1.3.0发布于 2026/06/20MITTypeScriptCommonJS近 30 天下载 9.2万

R grammar for tree-sitter

原始使用文档
文档目录6 节
  1. R package
  2. Rust bindings
  3. Node bindings
  4. References
  5. Known deviations
  6. ]] as a literal token

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.

Node bindings

This grammar is available as an npm package.

Note that it is currently listed as a scoped package under the name @davisvaughan/tree-sitter-r. We are working with the npm team to gain ownership of the tree-sitter-r package. Once that happens, we will move the npm package there instead.

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.

版本与发布记录

@davisvaughan/tree-sitter-r 共发布 2 个版本,首次发布于 2025/06/06;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.3.0latest2026/06/204 个月前
1.2.02025/06/061.4 年前

关于 @davisvaughan/tree-sitter-r 的常见问题

@davisvaughan/tree-sitter-r 是什么?

R grammar for tree-sitter

如何安装 @davisvaughan/tree-sitter-r?

在项目目录运行 npm install @davisvaughan/tree-sitter-r,或使用 pnpm add / yarn add / bun add。

@davisvaughan/tree-sitter-r 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@davisvaughan/tree-sitter-r 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@davisvaughan/tree-sitter-r 可以商用吗?

@davisvaughan/tree-sitter-r 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@davisvaughan/tree-sitter-r 的下载量有多少?

根据 npm 官方下载统计,@davisvaughan/tree-sitter-r 在 2026/10/12 – 2026/11/10 这 30 天内被下载 91,584 次,日均约 3,053 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@davisvaughan/tree-sitter-r 还在维护吗?

最新版本 1.3.0 发布于 2026/06/20(4 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 1 个;首次发布于 2025/06/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。