2010-08-11 21:06:11 +00:00
|
|
|
class Antlr < Formula
|
2015-05-19 00:00:59 +00:00
|
|
|
desc "ANTLR: ANother Tool for Language Recognition"
|
2014-05-20 00:39:55 +00:00
|
|
|
homepage "http://www.antlr.org/"
|
2016-08-31 20:52:44 +00:00
|
|
|
url "http://www.antlr.org/download/antlr-4.5.3-complete.jar"
|
|
|
|
sha256 "a32de739cfdf515774e696f91aa9697d2e7731e5cb5045ca8a4b657f8b1b4fb4"
|
2010-08-11 21:06:11 +00:00
|
|
|
|
2015-10-23 08:27:01 +00:00
|
|
|
bottle :unneeded
|
|
|
|
|
2010-08-11 21:06:11 +00:00
|
|
|
def install
|
2013-07-17 00:44:03 +00:00
|
|
|
prefix.install "antlr-#{version}-complete.jar"
|
2015-10-26 00:11:29 +00:00
|
|
|
|
|
|
|
(bin/"antlr4").write <<-EOS.undent
|
|
|
|
#!/bin/bash
|
2015-10-28 04:00:29 +00:00
|
|
|
CLASSPATH="#{prefix}/antlr-#{version}-complete.jar:." exec java -jar #{prefix}/antlr-#{version}-complete.jar "$@"
|
2015-10-26 00:11:29 +00:00
|
|
|
EOS
|
|
|
|
|
|
|
|
(bin/"grun").write <<-EOS.undent
|
2014-05-19 16:57:37 +00:00
|
|
|
#!/bin/bash
|
2016-03-29 06:16:55 +00:00
|
|
|
java -classpath #{prefix}/antlr-#{version}-complete.jar:. org.antlr.v4.gui.TestRig "$@"
|
2014-05-19 16:57:37 +00:00
|
|
|
EOS
|
2010-08-11 21:06:11 +00:00
|
|
|
end
|
2015-01-03 13:32:26 +00:00
|
|
|
|
|
|
|
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
|
2011-03-10 05:11:03 +00:00
|
|
|
end
|