2020-02-29 23:21:36 +00:00
|
|
|
{ stdenv
|
|
|
|
, tree-sitter
|
2021-05-31 15:20:22 +00:00
|
|
|
, libcxx
|
|
|
|
, lib
|
2020-12-13 05:54:25 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
# Build a parser grammar and put the resulting shared object in `$out/parser`
|
|
|
|
|
|
|
|
{
|
|
|
|
# language name
|
|
|
|
language
|
|
|
|
# version of tree-sitter
|
2020-02-29 23:21:36 +00:00
|
|
|
, version
|
2020-12-13 05:54:25 +00:00
|
|
|
# source for the language grammar
|
2020-02-29 23:21:36 +00:00
|
|
|
, source
|
2021-03-03 22:15:27 +00:00
|
|
|
, location ? null
|
2020-02-29 23:21:36 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
|
2020-12-24 01:52:32 +00:00
|
|
|
pname = "${language}-grammar";
|
2020-02-29 23:21:36 +00:00
|
|
|
inherit version;
|
|
|
|
|
2021-03-03 22:15:27 +00:00
|
|
|
src =
|
|
|
|
if location == null
|
|
|
|
then
|
|
|
|
source
|
|
|
|
else
|
|
|
|
"${source}/${location}"
|
|
|
|
;
|
2020-02-29 23:21:36 +00:00
|
|
|
|
2021-05-31 15:20:22 +00:00
|
|
|
NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1";
|
2020-02-29 23:21:36 +00:00
|
|
|
buildInputs = [ tree-sitter ];
|
|
|
|
|
|
|
|
dontUnpack = true;
|
2021-07-18 21:42:48 +00:00
|
|
|
dontConfigure = true;
|
|
|
|
|
2020-02-29 23:21:36 +00:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
2020-09-22 18:40:36 +00:00
|
|
|
scanner_cc="$src/src/scanner.cc"
|
|
|
|
if [ ! -f "$scanner_cc" ]; then
|
|
|
|
scanner_cc=""
|
|
|
|
fi
|
2021-01-07 05:13:23 +00:00
|
|
|
scanner_c="$src/src/scanner.c"
|
|
|
|
if [ ! -f "$scanner_c" ]; then
|
|
|
|
scanner_c=""
|
|
|
|
fi
|
|
|
|
$CC -I$src/src/ -shared -o parser -Os $src/src/parser.c $scanner_cc $scanner_c -lstdc++
|
2020-02-29 23:21:36 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir $out
|
|
|
|
mv parser $out/
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
}
|