Add support for R

Fixes #470
pull/474/head
Wilfred Hughes 2023-01-26 08:49:03 +07:00
parent c2e047a7bf
commit 5ed4bac8a5
10 changed files with 2643 additions and 0 deletions

@ -1,5 +1,9 @@
## 0.43 (unreleased)
### Parsing
Added support for R.
### Diffing
Fixed a rare crash when one file had repeated lists that partially

@ -275,6 +275,11 @@ fn main() {
src_dir: "vendored_parsers/tree-sitter-qmljs-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-r",
src_dir: "vendored_parsers/tree-sitter-r-src",
extra_files: vec!["scanner.cc"],
},
TreeSitterParser {
name: "tree-sitter-ruby",
src_dir: "vendored_parsers/tree-sitter-ruby-src",

@ -39,6 +39,7 @@ with `difft --list-languages`.
| PHP | [tree-sitter/tree-sitter-php](https://github.com/tree-sitter/tree-sitter-php) |
| Python | [tree-sitter/tree-sitter-python](https://github.com/tree-sitter/tree-sitter-python) |
| QML | [tree-sitter/tree-sitter-qmljs](https://github.com/yuja/tree-sitter-qmljs) |
| R | [r-lib/tree-sitter-r](https://github.com/r-lib/tree-sitter-r) |
| Ruby | [tree-sitter/tree-sitter-ruby](https://github.com/tree-sitter/tree-sitter-ruby) |
| Rust | [tree-sitter/tree-sitter-rust](https://github.com/tree-sitter/tree-sitter-rust) ([forked](https://github.com/Wilfred/tree-sitter-rust/tree/non_special_token)) |
| Scala | [tree-sitter/tree-sitter-scala](https://github.com/tree-sitter/tree-sitter-scala) |

@ -154,6 +154,9 @@ sample_files/preprocesor_before.h sample_files/preprocesor_after.h
sample_files/qml_before.qml sample_files/qml_after.qml
622951bb34dbae3e35acd72d712bf127 -
sample_files/r_before.R sample_files/r_after.R
7a9bc4e3ba87b6f2139a6cdadcc7ee5f -
sample_files/ruby_before.rb sample_files/ruby_after.rb
db81701f87486b18f99d326d028d9929 -

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -56,6 +56,7 @@ pub enum Language {
Php,
Python,
Qml,
R,
Ruby,
Rust,
Scala,
@ -109,6 +110,7 @@ pub fn language_name(language: Language) -> &'static str {
Php => "PHP",
Python => "Python",
Qml => "QML",
R => "R",
Ruby => "Ruby",
Rust => "Rust",
Scala => "Scala",
@ -201,6 +203,7 @@ pub const LANG_EXTENSIONS: &[(Language, &[&str])] = &[
(Php, &["php"]),
(Python, &["py", "py3", "pyi", "bzl"]),
(Qml, &["qml"]),
(R, &["R", "r", "rd", "rsx"]),
(Ruby, &["rb", "builder", "spec", "rake"]),
(Rust, &["rs"]),
(Scala, &["scala", "sbt", "sc"]),
@ -293,6 +296,7 @@ pub const LANG_FILE_NAMES: &[(Language, &[&str])] = &[
],
),
(Python, &["TARGETS", "BUCK", "DEPS"]),
(R, &[".Rprofile", "expr-dist"]),
(Ruby, &["Gemfile", "Rakefile"]),
(
Toml,
@ -407,6 +411,7 @@ fn from_shebang(src: &str) -> Option<Language> {
"ocaml" | "ocamlrun" | "ocamlscript" => return Some(OCaml),
"perl" => return Some(Perl),
"python" | "python2" | "python3" => return Some(Python),
"Rscript" => return Some(R),
"ruby" | "macruby" | "rake" | "jruby" | "rbx" => return Some(Ruby),
"swift" => return Some(Swift),
"deno" | "ts-node" => return Some(TypeScript),

@ -99,6 +99,7 @@ extern "C" {
fn tree_sitter_perl() -> ts::Language;
fn tree_sitter_python() -> ts::Language;
fn tree_sitter_qmljs() -> ts::Language;
fn tree_sitter_r() -> ts::Language;
fn tree_sitter_ruby() -> ts::Language;
fn tree_sitter_rust() -> ts::Language;
fn tree_sitter_scala() -> ts::Language;
@ -749,6 +750,20 @@ pub fn from_language(language: guess::Language) -> TreeSitterConfig {
sub_languages: vec![],
}
}
R => {
let language = unsafe { tree_sitter_r() };
TreeSitterConfig {
language,
atom_nodes: vec!["string"].into_iter().collect(),
delimiter_tokens: vec![("{", "}"), ("(", ")"), ("[", "]")],
highlight_query: ts::Query::new(
language,
include_str!("../../vendored_parsers/highlights/r.scm"),
)
.unwrap(),
sub_languages: vec![],
}
}
Ruby => {
let language = unsafe { tree_sitter_ruby() };
TreeSitterConfig {

@ -0,0 +1 @@
../tree-sitter-r/queries/highlights.scm

@ -0,0 +1 @@
tree-sitter-r/src