2013-12-15 19:33:34 -08:00
|
|
|
#include "spec_helper.h"
|
2013-12-27 17:31:08 -08:00
|
|
|
#include "table_builder.h"
|
2013-12-15 19:33:34 -08:00
|
|
|
#include "parse_table.h"
|
|
|
|
|
#include "c_code.h"
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
2013-12-28 15:09:52 -08:00
|
|
|
START_TEST
|
2013-12-15 19:33:34 -08:00
|
|
|
|
2013-12-30 19:30:48 -08:00
|
|
|
describe("code generation", []() {
|
2013-12-15 23:57:30 -08:00
|
|
|
string test_parser_dir = src_dir() + "/spec/fixtures/parsers";
|
2013-12-15 19:33:34 -08:00
|
|
|
|
2013-12-28 15:09:52 -08:00
|
|
|
it("works for the arithmetic grammar", [&]() {
|
2013-12-15 19:33:34 -08:00
|
|
|
Grammar grammar = test_grammars::arithmetic();
|
2013-12-28 15:09:52 -08:00
|
|
|
auto tables = lr::build_tables(grammar);
|
|
|
|
|
string code = code_gen::c_code(grammar, tables.first, tables.second);
|
|
|
|
|
std::ofstream(test_parser_dir + "/arithmetic.c") << code;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
END_TEST
|