Treat parse conflicts as errors in grammar compilation
For now, only reduce/reduce conflicts w/ no tie-breaking precedence are treated as errors. The rest are dropped, because shift/reduce conflicts are currently very common because we don't have a way of specifying associativity along w/ precedence.
This commit is contained in:
parent
8bd11e1b58
commit
9a198562e0
20 changed files with 1394 additions and 1408 deletions
|
|
@ -7,32 +7,35 @@
|
|||
|
||||
namespace tree_sitter {
|
||||
|
||||
using std::tuple;
|
||||
using std::pair;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::get;
|
||||
using std::make_tuple;
|
||||
|
||||
tuple<string, vector<Conflict>, const GrammarError *> compile(
|
||||
const Grammar &grammar, std::string name) {
|
||||
pair<string, const GrammarError *>
|
||||
compile(const Grammar &grammar, std::string name) {
|
||||
auto prepare_grammar_result = prepare_grammar::prepare_grammar(grammar);
|
||||
const SyntaxGrammar &syntax_grammar = get<0>(prepare_grammar_result);
|
||||
const LexicalGrammar &lexical_grammar = get<1>(prepare_grammar_result);
|
||||
const GrammarError *error = get<2>(prepare_grammar_result);
|
||||
|
||||
if (error)
|
||||
return make_tuple("", vector<Conflict>(), error);
|
||||
return {"", error};
|
||||
|
||||
auto table_build_result =
|
||||
build_tables::build_tables(syntax_grammar, lexical_grammar);
|
||||
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);
|
||||
error = get<2>(table_build_result);
|
||||
|
||||
if (error)
|
||||
return {"", error};
|
||||
|
||||
string code = generate_code::c_code(name, parse_table, lex_table,
|
||||
syntax_grammar, lexical_grammar);
|
||||
|
||||
return make_tuple(code, conflicts, nullptr);
|
||||
return {code, nullptr};
|
||||
}
|
||||
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue