2010-08-11 21:06:11 +00:00
|
|
|
class Antlr < Formula
|
2014-05-20 00:39:55 +00:00
|
|
|
homepage "http://www.antlr.org/"
|
2014-07-24 05:07:16 +00:00
|
|
|
url "http://www.antlr.org/download/antlr-4.4-complete.jar"
|
|
|
|
sha1 "735569b1fa92a0d3f14bb5f3a3ffa713f5be4d1e"
|
2010-08-11 21:06:11 +00:00
|
|
|
|
|
|
|
def install
|
2013-07-17 00:44:03 +00:00
|
|
|
prefix.install "antlr-#{version}-complete.jar"
|
|
|
|
bin.write_jar_script prefix/"antlr-#{version}-complete.jar", "antlr4"
|
2014-05-19 16:57:37 +00:00
|
|
|
(bin+"grun").write <<-EOS.undent
|
|
|
|
#!/bin/bash
|
|
|
|
java -classpath #{prefix}/antlr-#{version}-complete.jar:. org.antlr.v4.runtime.misc.TestRig "$@"
|
|
|
|
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
|