Skip to content

Commit

Permalink
Add Hacklang support
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfred committed Jul 12, 2022
1 parent 470585e commit 8547987
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Parsing

Added SQL support.
Added Hacklang and SQL support.

Updated to the latest tree-sitter parsers for C#, Dart, Elm, Gleam,
Haskell, HCL, Java, JSON, OCaml, PHP, Python, Ruby, Scala and
Expand Down
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ fn main() {
src_dir: "vendor/tree-sitter-go-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-hack",
src_dir: "vendor/tree-sitter-hack-src",
extra_files: vec!["scanner.cc"],
},
TreeSitterParser {
name: "tree-sitter-haskell",
src_dir: "vendor/tree-sitter-haskell-src",
Expand Down
1 change: 1 addition & 0 deletions manual/src/languages_supported.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Difftastic supports the following programming languages.
| Emacs Lisp | [wilfred/tree-sitter-elisp](https://github.com/Wilfred/tree-sitter-elisp) |
| Gleam | [gleam-lang/tree-sitter-gleam](https://github.com/gleam-lang/tree-sitter-gleam) |
| Go | [tree-sitter/tree-sitter-go](https://github.com/tree-sitter/tree-sitter-go) |
| Hack | [slackhq/tree-sitter-hack](https://github.com/slackhq/tree-sitter-hack) |
| Haskell | [tree-sitter/tree-sitter-haskell](https://github.com/tree-sitter/tree-sitter-haskell) |
| Janet | [sogaiu/tree-sitter-janet-simple](https://github.com/sogaiu/tree-sitter-janet-simple) |
| Java | [tree-sitter/tree-sitter-java](https://github.com/tree-sitter/tree-sitter-java) |
Expand Down
2 changes: 1 addition & 1 deletion src/diff/sliders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn prefer_outer_delimiter(language: guess_language::Language) -> bool {
// For everything else, prefer the inner delimiter. These
// languages have syntax like `foo(bar)` or `foo[bar]` where
// the inner delimiter is more relevant.
Bash | C | CPlusPlus | CSharp | Css | Dart | Elixir | Elm | Elvish | Gleam | Go
Bash | C | CPlusPlus | CSharp | Css | Dart | Elixir | Elm | Elvish | Gleam | Go | Hack
| Haskell | Html | Java | JavaScript | Jsx | Julia | Kotlin | Lua | Nix | OCaml
| OCamlInterface | Perl | Php | Python | Ruby | Rust | Scala | Swift | Tsx | TypeScript
| Yaml | Zig => false,
Expand Down
8 changes: 8 additions & 0 deletions src/parse/guess_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum Language {
EmacsLisp,
Gleam,
Go,
Hack,
Haskell,
Hcl,
Html,
Expand Down Expand Up @@ -162,6 +163,7 @@ fn from_shebang(src: &str) -> Option<Language> {
"lisp" | "sbc" | "ccl" | "clisp" | "ecl" => return Some(CommonLisp),
"elixir" => return Some(Elixir),
"elvish" => return Some(Elvish),
"hhvm" => return Some(Hack),
"runghc" | "runhaskell" | "runhugs" => return Some(Haskell),
"chakra" | "d8" | "gjs" | "js" | "node" | "nodejs" | "qjs" | "rhino" | "v8"
| "v8-shell" => return Some(JavaScript),
Expand All @@ -175,6 +177,11 @@ fn from_shebang(src: &str) -> Option<Language> {
}
}
}

// Hack can use <?hh in files with a .php extension.
if first_line.starts_with("<?hh") {
return Some(Hack);
}
}

None
Expand Down Expand Up @@ -224,6 +231,7 @@ pub fn from_extension(extension: &OsStr) -> Option<Language> {
"elv" => Some(Elvish),
"gleam" => Some(Gleam),
"go" => Some(Go),
"hack" | "hck" | "hhi" => Some(Hack),
"hs" => Some(Haskell),
"hcl" | "nomad" | "tf" | "tfvars" | "worfklow" => Some(Hcl),
"html" | "htm" | "xhtml" => Some(Html),
Expand Down
15 changes: 15 additions & 0 deletions src/parse/tree_sitter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ extern "C" {
fn tree_sitter_elvish() -> ts::Language;
fn tree_sitter_gleam() -> ts::Language;
fn tree_sitter_go() -> ts::Language;
fn tree_sitter_hack() -> ts::Language;
fn tree_sitter_haskell() -> ts::Language;
fn tree_sitter_hcl() -> ts::Language;
fn tree_sitter_html() -> ts::Language;
Expand Down Expand Up @@ -313,6 +314,20 @@ pub fn from_language(language: guess::Language) -> TreeSitterConfig {
.unwrap(),
}
}
Hack => {
let language = unsafe { tree_sitter_hack() };
TreeSitterConfig {
name: "Hack",
language,
atom_nodes: vec!["prefixed_string", "heredoc"].into_iter().collect(),
delimiter_tokens: vec![("[", "]"), ("(", ")"), ("<", ">"), ("{", "}")],
highlight_query: ts::Query::new(
language,
include_str!("../../vendor/highlights/hack.scm"),
)
.unwrap(),
}
}
Haskell => {
let language = unsafe { tree_sitter_haskell() };
TreeSitterConfig {
Expand Down

0 comments on commit 8547987

Please sign in to comment.