2014-03-08 15:26:27 -08:00
|
|
|
#include "compiler_spec_helper.h"
|
2014-02-17 13:15:52 -08:00
|
|
|
#include "../../examples/grammars/json.hpp"
|
|
|
|
|
#include "../../examples/grammars/arithmetic.hpp"
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
2014-03-08 15:26:27 -08:00
|
|
|
static string src_dir() {
|
|
|
|
|
const char * dir = getenv("TREESITTER_DIR");
|
|
|
|
|
if (!dir) dir = getenv("PWD");
|
|
|
|
|
return dir;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 13:15:52 -08:00
|
|
|
START_TEST
|
|
|
|
|
|
|
|
|
|
describe("compiling the example grammars", []() {
|
|
|
|
|
string example_parser_dir = src_dir() + "/examples/parsers/";
|
2014-03-08 15:26:27 -08:00
|
|
|
|
2014-02-17 13:15:52 -08:00
|
|
|
it("compiles the arithmetic grammar", [&]() {
|
|
|
|
|
Grammar grammar = test_grammars::arithmetic();
|
|
|
|
|
ofstream(example_parser_dir + "arithmetic.c") << compile(grammar, "arithmetic");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("compiles the json grammar", [&]() {
|
|
|
|
|
Grammar grammar = test_grammars::json();
|
|
|
|
|
ofstream(example_parser_dir + "json.c") << compile(grammar, "json");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2014-03-08 15:26:27 -08:00
|
|
|
END_TEST
|