summary refs log tree commit diff
path: root/pkgs/development/tools/parsing/tree-sitter
diff options
context:
space:
mode:
authorMatthieu Coudron <mattator@gmail.com>2020-03-01 00:21:36 +0100
committerProfpatsch <mail@profpatsch.de>2020-03-06 08:01:35 +0100
commit53ae5f76a20257a61e231f250196066a7d0667bc (patch)
tree3998a8c8a75ceb91a45fdff6e7821d91054b1b0f /pkgs/development/tools/parsing/tree-sitter
parent2d2a5a9b634e39dec752b112a380055990c3cd35 (diff)
downloadnixpkgs-53ae5f76a20257a61e231f250196066a7d0667bc.tar
nixpkgs-53ae5f76a20257a61e231f250196066a7d0667bc.tar.gz
nixpkgs-53ae5f76a20257a61e231f250196066a7d0667bc.tar.bz2
nixpkgs-53ae5f76a20257a61e231f250196066a7d0667bc.tar.lz
nixpkgs-53ae5f76a20257a61e231f250196066a7d0667bc.tar.xz
nixpkgs-53ae5f76a20257a61e231f250196066a7d0667bc.tar.zst
nixpkgs-53ae5f76a20257a61e231f250196066a7d0667bc.zip
tree-sitter.builtGrammars: build parser libraries
except for typescript that provokes an error.
These libraries can be used on neovim 0.5 for instance.
Diffstat (limited to 'pkgs/development/tools/parsing/tree-sitter')
-rw-r--r--pkgs/development/tools/parsing/tree-sitter/default.nix18
-rw-r--r--pkgs/development/tools/parsing/tree-sitter/library.nix30
2 files changed, 44 insertions, 4 deletions
diff --git a/pkgs/development/tools/parsing/tree-sitter/default.nix b/pkgs/development/tools/parsing/tree-sitter/default.nix
index 0e69fa3259f..e77b338a20a 100644
--- a/pkgs/development/tools/parsing/tree-sitter/default.nix
+++ b/pkgs/development/tools/parsing/tree-sitter/default.nix
@@ -2,6 +2,7 @@
 , fetchgit, fetchFromGitHub, fetchurl
 , writeShellScript, runCommand, which
 , rustPlatform, jq, nix-prefetch-git, xe, curl, emscripten
+, callPackage
 }:
 
 # TODO: move to carnix or https://github.com/kolloch/crate2nix
@@ -26,15 +27,23 @@ let
     inherit writeShellScript nix-prefetch-git curl jq xe src;
   };
 
+  fetchGrammar = (v: fetchgit {inherit (v) url rev sha256 fetchSubmodules; });
+
   grammars =
-    let fetch =
-      (v: fetchgit {inherit (v) url rev sha256 fetchSubmodules; });
-    in runCommand "grammars" {} (''
+    runCommand "grammars" {} (''
        mkdir $out
      '' + (lib.concatStrings (lib.mapAttrsToList
-            (name: grammar: "ln -s ${fetch grammar} $out/${name}\n")
+            (name: grammar: "ln -s ${fetchGrammar grammar} $out/${name}\n")
             (import ./grammars))));
 
+  builtGrammars = let
+    change = name: grammar:
+      callPackage ./library.nix {
+        language = name; inherit version; source = fetchGrammar grammar;
+      };
+  in
+    # typescript doesn't have parser.c in the same place as others
+    lib.mapAttrs change (removeAttrs (import ./grammars) ["typescript"]);
 
 in rustPlatform.buildRustPackage {
   pname = "tree-sitter";
@@ -64,6 +73,7 @@ in rustPlatform.buildRustPackage {
       inherit update-all-grammars;
     };
     inherit grammars;
+    inherit builtGrammars;
   };
 
   meta = {
diff --git a/pkgs/development/tools/parsing/tree-sitter/library.nix b/pkgs/development/tools/parsing/tree-sitter/library.nix
new file mode 100644
index 00000000000..2d5d3e7d0b4
--- /dev/null
+++ b/pkgs/development/tools/parsing/tree-sitter/library.nix
@@ -0,0 +1,30 @@
+{ stdenv
+, language
+, tree-sitter
+, version
+, source
+}:
+
+stdenv.mkDerivation {
+
+  pname = "tree-sitter-${language}-library";
+  inherit version;
+
+  src = source;
+
+  buildInputs = [ tree-sitter ];
+
+  dontUnpack = true;
+  configurePhase= ":";
+  buildPhase = ''
+    runHook preBuild
+    $CC -I$src/src/ -shared -o parser -Os $src/src/parser.c
+    runHook postBuild
+  '';
+  installPhase = ''
+    runHook preInstall
+    mkdir $out
+    mv parser $out/
+    runHook postInstall
+  '';
+}