about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/tools/parsing/antlr/4.nix
blob: a4b2034852f2ff1f26e5b222e94e25ec694c89f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
{ lib, stdenv, fetchurl, jre
, fetchFromGitHub, cmake, ninja, pkg-config

# darwin only
, CoreFoundation ? null

# ANTLR 4.8 & 4.9
, libuuid

# ANTLR 4.9
, utf8cpp }:

let

  mkAntlr = {
    version, sourceSha256, jarSha256,
    extraCppBuildInputs ? [],
    extraCppCmakeFlags ? [],
    extraPatches ? [ ]
  }: rec {
    source = fetchFromGitHub {
      owner = "antlr";
      repo = "antlr4";
      rev = version;
      sha256 = sourceSha256;
    };

    antlr = stdenv.mkDerivation {
      pname = "antlr";
      inherit version;

      src = fetchurl {
        url = "https://www.antlr.org/download/antlr-${version}-complete.jar";
        sha256 = jarSha256;
      };

      dontUnpack = true;

      installPhase = ''
        mkdir -p "$out"/{share/java,bin}
        cp "$src" "$out/share/java/antlr-${version}-complete.jar"

        echo "#! ${stdenv.shell}" >> "$out/bin/antlr"
        echo "'${jre}/bin/java' -cp '$out/share/java/antlr-${version}-complete.jar:$CLASSPATH' -Xmx500M org.antlr.v4.Tool \"\$@\"" >> "$out/bin/antlr"

        echo "#! ${stdenv.shell}" >> "$out/bin/antlr-parse"
        echo "'${jre}/bin/java' -cp '$out/share/java/antlr-${version}-complete.jar:$CLASSPATH' -Xmx500M org.antlr.v4.gui.Interpreter \"\$@\"" >> "$out/bin/antlr-parse"

        echo "#! ${stdenv.shell}" >> "$out/bin/grun"
        echo "'${jre}/bin/java' -cp '$out/share/java/antlr-${version}-complete.jar:$CLASSPATH' org.antlr.v4.gui.TestRig \"\$@\"" >> "$out/bin/grun"

        chmod a+x "$out/bin/antlr" "$out/bin/antlr-parse" "$out/bin/grun"
        ln -s "$out/bin/antlr"{,4}
        ln -s "$out/bin/antlr"{,4}-parse
      '';

      inherit jre;

      passthru = {
        inherit runtime;
        jarLocation = "${antlr}/share/java/antlr-${version}-complete.jar";
      };

      meta = with lib; {
        description = "Powerful parser generator";
        longDescription = ''
          ANTLR (ANother Tool for Language Recognition) is a powerful parser
          generator for reading, processing, executing, or translating structured
          text or binary files. It's widely used to build languages, tools, and
          frameworks. From a grammar, ANTLR generates a parser that can build and
          walk parse trees.
        '';
        homepage = "https://www.antlr.org/";
        sourceProvenance = with sourceTypes; [ binaryBytecode ];
        license = licenses.bsd3;
        platforms = platforms.unix;
      };
    };

    runtime = {
      cpp = stdenv.mkDerivation {
        pname = "antlr-runtime-cpp";
        inherit version;
        src = source;

        patches = extraPatches;

        outputs = [ "out" "dev" "doc" ];

        nativeBuildInputs = [ cmake ninja pkg-config ];
        buildInputs =
          lib.optional stdenv.isDarwin CoreFoundation ++
          extraCppBuildInputs;

        cmakeDir = "../runtime/Cpp";

        cmakeFlags = extraCppCmakeFlags;

        meta = with lib; {
          description = "C++ target for ANTLR 4";
          homepage = "https://www.antlr.org/";
          license = licenses.bsd3;
          platforms = platforms.unix;
        };
      };
    };
  };

in {
  antlr4_13 = (mkAntlr {
    version = "4.13.0";
    sourceSha256 = "sha256-s1yAdScMYg1wFpYNsBAtpifIhQsnSAgJg7JjPDx+htc=";
    jarSha256 = "sha256-vG9KvA0iWidXASbFFAJWnwAKje2jSHtw52QoQOVw5KY=";
    extraCppCmakeFlags = [
      # Generate CMake config files, which are not installed by default.
      "-DANTLR4_INSTALL=ON"

      # Disable tests, since they require downloading googletest, which is
      # not available in a sandboxed build.
      "-DANTLR_BUILD_CPP_TESTS=OFF"
    ];
  }).antlr;

  antlr4_12 = (mkAntlr {
    version = "4.12.0";
    sourceSha256 = "sha256-0JMG8UYFT+IAWvARY2KnuXSr5X6LlVZN4LJHy5d4x08=";
    jarSha256 = "sha256-iPGKK/rA3eEAntpcfc41ilKHf673ho9WIjpbzBUynkM=";
    extraCppCmakeFlags = [
      # Generate CMake config files, which are not installed by default.
      "-DANTLR4_INSTALL=ON"

      # Disable tests, since they require downloading googletest, which is
      # not available in a sandboxed build.
      "-DANTLR_BUILD_CPP_TESTS=OFF"
    ];
  }).antlr;

  antlr4_11 = (mkAntlr {
    version = "4.11.1";
    sourceSha256 = "sha256-SUeDgfqLjYQorC8r/CKlwbYooTThMOILkizwQV8pocc=";
    jarSha256 = "sha256-YpdeGStK8mIrcrXwExVT7jy86X923CpBYy3MVeJUc+E=";
    extraCppCmakeFlags = [
      # Generate CMake config files, which are not installed by default.
      "-DANTLR4_INSTALL=ON"

      # Disable tests, since they require downloading googletest, which is
      # not available in a sandboxed build.
      "-DANTLR_BUILD_CPP_TESTS=OFF"
    ];
  }).antlr;

  antlr4_10 = (mkAntlr {
    version = "4.10.1";
    sourceSha256 = "sha256-Z1P81L0aPbimitzrHH/9rxsMCA6Qn3i42jFbUmVqu1E=";
    jarSha256 = "sha256-QZSdQfINMdW4J3GHc13XVRCN9Ss422yGUQjTOCBA+Rg=";
    extraCppBuildInputs = lib.optional stdenv.isLinux libuuid;
    extraCppCmakeFlags = [
      "-DANTLR4_INSTALL=ON"
      "-DANTLR_BUILD_CPP_TESTS=OFF"
    ];
  }).antlr;

  antlr4_9 = (mkAntlr {
    version = "4.9.3";
    sourceSha256 = "1af3cfqwk7lq1b5qsh1am0922fyhy7wmlpnrqdnvch3zzza9n1qm";
    jarSha256 = "0dnz2x54kigc58bxnynjhmr5iq49f938vj6p50gdir1xdna41kdg";
    extraCppBuildInputs = [ utf8cpp ]
      ++ lib.optional stdenv.isLinux libuuid;
    extraCppCmakeFlags = [
      "-DCMAKE_CXX_FLAGS='-I${lib.getDev utf8cpp}/include/utf8cpp'"
    ];
    extraPatches = [
      ./utf8cpp.patch
    ];
  }).antlr;

  antlr4_8 = (mkAntlr {
    version = "4.8";
    sourceSha256 = "1qal3add26qxskm85nk7r758arladn5rcyjinmhlhznmpbbv9j8m";
    jarSha256 = "0nms976cnqyr1ndng3haxkmknpdq6xli4cpf4x4al0yr21l9v93k";
    extraCppBuildInputs = lib.optional stdenv.isLinux libuuid;
    extraCppCmakeFlags = [ "-DANTLR4_INSTALL=ON" ];
  }).antlr;
}