homebrew-core/Formula/antlr.rb
René Schwaiger c53f882b7d antlr 4.7.2
Closes #35252.

Signed-off-by: Jan Viljanen <527069+javian@users.noreply.github.com>
2018-12-19 20:51:20 +01:00

44 lines
1.2 KiB
Ruby

class Antlr < Formula
desc "ANother Tool for Language Recognition"
homepage "https://www.antlr.org/"
url "https://www.antlr.org/download/antlr-4.7.2-complete.jar"
sha256 "6852386d7975eff29171dae002cc223251510d35f291ae277948f381a7b380b4"
bottle :unneeded
depends_on :java
def install
prefix.install "antlr-#{version}-complete.jar"
(bin/"antlr").write <<~EOS
#!/bin/bash
CLASSPATH="#{prefix}/antlr-#{version}-complete.jar:." exec java -jar #{prefix}/antlr-#{version}-complete.jar "$@"
EOS
(bin/"grun").write <<~EOS
#!/bin/bash
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 "javac", *Dir["Expr*.java"]
assert_match(/^$/, pipe_output("#{bin}/grun Expr prog", "22+20\n"))
end
end