Add support for bash syntax

pull/70/head
Wilfred Hughes 2021-11-24 23:53:01 +07:00
parent 678c1c5773
commit de56eabe94
7 changed files with 19 additions and 2 deletions

@ -2,7 +2,7 @@
### Parsing
Added Ruby support.
Added Bash and Ruby support.
Updated the C, CSS and JSON parsers to the latest upstream versions.

@ -55,6 +55,7 @@ $ GIT_EXTERNAL_DIFF=difft git show --ext-diff 38805c6a882a9f00615078250ccc8c070c
Difftastic supports the following languages:
* Bash
* C
* C++
* C#

@ -52,6 +52,11 @@ fn main() {
println!("cargo:rerun-if-changed=vendor");
let parsers = vec![
TreeSitterParser {
name: "tree-sitter-bash".into(),
src_dir: "vendor/tree-sitter-bash-src".into(),
extra_files: vec!["scanner.cc".into()],
},
TreeSitterParser {
name: "tree-sitter-c".into(),
src_dir: "vendor/tree-sitter-c-src".into(),

@ -1,8 +1,9 @@
# Introduction
Difftastic ([source on GitHub](https://github.com/wilfred/difftastic)) is a diff
tool that understands syntax. It currently supports 19 languages:
tool that understands syntax. It supports the following languages:
* Bash
* C
* C++
* C#

@ -42,6 +42,7 @@ pub struct TreeSitterConfig {
}
extern "C" {
fn tree_sitter_bash() -> Language;
fn tree_sitter_c() -> Language;
fn tree_sitter_c_sharp() -> Language;
fn tree_sitter_clojure() -> Language;
@ -67,6 +68,13 @@ pub fn from_extension(extension: &OsStr) -> Option<TreeSitterConfig> {
// TODO: find a nice way to extract name and extension information
// from the package.json in these parsers.
match extension.to_string_lossy().borrow() {
"bash" | "sh" => Some(TreeSitterConfig {
name: "Bash",
language: unsafe { tree_sitter_bash() },
atom_nodes: (vec!["string", "raw_string"]).into_iter().collect(),
delimiter_tokens: (vec![("(", ")"), ("{", "}"), ("[", "]")]),
highlight_queries: include_str!("../vendor/highlights/bash.scm"),
}),
"c" => Some(TreeSitterConfig {
name: "C",
language: unsafe { tree_sitter_c() },

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

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