forked from sjackman/linuxbrew-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
antlr.rb
45 lines (39 loc) · 1.33 KB
/
antlr.rb
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
class Antlr < Formula
desc "ANother Tool for Language Recognition"
homepage "https://www.antlr.org/"
url "https://www.antlr.org/download/antlr-4.8-complete.jar"
sha256 "73a49d6810d903aa4827ee32126937b85d3bebec0a8e679b0dd963cbcc49ba5a"
revision 1
bottle :unneeded
depends_on "openjdk"
def install
prefix.install "antlr-#{version}-complete.jar"
(bin/"antlr").write <<~EOS
#!/bin/bash
CLASSPATH="#{prefix}/antlr-#{version}-complete.jar:." exec "#{Formula["openjdk"].opt_bin}/java" -jar #{prefix}/antlr-#{version}-complete.jar "$@"
EOS
(bin/"grun").write <<~EOS
#!/bin/bash
exec "#{Formula["openjdk"].opt_bin}/java" -classpath #{prefix}/antlr-#{version}-complete.jar:. org.antlr.v4.gui.TestRig "$@"
EOS
end
test do
path = testpath/"Expr.g4"
path.write <<~EOS
grammar Expr;
prog:\t(expr NEWLINE)* ;
expr:\texpr ('*'|'/') expr
|\texpr ('+'|'-') expr
|\tINT
|\t'(' expr ')'
;
NEWLINE :\t[\\r\\n]+ ;
INT :\t[0-9]+ ;
EOS
ENV.prepend "CLASSPATH", "#{prefix}/antlr-#{version}-complete.jar", ":"
ENV.prepend "CLASSPATH", ".", ":"
system "#{bin}/antlr", "Expr.g4"
system "#{Formula["openjdk"].bin}/javac", *Dir["Expr*.java"]
assert_match(/^$/, pipe_output("#{bin}/grun Expr prog", "22+20\n"))
end
end