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