Add C# support

Closes #37.
edge_only_predecessors
Wilfred Hughes 2021-09-22 22:37:06 +07:00
parent 806f925948
commit 3b36e6486d
7 changed files with 26 additions and 1 deletions

@ -7,6 +7,8 @@ Added a C parser.
Added a C++ parser. Difftastic prefers the C++ parser for `.h`
files. Please file a bug if you see issues.
Added a C# parser.
Added a Haskell parser.
Removed legacy regex-based parsing backend.

@ -18,6 +18,7 @@ Difftastic supports the following languages:
* C
* C++
* C#
* Clojure
* CSS
* Elixir

@ -60,6 +60,11 @@ fn main() {
src_dir: "vendor/tree-sitter-cpp-src".into(),
extra_files: vec!["scanner.cc".into()],
},
TreeSitterParser {
name: "tree-sitter-c-sharp".into(),
src_dir: "vendor/tree-sitter-c-sharp-src".into(),
extra_files: vec!["scanner.c".into()],
},
TreeSitterParser {
name: "tree-sitter-clojure".into(),
src_dir: "vendor/tree-sitter-clojure-src".into(),

@ -1,10 +1,11 @@
# Introduction
Difftastic is a diff tool that understands syntax. It currently
supports 17 languages:
supports 18 languages:
* C
* C++
* C#
* Clojure
* CSS
* Elixir

@ -6,6 +6,7 @@ Difftastic uses the following tree-sitter parsers:
|-----------------|---------------------------------------------------------------------------------------------|
| C | [tree-sitter/tree-sitter-c](https://github.com/tree-sitter/tree-sitter-c) |
| C++ | [tree-sitter/tree-sitter-cpp](https://github.com/tree-sitter/tree-sitter-cpp) |
| C# | [tree-sitter/tree-sitter-c-sharp](https://github.com/tree-sitter/tree-sitter-c-sharp) |
| Clojure | [sogaiu/tree-sitter-clojure](https://github.com/sogaiu/tree-sitter-clojure) |
| CSS | [tree-sitter/tree-sitter-css](https://github.com/tree-sitter/tree-sitter-css) |
| Elixir | [ananthakumaran/tree-sitter-elixir](https://github.com/ananthakumaran/tree-sitter-elixir) |

@ -26,6 +26,7 @@ pub struct TreeSitterConfig {
extern "C" {
fn tree_sitter_c() -> Language;
fn tree_sitter_c_sharp() -> Language;
fn tree_sitter_clojure() -> Language;
fn tree_sitter_cpp() -> Language;
fn tree_sitter_css() -> Language;
@ -81,6 +82,19 @@ pub fn from_extension(extension: &OsStr) -> Option<TreeSitterConfig> {
open_delimiter_tokens: (vec!["{", "(", "["]).into_iter().collect(),
})
}
"cs" => Some(TreeSitterConfig {
name: "C#",
language: unsafe { tree_sitter_c_sharp() },
atom_nodes: (vec![
"string_literal",
"verbatim_string_literal",
"character_literal",
])
.into_iter()
.collect(),
// TODO: If statements have ( as the second item.
open_delimiter_tokens: (vec!["{", "("]).into_iter().collect(),
}),
"css" => Some(TreeSitterConfig {
name: "CSS",
language: unsafe { tree_sitter_css() },

@ -0,0 +1 @@
tree-sitter-c-sharp/src