tree-sitter/spec/compiler/generate_parsers.cpp

26 lines
897 B
C++
Raw Normal View History

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 "prepare_grammar.h"
2013-12-15 19:33:34 -08:00
#include "c_code.h"
2014-01-04 15:30:05 -08:00
#include "../fixtures/grammars/arithmetic.h"
2013-12-15 19:33:34 -08:00
#include <fstream>
START_TEST
2013-12-15 19:33:34 -08:00
describe("code generation", []() {
string test_parser_dir = src_dir() + "/spec/fixtures/parsers";
2013-12-15 19:33:34 -08:00
it("works for the arithmetic grammar", [&]() {
2013-12-15 19:33:34 -08:00
Grammar grammar = test_grammars::arithmetic();
auto grammars = prepare_grammar(grammar);
auto tables = lr::build_tables(grammars.first, grammars.second);
auto rule_names = grammars.first.rule_names();
auto token_names = grammars.second.rule_names();
rule_names.insert(rule_names.end(), token_names.begin(), token_names.end());
auto code = code_gen::c_code(rule_names, tables.first, tables.second);
ofstream(test_parser_dir + "/arithmetic.c") << code;
});
});
END_TEST