homebrew-core/Formula/antlr.rb
Mike McQuaid 382490df05 antlr: depends on java.
Closes #8376.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
2017-01-03 20:05:36 +00:00

44 lines
1.2 KiB
Ruby

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