1234567891011121314151617181920212223242526272829303132 |
- { lib, runCommand, fetchFromGitHub, tree-sitter }:
- let
- grammars = builtins.fromJSON (builtins.readFile ./grammars.json);
- buildTreesitterPlugin = name: spec:
- let
- nameParts = builtins.split "/" (spec.repo or "tree-sitter/tree-sitter-${name}");
- owner = builtins.head nameParts;
- repo = builtins.elemAt nameParts 2;
- grammar = tree-sitter.buildGrammar ({
- language = name;
- version = "0.0.0+rev=${spec.rev}";
- src = fetchFromGitHub {
- inherit owner repo;
- inherit (spec) rev sha256;
- };
- } // lib.optionalAttrs (builtins.hasAttr "path" spec) {
- location = spec.path;
- });
- in
- runCommand "tree-sitter-${name}" {
- passthru = {
- inherit grammar;
- };
- } ''
- mkdir -p $out/parser
- ln -s ${grammar}/parser $out/parser/${name}.so
- '';
- in
- builtins.mapAttrs buildTreesitterPlugin grammars
|