|
|
@ -21,13 +21,6 @@
|
|
|
|
builtins.hasAttr "source" grammar
|
|
|
|
builtins.hasAttr "source" grammar
|
|
|
|
&& builtins.hasAttr "git" grammar.source
|
|
|
|
&& builtins.hasAttr "git" grammar.source
|
|
|
|
&& builtins.hasAttr "rev" grammar.source;
|
|
|
|
&& builtins.hasAttr "rev" grammar.source;
|
|
|
|
isGitHubGrammar = grammar: lib.hasPrefix "https://github.com" grammar.source.git;
|
|
|
|
|
|
|
|
toGitHubFetcher = url: let
|
|
|
|
|
|
|
|
match = builtins.match "https://github\.com/([^/]*)/([^/]*)/?" url;
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
owner = builtins.elemAt match 0;
|
|
|
|
|
|
|
|
repo = builtins.elemAt match 1;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
# If `use-grammars.only` is set, use only those grammars.
|
|
|
|
# If `use-grammars.only` is set, use only those grammars.
|
|
|
|
# If `use-grammars.except` is set, use all other grammars.
|
|
|
|
# If `use-grammars.except` is set, use all other grammars.
|
|
|
|
# Otherwise use all grammars.
|
|
|
|
# Otherwise use all grammars.
|
|
|
@ -40,24 +33,13 @@
|
|
|
|
grammarsToUse = builtins.filter useGrammar languagesConfig.grammar;
|
|
|
|
grammarsToUse = builtins.filter useGrammar languagesConfig.grammar;
|
|
|
|
gitGrammars = builtins.filter isGitGrammar grammarsToUse;
|
|
|
|
gitGrammars = builtins.filter isGitGrammar grammarsToUse;
|
|
|
|
buildGrammar = grammar: let
|
|
|
|
buildGrammar = grammar: let
|
|
|
|
gh = toGitHubFetcher grammar.source.git;
|
|
|
|
source = builtins.fetchTree {
|
|
|
|
sourceGit = builtins.fetchTree {
|
|
|
|
|
|
|
|
type = "git";
|
|
|
|
type = "git";
|
|
|
|
url = grammar.source.git;
|
|
|
|
url = grammar.source.git;
|
|
|
|
rev = grammar.source.rev;
|
|
|
|
rev = grammar.source.rev;
|
|
|
|
ref = grammar.source.ref or "HEAD";
|
|
|
|
ref = grammar.source.ref or "HEAD";
|
|
|
|
shallow = true;
|
|
|
|
shallow = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
sourceGitHub = builtins.fetchTree {
|
|
|
|
|
|
|
|
type = "github";
|
|
|
|
|
|
|
|
owner = gh.owner;
|
|
|
|
|
|
|
|
repo = gh.repo;
|
|
|
|
|
|
|
|
inherit (grammar.source) rev;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
source =
|
|
|
|
|
|
|
|
if isGitHubGrammar grammar
|
|
|
|
|
|
|
|
then sourceGitHub
|
|
|
|
|
|
|
|
else sourceGit;
|
|
|
|
|
|
|
|
in
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
# see https://github.com/NixOS/nixpkgs/blob/fbdd1a7c0bc29af5325e0d7dd70e804a972eb465/pkgs/development/tools/parsing/tree-sitter/grammar.nix
|
|
|
|
# see https://github.com/NixOS/nixpkgs/blob/fbdd1a7c0bc29af5325e0d7dd70e804a972eb465/pkgs/development/tools/parsing/tree-sitter/grammar.nix
|
|
|
|