2020-04-24 23:36:52 +00:00
|
|
|
{ stdenv
|
|
|
|
, tree-sitter
|
2021-06-28 23:13:55 +00:00
|
|
|
, libcxx
|
|
|
|
, lib
|
2020-12-25 13:55:36 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
# Build a parser grammar and put the resulting shared object in `$out/parser`
|
|
|
|
|
|
|
|
{
|
|
|
|
# language name
|
|
|
|
language
|
|
|
|
# version of tree-sitter
|
2020-04-24 23:36:52 +00:00
|
|
|
, version
|
2020-12-25 13:55:36 +00:00
|
|
|
# source for the language grammar
|
2020-04-24 23:36:52 +00:00
|
|
|
, source
|
2021-03-16 09:55:35 +00:00
|
|
|
, location ? null
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
pname = "${language}-grammar";
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit version;
|
|
|
|
|
2021-03-16 09:55:35 +00:00
|
|
|
src =
|
|
|
|
if location == null
|
|
|
|
then
|
|
|
|
source
|
|
|
|
else
|
|
|
|
"${source}/${location}"
|
|
|
|
;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1";
|
2020-04-24 23:36:52 +00:00
|
|
|
buildInputs = [ tree-sitter ];
|
|
|
|
|
|
|
|
dontUnpack = true;
|
2021-07-21 07:28:18 +00:00
|
|
|
dontConfigure = true;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
2020-10-07 09:15:18 +00:00
|
|
|
scanner_cc="$src/src/scanner.cc"
|
|
|
|
if [ ! -f "$scanner_cc" ]; then
|
|
|
|
scanner_cc=""
|
|
|
|
fi
|
2021-03-09 03:18:52 +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-04-24 23:36:52 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir $out
|
|
|
|
mv parser $out/
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
}
|