3
0
Fork 0
forked from mirrors/nixpkgs

tree-sitter: add buildGrammar to passthru

`buildGrammar` is useful for building custom grammars.

Also, improve perf by moving `callPackage` out of the fn call.

Use more precise var name: `change` -> `build`.
This commit is contained in:
Erik Arvstedt 2023-01-05 19:53:26 +01:00
parent 109fc99d1c
commit 99225ef64d
No known key found for this signature in database
GPG key ID: 33312B944DD97846

View file

@ -51,10 +51,13 @@ let
'' + (lib.concatStrings (lib.mapAttrsToList
(name: grammar: "ln -s ${if grammar ? src then grammar.src else fetchGrammar grammar} $out/${name}\n")
(import ./grammars { inherit lib; }))));
buildGrammar = callPackage ./grammar.nix { };
builtGrammars =
let
change = name: grammar:
callPackage ./grammar.nix { } {
build = name: grammar:
buildGrammar {
language = if grammar ? language then grammar.language else name;
inherit version;
source = if grammar ? src then grammar.src else fetchGrammar grammar;
@ -70,7 +73,7 @@ let
{ tree-sitter-markdown = grammars'.tree-sitter-markdown // { location = "tree-sitter-markdown"; }; } //
{ tree-sitter-markdown-inline = grammars'.tree-sitter-markdown // { language = "markdown_inline"; location = "tree-sitter-markdown-inline"; }; };
in
lib.mapAttrs change (grammars);
lib.mapAttrs build (grammars);
# Usage:
# pkgs.tree-sitter.withPlugins (p: [ p.tree-sitter-c p.tree-sitter-java ... ])
@ -142,7 +145,7 @@ rustPlatform.buildRustPackage {
updater = {
inherit update-all-grammars;
};
inherit grammars builtGrammars withPlugins allGrammars;
inherit grammars buildGrammar builtGrammars withPlugins allGrammars;
tests = {
# make sure all grammars build