mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-23 07:23:20 +00:00
Merge pull request #209198 from erikarvstedt/tree-sitter-build-grammar
tree-sitter: add `buildGrammar` to `passthru`
This commit is contained in:
commit
d811234cba
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,7 @@ self: super:
|
||||
|
||||
let
|
||||
generatedGrammars = callPackage ./generated.nix {
|
||||
buildGrammar = callPackage ../../../../../development/tools/parsing/tree-sitter/grammar.nix { };
|
||||
inherit (tree-sitter) buildGrammar;
|
||||
};
|
||||
|
||||
generatedDerivations = lib.filterAttrs (_: lib.isDerivation) generatedGrammars;
|
||||
|
@ -36,7 +36,7 @@ def generate_grammar(item):
|
||||
generated = f""" {lang} = buildGrammar {{
|
||||
language = "{lang}";
|
||||
version = "{rev[:7]}";
|
||||
source = """
|
||||
src = """
|
||||
|
||||
generated += subprocess.check_output(["nurl", url, rev, "--indent=4"], text=True)
|
||||
generated += ";"
|
||||
|
@ -51,14 +51,17 @@ 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 { } {
|
||||
language = if grammar ? language then grammar.language else name;
|
||||
build = name: grammar:
|
||||
buildGrammar {
|
||||
language = grammar.language or name;
|
||||
inherit version;
|
||||
source = if grammar ? src then grammar.src else fetchGrammar grammar;
|
||||
location = if grammar ? location then grammar.location else null;
|
||||
src = grammar.src or fetchGrammar grammar;
|
||||
location = grammar.location or null;
|
||||
};
|
||||
grammars' = import ./grammars { inherit lib; } // extraGrammars;
|
||||
grammars = grammars' //
|
||||
@ -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
|
||||
|
@ -9,10 +9,8 @@
|
||||
{
|
||||
# language name
|
||||
language
|
||||
# version of tree-sitter
|
||||
, version
|
||||
# source for the language grammar
|
||||
, source
|
||||
, src
|
||||
, location ? null
|
||||
, generate ? false
|
||||
, ...
|
||||
@ -21,7 +19,7 @@
|
||||
stdenv.mkDerivation ({
|
||||
pname = "${language}-grammar";
|
||||
|
||||
src = source;
|
||||
inherit src version;
|
||||
|
||||
nativeBuildInputs = lib.optionals generate [ nodejs tree-sitter ];
|
||||
|
||||
@ -60,4 +58,4 @@ stdenv.mkDerivation ({
|
||||
fi
|
||||
runHook postInstall
|
||||
'';
|
||||
} // removeAttrs args [ "language" "source" "location" "generate" ])
|
||||
} // removeAttrs args [ "language" "location" "generate" ])
|
||||
|
Loading…
Reference in New Issue
Block a user