93 lines
2.7 KiB
Ruby
93 lines
2.7 KiB
Ruby
class TreeSitter < Formula
|
|
desc "Parser generator tool and incremental parsing library"
|
|
homepage "https://tree-sitter.github.io/"
|
|
url "https://github.com/tree-sitter/tree-sitter/archive/0.17.3.tar.gz"
|
|
sha256 "a897e5c9a7ccb74271d9b20d59121d2d2e9de8b896c4d1cfaac0f8104c1ef9f8"
|
|
license "MIT"
|
|
head "https://github.com/tree-sitter/tree-sitter.git"
|
|
|
|
bottle do
|
|
cellar :any
|
|
rebuild 1
|
|
sha256 "c89bc31148685aa6c2abe0aca99d0283f3ac7ca8b95fdfd31f1b38c8e955ee7e" => :big_sur
|
|
sha256 "affadea701f887e8ae3f757ce88c3aa9cbc558887dfcf997c167f93e3a94af57" => :catalina
|
|
sha256 "1b745dd2fbd391ce0e26b639cb3202606f1d4f745e86a98a6f0d5c34ed3f8106" => :mojave
|
|
end
|
|
|
|
depends_on "rust" => :build
|
|
depends_on "emscripten"
|
|
depends_on "node"
|
|
|
|
def install
|
|
system "make"
|
|
system "make", "install", "PREFIX=#{prefix}"
|
|
|
|
cd "cli" do
|
|
system "cargo", "install", *std_cargo_args
|
|
end
|
|
end
|
|
|
|
test do
|
|
# a trivial tree-sitter test
|
|
assert_equal "tree-sitter #{version}", shell_output("#{bin}/tree-sitter --version").strip
|
|
|
|
# test `tree-sitter generate`
|
|
(testpath/"grammar.js").write <<~EOS
|
|
module.exports = grammar({
|
|
name: 'YOUR_LANGUAGE_NAME',
|
|
rules: {
|
|
source_file: $ => 'hello'
|
|
}
|
|
});
|
|
EOS
|
|
system "#{bin}/tree-sitter", "generate"
|
|
|
|
# test `tree-sitter parse`
|
|
(testpath/"test/corpus/hello.txt").write <<~EOS
|
|
hello
|
|
EOS
|
|
parse_result = shell_output("#{bin}/tree-sitter parse #{testpath}/test/corpus/hello.txt").strip
|
|
assert_equal("(source_file [0, 0] - [1, 0])", parse_result)
|
|
|
|
# test `tree-sitter test`
|
|
(testpath/"test"/"corpus"/"test_case.txt").write <<~EOS
|
|
=========
|
|
hello
|
|
=========
|
|
hello
|
|
---
|
|
(source_file)
|
|
EOS
|
|
system "#{bin}/tree-sitter", "test"
|
|
|
|
(testpath/"test_program.c").write <<~EOS
|
|
#include <string.h>
|
|
#include <tree_sitter/api.h>
|
|
int main(int argc, char* argv[]) {
|
|
TSParser *parser = ts_parser_new();
|
|
if (parser == NULL) {
|
|
return 1;
|
|
}
|
|
// Because we have no language libraries installed, we cannot
|
|
// actually parse a string succesfully. But, we can verify
|
|
// that it can at least be attempted.
|
|
const char *source_code = "empty";
|
|
TSTree *tree = ts_parser_parse_string(
|
|
parser,
|
|
NULL,
|
|
source_code,
|
|
strlen(source_code)
|
|
);
|
|
if (tree == NULL) {
|
|
printf("tree creation failed");
|
|
}
|
|
ts_tree_delete(tree);
|
|
ts_parser_delete(parser);
|
|
return 0;
|
|
}
|
|
EOS
|
|
system ENV.cc, "test_program.c", "-L#{lib}", "-ltree-sitter", "-o", "test_program"
|
|
assert_equal "tree creation failed", shell_output("./test_program")
|
|
end
|
|
end
|