7 # Build a parser grammar and put the resulting shared object in `$out/parser`
19 stdenv.mkDerivation ({
20 pname = "${language}-grammar";
24 nativeBuildInputs = lib.optionals generate [ nodejs tree-sitter ];
26 CFLAGS = [ "-Isrc" "-O2" ];
27 CXXFLAGS = [ "-Isrc" "-O2" ];
29 stripDebugList = [ "parser" ];
31 configurePhase = lib.optionalString (location != null) ''
33 '' + lib.optionalString generate ''
37 # When both scanner.{c,cc} exist, we should not link both since they may be the same but in
38 # different languages. Just randomly prefer C++ if that happens.
41 if [[ -e src/scanner.cc ]]; then
42 $CXX -fPIC -c src/scanner.cc -o scanner.o $CXXFLAGS
43 elif [[ -e src/scanner.c ]]; then
44 $CC -fPIC -c src/scanner.c -o scanner.o $CFLAGS
46 $CC -fPIC -c src/parser.c -o parser.o $CFLAGS
48 $CXX -shared -o parser *.o
56 if [[ -d queries ]]; then
61 } // removeAttrs args [ "language" "location" "generate" ])