@ -5,6 +5,7 @@
runCommand ,
yj ,
includeGrammarIf ? _ : true ,
grammarOverlays ? [ ] ,
. . .
} : let
# HACK: nix < 2.6 has a bug in the toml parser, so we convert to JSON
@ -48,22 +49,22 @@
then sourceGitHub
else sourceGit ;
in
stdenv . mkDerivation rec {
stdenv . mkDerivation {
# see https://github.com/NixOS/nixpkgs/blob/fbdd1a7c0bc29af5325e0d7dd70e804a972eb465/pkgs/development/tools/parsing/tree-sitter/grammar.nix
pname = " h e l i x - t r e e - s i t t e r - ${ grammar . name } " ;
version = grammar . source . rev ;
src =
if builtins . hasAttr " s u b p a t h " grammar . source
then " ${ source } / ${ grammar . source . subpath } "
else source ;
src = source ;
sourceRoot = if builtins . hasAttr " s u b p a t h " grammar . source then
" s o u r c e / ${ grammar . source . subpath } "
else
" s o u r c e " ;
dontUnpack = true ;
dontConfigure = true ;
FLAGS = [
" - I ${ src } / s r c "
" - I s r c "
" - g "
" - O 3 "
" - f P I C "
@ -76,13 +77,13 @@
buildPhase = ''
runHook preBuild
if [ [ - e " $ s r c / s r c / s c a n n e r . c c " ] ] ; then
$ CXX - c " $ s r c / s r c / s c a n n e r . c c " - o scanner . o $ FLAGS
elif [ [ - e " $ s r c / s r c / s c a n n e r . c " ] ] ; then
$ CC - c " $ s r c / s r c / s c a n n e r . c " - o scanner . o $ FLAGS
if [ [ - e src/scanner.cc ] ] ; then
$ CXX - c src/scanner.cc - o scanner . o $ FLAGS
elif [ [ - e src/scanner.c ] ] ; then
$ CC - c src/scanner.c - o scanner . o $ FLAGS
fi
$ CC - c " $ s r c / s r c / p a r s e r . c " - o parser . o $ FLAGS
$ CC - c src/parser.c - o parser . o $ FLAGS
$ CXX - shared - o $ NAME . so * . o
ls - al
@ -105,15 +106,17 @@
'' ;
} ;
grammarsToBuild = builtins . filter includeGrammarIf gitGrammars ;
builtGrammars =
builtins . map ( grammar : {
builtGrammars = builtins . map ( grammar : {
inherit ( grammar ) name ;
artifact = buildGrammar grammar ;
} )
grammarsToBuild ;
grammarLinks =
builtins . map ( grammar : " l n - s ${ grammar . artifact } / ${ grammar . name } . s o $ o u t / ${ grammar . name } . s o " )
builtGrammars ;
value = buildGrammar grammar ;
} ) grammarsToBuild ;
extensibleGrammars =
lib . makeExtensible ( self : builtins . listToAttrs builtGrammars ) ;
overlayedGrammars = lib . pipe extensibleGrammars
( builtins . map ( overlay : grammar : grammar . extend overlay ) grammarOverlays ) ;
grammarLinks = lib . mapAttrsToList
( name : artifact : " l n - s ${ artifact } / ${ name } . s o $ o u t / ${ name } . s o " )
( lib . filterAttrs ( n : v : lib . isDerivation v ) overlayedGrammars ) ;
in
runCommand " c o n s o l i d a t e d - h e l i x - g r a m m a r s " { } ''
mkdir - p $ out