tree-sitter/spec/compiler/compile_examples.cc

37 lines
929 B
C++
Raw Normal View History

#include "compiler_spec_helper.h"
#include <fstream>
static string src_dir() {
const char * dir = getenv("TREESITTER_DIR");
if (!dir) dir = getenv("PWD");
return dir;
}
namespace tree_sitter {
namespace examples {
Grammar arithmetic();
2014-03-24 09:14:29 -07:00
Grammar javascript();
Grammar json();
}
}
START_TEST
describe("compiling the example grammars", []() {
string example_parser_dir = src_dir() + "/examples/parsers/";
auto compile_grammar = [&](Grammar grammar, string language) {
it(("compiles the " + language + " grammar").c_str(), [&]() {
2014-03-26 12:52:31 -07:00
ofstream file(example_parser_dir + language + ".c");
file << compile(grammar, language);
file.close();
});
};
2014-03-24 09:14:29 -07:00
compile_grammar(examples::arithmetic(), "arithmetic");
compile_grammar(examples::json(), "json");
2014-03-24 09:14:29 -07:00
compile_grammar(examples::javascript(), "javascript");
});
END_TEST