Skip to content

Commit 6949436

Browse files
committed
add tree-sitter-nix support
1 parent 248a0e2 commit 6949436

File tree

6 files changed

+2609
-0
lines changed

6 files changed

+2609
-0
lines changed

build.rs

+17
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ fn main() {
110110
.file(markdown_dir.join("scanner.cc"))
111111
.compile("tree_sitter_markdown_scanner");
112112

113+
// nix
114+
let nix_dir: PathBuf = ["vendor", "tree-sitter-nix", "src"].iter().collect();
115+
116+
println!("cargo:rerun-if-changed=vendor/tree-sitter-nix/src/parser.c");
117+
cc::Build::new()
118+
.include(&nix_dir)
119+
.warnings(false)
120+
.file(nix_dir.join("parser.c"))
121+
.compile("tree-sitter-nix");
122+
123+
println!("cargo:rerun-if-changed=vendor/tree-sitter-nix/src/scanner.c");
124+
cc::Build::new()
125+
.include(&nix_dir)
126+
.warnings(false)
127+
.file(nix_dir.join("scanner.c"))
128+
.compile("tree_sitter_nix_scanner");
129+
113130
// php
114131
let php_dir: PathBuf = ["vendor", "tree-sitter-php", "src"].iter().collect();
115132

flake.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
flake = false;
1212
};
1313

14+
tree-sitter-nix = {
15+
url = "github:cstrahan/tree-sitter-nix";
16+
flake = false;
17+
};
18+
1419
tree-sitter-elixir = {
1520
url = "github:elixir-lang/tree-sitter-elixir/main";
1621
flake = false;
@@ -81,6 +86,7 @@
8186
ln -s ${inputs.tree-sitter-ruby} vendor/tree-sitter-ruby
8287
ln -s ${inputs.tree-sitter-rust} vendor/tree-sitter-rust
8388
ln -s ${inputs.tree-sitter-typescript} vendor/tree-sitter-typescript
89+
ln -s ${inputs.tree-sitter-nix} vendor/tree-sitter-nix
8490
'';
8591
in rec {
8692
# `nix build`

src/language.rs

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub enum Language {
1010
Haskell,
1111
JavaScript,
1212
Markdown,
13+
Nix,
1314
Php,
1415
Ruby,
1516
Rust,
@@ -25,6 +26,7 @@ impl Language {
2526
Language::Haskell,
2627
Language::JavaScript,
2728
Language::Markdown,
29+
Language::Nix,
2830
Language::Php,
2931
Language::Ruby,
3032
Language::Rust,
@@ -41,6 +43,7 @@ impl Language {
4143
Language::Haskell => tree_sitter_haskell(),
4244
Language::JavaScript => tree_sitter_javascript(),
4345
Language::Markdown => tree_sitter_markdown(),
46+
Language::Nix => tree_sitter_nix(),
4447
Language::Php => tree_sitter_php(),
4548
Language::Ruby => tree_sitter_ruby(),
4649
Language::Rust => tree_sitter_rust(),
@@ -61,6 +64,7 @@ impl Language {
6164
Language::Haskell => "haskell",
6265
Language::JavaScript => "js",
6366
Language::Markdown => "markdown",
67+
Language::Nix => "nix",
6468
Language::Php => "php",
6569
Language::Ruby => "ruby",
6670
Language::Rust => "rust",
@@ -80,6 +84,7 @@ impl FromStr for Language {
8084
"haskell" => Ok(Language::Haskell),
8185
"javascript" => Ok(Language::JavaScript),
8286
"markdown" => Ok(Language::Markdown),
87+
"nix" => Ok(Language::Nix),
8388
"php" => Ok(Language::Php),
8489
"ruby" => Ok(Language::Ruby),
8590
"rust" => Ok(Language::Rust),
@@ -106,6 +111,7 @@ impl Display for Language {
106111
Language::Haskell => f.write_str("haskell"),
107112
Language::JavaScript => f.write_str("javascript"),
108113
Language::Markdown => f.write_str("markdown"),
114+
Language::Nix => f.write_str("nix"),
109115
Language::Php => f.write_str("php"),
110116
Language::Ruby => f.write_str("ruby"),
111117
Language::Rust => f.write_str("rust"),
@@ -155,6 +161,7 @@ extern "C" {
155161
fn tree_sitter_haskell() -> tree_sitter::Language;
156162
fn tree_sitter_javascript() -> tree_sitter::Language;
157163
fn tree_sitter_markdown() -> tree_sitter::Language;
164+
fn tree_sitter_nix() -> tree_sitter::Language;
158165
fn tree_sitter_php() -> tree_sitter::Language;
159166
fn tree_sitter_ruby() -> tree_sitter::Language;
160167
fn tree_sitter_rust() -> tree_sitter::Language;

src/main.rs

+14
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,20 @@ mod tests {
340340
]))
341341
}
342342

343+
#[test]
344+
fn all_nix() {
345+
insta::assert_snapshot!(call(&[
346+
"tree-grepper",
347+
"-q",
348+
"nix",
349+
"(_)",
350+
"--format=pretty-json",
351+
"--sort",
352+
"--no-gitignore",
353+
"vendor/tree-sitter-nix/test/highlight/basic.nix",
354+
]))
355+
}
356+
343357
#[test]
344358
fn all_php() {
345359
insta::assert_snapshot!(call(&[

0 commit comments

Comments
 (0)