137 lines
4.2 KiB
Ruby
137 lines
4.2 KiB
Ruby
class Bnfc < Formula
|
|
desc "BNF Converter"
|
|
homepage "https://bnfc.digitalgrammars.com/"
|
|
url "https://github.com/BNFC/bnfc/archive/v2.9.1.tar.gz"
|
|
sha256 "d79125168636fdcf0acd64a9b83ea620c311b16dcada0848d8a577aa8aeddec4"
|
|
license "BSD-3-Clause"
|
|
head "https://github.com/BNFC/bnfc.git"
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, big_sur: "173f30b8a4c701eefc9e6b5c702f55237e0104a2b33120004aa1661c276483a2"
|
|
sha256 cellar: :any_skip_relocation, catalina: "6733cd26b5cdb5c8bc5ed05e1ef648eab9e56d8e484e680166894ca195dd9390"
|
|
sha256 cellar: :any_skip_relocation, mojave: "df909d3e8bfa179f607fd208beaff741e9ff02e3dc5f75e3890c5707685e4424"
|
|
end
|
|
|
|
depends_on "cabal-install" => [:build, :test]
|
|
depends_on "ghc" => [:build, :test]
|
|
depends_on "sphinx-doc" => :build
|
|
depends_on "antlr" => :test
|
|
depends_on "openjdk" => :test
|
|
|
|
uses_from_macos "bison" => :test
|
|
uses_from_macos "flex" => :test
|
|
|
|
def install
|
|
cd "source" do
|
|
system "cabal", "v2-update"
|
|
system "cabal", "v2-install", *std_cabal_v2_args
|
|
doc.install "CHANGELOG.md"
|
|
doc.install "src/BNFC.cf" => "BNFC.cf"
|
|
end
|
|
cd "docs" do
|
|
system "make", "text", "man", "SPHINXBUILD=#{Formula["sphinx-doc"].bin/"sphinx-build"}"
|
|
cd "_build" do
|
|
doc.install "text" => "manual"
|
|
man1.install "man/bnfc.1" => "bnfc.1"
|
|
end
|
|
end
|
|
doc.install %w[README.md examples]
|
|
end
|
|
|
|
test do
|
|
ENV.prepend_create_path "PATH", testpath/"tools-bin"
|
|
|
|
(testpath/"calc.cf").write <<~EOS
|
|
EAdd. Exp ::= Exp "+" Exp1 ;
|
|
ESub. Exp ::= Exp "-" Exp1 ;
|
|
EMul. Exp1 ::= Exp1 "*" Exp2 ;
|
|
EDiv. Exp1 ::= Exp1 "/" Exp2 ;
|
|
EInt. Exp2 ::= Integer ;
|
|
coercions Exp 2 ;
|
|
entrypoints Exp ;
|
|
comment "(#" "#)" ;
|
|
EOS
|
|
(testpath/"test.calc").write "14 * (# Parsing is fun! #) (3 + 2 / 5 - 8)"
|
|
treespace = if build.head?
|
|
" "
|
|
else
|
|
""
|
|
end
|
|
check_out = <<~EOS
|
|
|
|
Parse Successful!
|
|
|
|
[Abstract Syntax]
|
|
(EMul (EInt 14) (ESub (EAdd (EInt 3) (EDiv (EInt 2) (EInt 5))) (EInt 8)))
|
|
|
|
[Linearized Tree]
|
|
14 * (3 + 2 / 5 - 8) #{treespace}
|
|
|
|
EOS
|
|
|
|
mktemp "c-test" do
|
|
system bin/"bnfc", "-m", "-o.", "--c", testpath/"calc.cf"
|
|
system "make", "CC=#{ENV.cc}", "CCFLAGS=#{ENV.cflags}"
|
|
test_out = shell_output("./Testcalc #{testpath}/test.calc")
|
|
assert_equal check_out, test_out
|
|
end
|
|
|
|
mktemp "cxx-test" do
|
|
system bin/"bnfc", "-m", "-o.", "--cpp", testpath/"calc.cf"
|
|
system "make", "CC=#{ENV.cxx}", "CCFLAGS=#{ENV.cxxflags}"
|
|
test_out = shell_output("./Testcalc #{testpath}/test.calc")
|
|
assert_equal check_out, test_out
|
|
end
|
|
|
|
mktemp "haskell-test" do
|
|
system "cabal", "v2-update"
|
|
system "cabal", "v2-install",
|
|
"--jobs=#{ENV.make_jobs}", "--max-backjumps=100000",
|
|
"--install-method=copy", "--installdir=#{testpath/"tools-bin"}",
|
|
"alex", "happy"
|
|
system bin/"bnfc", "-m", "-o.", "--haskell", "--ghc", "-d", testpath/"calc.cf"
|
|
system "make"
|
|
test_out = shell_output("./Calc/Test #{testpath/"test.calc"}")
|
|
check_out_hs = <<~EOS
|
|
#{testpath/"test.calc"}
|
|
|
|
Parse Successful!
|
|
|
|
[Abstract Syntax]
|
|
|
|
EMul (EInt 14) (ESub (EAdd (EInt 3) (EDiv (EInt 2) (EInt 5))) (EInt 8))
|
|
|
|
[Linearized tree]
|
|
|
|
14 * (3 + 2 / 5 - 8)
|
|
EOS
|
|
assert_equal check_out_hs, test_out
|
|
end
|
|
|
|
mktemp "java-test" do
|
|
ENV.deparallelize # only the Java test needs this
|
|
jdk_dir = Formula["openjdk"].bin
|
|
antlr_bin = Formula["antlr"].bin/"antlr"
|
|
antlr_jar = Dir[Formula["antlr"].prefix/"antlr-*-complete.jar"][0]
|
|
ENV["CLASSPATH"] = ".:#{antlr_jar}"
|
|
system bin/"bnfc", "-m", "-o.", "--java", "--antlr4", testpath/"calc.cf"
|
|
system "make", "JAVAC=#{jdk_dir/"javac"}", "JAVA=#{jdk_dir/"java"}", "LEXER=#{antlr_bin}", "PARSER=#{antlr_bin}"
|
|
test_out = shell_output("#{jdk_dir}/java calc.Test #{testpath}/test.calc")
|
|
space = " "
|
|
check_out_j = <<~EOS
|
|
|
|
Parse Succesful!
|
|
|
|
[Abstract Syntax]
|
|
|
|
(EMul (EInt 14) (ESub (EAdd (EInt 3) (EDiv (EInt 2) (EInt 5))) (EInt 8)))#{space}
|
|
|
|
[Linearized Tree]
|
|
|
|
14 * (3 + 2 / 5 - 8)
|
|
EOS
|
|
assert_equal check_out_j, test_out
|
|
end
|
|
end
|
|
end
|