2014-02-17 12:53:57 -08:00
|
|
|
#include "tree_sitter/compiler.h"
|
2014-03-09 21:37:21 -07:00
|
|
|
#include "compiler/prepare_grammar/prepare_grammar.h"
|
|
|
|
|
#include "compiler/build_tables/build_tables.h"
|
|
|
|
|
#include "compiler/generate_code/c_code.h"
|
|
|
|
|
#include "compiler/prepared_grammar.h"
|
2014-01-11 15:14:17 -08:00
|
|
|
|
|
|
|
|
namespace tree_sitter {
|
2014-05-01 23:28:40 -07:00
|
|
|
using std::tuple;
|
2014-04-08 08:19:55 -07:00
|
|
|
using std::string;
|
|
|
|
|
using std::vector;
|
2014-05-01 23:28:40 -07:00
|
|
|
using std::get;
|
2014-05-04 19:49:09 -07:00
|
|
|
using std::make_tuple;
|
2014-04-08 08:19:55 -07:00
|
|
|
|
2014-05-01 23:28:40 -07:00
|
|
|
tuple<string, vector<Conflict>, const GrammarError *>
|
|
|
|
|
compile(const Grammar &grammar, std::string name) {
|
|
|
|
|
auto prepare_grammar_result = prepare_grammar::prepare_grammar(grammar);
|
|
|
|
|
const PreparedGrammar &syntax_grammar = get<0>(prepare_grammar_result);
|
|
|
|
|
const PreparedGrammar &lexical_grammar = get<1>(prepare_grammar_result);
|
|
|
|
|
const GrammarError *error = get<2>(prepare_grammar_result);
|
|
|
|
|
|
2014-05-04 19:49:09 -07:00
|
|
|
if (error)
|
|
|
|
|
return make_tuple("", vector<Conflict>(), error);
|
2014-03-27 12:54:54 -07:00
|
|
|
|
2014-04-22 23:38:26 -07:00
|
|
|
auto table_build_result = build_tables::build_tables(syntax_grammar, lexical_grammar);
|
2014-05-01 23:28:40 -07:00
|
|
|
const ParseTable &parse_table = get<0>(table_build_result);
|
|
|
|
|
const LexTable &lex_table = get<1>(table_build_result);
|
|
|
|
|
const vector<Conflict> &conflicts = get<2>(table_build_result);
|
2014-04-14 08:38:11 -07:00
|
|
|
|
2014-05-01 23:28:40 -07:00
|
|
|
string code = generate_code::c_code(name, parse_table, lex_table, syntax_grammar, lexical_grammar);
|
2014-03-27 12:54:54 -07:00
|
|
|
|
2014-05-04 19:49:09 -07:00
|
|
|
return make_tuple(code, conflicts, nullptr);
|
2014-01-11 15:14:17 -08:00
|
|
|
}
|
|
|
|
|
}
|