Skip to content

Instantly share code, notes, and snippets.

@clhodapp
Last active May 7, 2023 21:06
Show Gist options
  • Save clhodapp/4d9431c409d1bee2ab84e67519ed5896 to your computer and use it in GitHub Desktop.
Save clhodapp/4d9431c409d1bee2ab84e67519ed5896 to your computer and use it in GitHub Desktop.
{tree-sitter, linkFarm, lib}:
let
make-tree-sitter-libs = grammarFn: (
let
grammars = grammarFn tree-sitter.builtGrammars;
nameForEmacs = origName: (
let truncated = (lib.strings.removeSuffix "-grammar" origName);
in "lib" + truncated + ".so"
);
linkParser = drv: (
let
name = lib.strings.getName drv;
in {
name = nameForEmacs name;
path = "${drv}/parser";
}
);
libDir = linkFarm "grammars-lib" (map linkParser grammars);
in linkFarm "grammars" [ { name = "lib"; path = "${libDir}"; } ]
);
in make-tree-sitter-libs (p:
[
p.tree-sitter-c
p.tree-sitter-dockerfile
p.tree-sitter-java
p.tree-sitter-javascript
p.tree-sitter-json
p.tree-sitter-ruby
p.tree-sitter-scala
p.tree-sitter-tsx
p.tree-sitter-typescript
p.tree-sitter-yaml
]
)
{inputs, bash, stdenv, writeShellScriptBin}:
{
src, # Language source
lang,
pname ? "tree-sitter-grammar-${lang}",
}:
let
fakeGit = writeShellScriptBin "git" ''
echo "Skipping git command"
'';
pkg = stdenv.mkDerivation {
inherit pname src lang;
buildPhase = ''
ln -s . tree-sitter-${lang}
mkdir dist
bash ${inputs.emacsSrc}/admin/notes/tree-sitter/build-module/build.sh ${lang}
'';
installPhase = ''
mkdir -p $out
cp --recursive dist $out/lib
'';
version = "unstable";
nativeBuildInputs = [ bash fakeGit ];
};
in pkg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment