2019-08-17 15:50:45 +01:00
|
|
|
{ lib, stdenv
|
|
|
|
, fetchgit, fetchFromGitHub, fetchurl
|
2020-02-15 05:11:00 +00:00
|
|
|
, writeShellScript, runCommand, which
|
|
|
|
, rustPlatform, jq, nix-prefetch-git, xe, curl, emscripten
|
2020-02-29 23:21:36 +00:00
|
|
|
, callPackage
|
2019-08-17 15:50:45 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
# TODO: move to carnix or https://github.com/kolloch/crate2nix
|
|
|
|
let
|
|
|
|
# to update:
|
|
|
|
# 1) change all these hashes
|
|
|
|
# 2) nix-build -A tree-sitter.updater.update-all-grammars
|
2020-02-15 05:11:00 +00:00
|
|
|
# 3) run the ./result script that is output by that (it updates ./grammars)
|
|
|
|
version = "0.16.4";
|
|
|
|
sha256 = "1m0zxz7h4w2zny7yhrlxwqvizcf043cizg7ca5dn3h9k16adcxil";
|
|
|
|
cargoSha256 = "0hxm73diwiybljm6yy3vmwfdpg33b4rlg0h7afq4xgccq2vkwafs";
|
2019-08-17 15:50:45 +01:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "tree-sitter";
|
|
|
|
repo = "tree-sitter";
|
|
|
|
rev = version;
|
|
|
|
inherit sha256;
|
|
|
|
fetchSubmodules = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
update-all-grammars = import ./update.nix {
|
|
|
|
inherit writeShellScript nix-prefetch-git curl jq xe src;
|
|
|
|
};
|
|
|
|
|
2020-02-29 23:21:36 +00:00
|
|
|
fetchGrammar = (v: fetchgit {inherit (v) url rev sha256 fetchSubmodules; });
|
|
|
|
|
2019-08-17 15:50:45 +01:00
|
|
|
grammars =
|
2020-02-29 23:21:36 +00:00
|
|
|
runCommand "grammars" {} (''
|
2019-08-17 15:50:45 +01:00
|
|
|
mkdir $out
|
|
|
|
'' + (lib.concatStrings (lib.mapAttrsToList
|
2020-02-29 23:21:36 +00:00
|
|
|
(name: grammar: "ln -s ${fetchGrammar grammar} $out/${name}\n")
|
2019-08-17 15:50:45 +01:00
|
|
|
(import ./grammars))));
|
|
|
|
|
2020-02-29 23:21:36 +00:00
|
|
|
builtGrammars = let
|
|
|
|
change = name: grammar:
|
|
|
|
callPackage ./library.nix {
|
|
|
|
language = name; inherit version; source = fetchGrammar grammar;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
# typescript doesn't have parser.c in the same place as others
|
|
|
|
lib.mapAttrs change (removeAttrs (import ./grammars) ["typescript"]);
|
2019-08-17 15:50:45 +01:00
|
|
|
|
|
|
|
in rustPlatform.buildRustPackage {
|
|
|
|
pname = "tree-sitter";
|
2020-02-15 05:11:00 +00:00
|
|
|
inherit src version cargoSha256;
|
2019-08-17 15:50:45 +01:00
|
|
|
|
2020-02-15 05:11:00 +00:00
|
|
|
nativeBuildInputs = [ emscripten which ];
|
2019-08-17 15:50:45 +01:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
# needed for the tests
|
|
|
|
rm -rf test/fixtures/grammars
|
|
|
|
ln -s ${grammars} test/fixtures/grammars
|
|
|
|
'';
|
|
|
|
|
2020-02-15 05:11:00 +00:00
|
|
|
# Compile web assembly with emscripten. The --debug flag prevents us from
|
|
|
|
# minifying the JavaScript; passing it allows us to side-step more Node
|
|
|
|
# JS dependencies for installation.
|
|
|
|
preBuild = ''
|
|
|
|
HOME=/tmp
|
|
|
|
bash ./script/build-wasm --debug
|
|
|
|
'';
|
|
|
|
|
|
|
|
# test result: FAILED. 120 passed; 13 failed; 0 ignored; 0 measured; 0 filtered out
|
|
|
|
doCheck = false;
|
|
|
|
|
2019-08-17 15:50:45 +01:00
|
|
|
passthru = {
|
|
|
|
updater = {
|
|
|
|
inherit update-all-grammars;
|
|
|
|
};
|
|
|
|
inherit grammars;
|
2020-02-29 23:21:36 +00:00
|
|
|
inherit builtGrammars;
|
2019-08-17 15:50:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
homepage = "https://github.com/tree-sitter/tree-sitter";
|
|
|
|
description = "A parser generator tool and an incremental parsing library";
|
|
|
|
longDescription = ''
|
|
|
|
Tree-sitter is a parser generator tool and an incremental parsing library.
|
|
|
|
It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited.
|
|
|
|
|
|
|
|
Tree-sitter aims to be:
|
|
|
|
|
|
|
|
* General enough to parse any programming language
|
|
|
|
* Fast enough to parse on every keystroke in a text editor
|
|
|
|
* Robust enough to provide useful results even in the presence of syntax errors
|
|
|
|
* Dependency-free so that the runtime library (which is written in pure C) can be embedded in any application
|
|
|
|
'';
|
|
|
|
platforms = lib.platforms.all;
|
|
|
|
license = lib.licenses.mit;
|
|
|
|
maintainers = with lib.maintainers; [ Profpatsch ];
|
|
|
|
# Darwin needs some more work with default libraries
|
|
|
|
# Aarch has test failures with how tree-sitter compiles the generated C files
|
|
|
|
broken = stdenv.isDarwin || stdenv.isAarch64;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|