From 6951acb13b45d53d6414adbabdd5d1715ac4e410 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 13 Jul 2014 21:26:21 -0700 Subject: [PATCH] Fix error when grammar contains to error productions --- spec/compiler/build_tables/build_parse_table_spec.cc | 5 +++++ src/compiler/build_tables/build_parse_table.cc | 2 ++ 2 files changed, 7 insertions(+) diff --git a/spec/compiler/build_tables/build_parse_table_spec.cc b/spec/compiler/build_tables/build_parse_table_spec.cc index 040f318d..c50bf8c1 100644 --- a/spec/compiler/build_tables/build_parse_table_spec.cc +++ b/spec/compiler/build_tables/build_parse_table_spec.cc @@ -39,6 +39,11 @@ describe("building parse tables", []() { }))); }); + it("ensures that the built-in 'ERROR' symbol is in the symbol set", [&]() { + auto result = build_parse_table(parse_grammar, lex_grammar); + AssertThat(result.first.symbols, Contains(rules::ERROR())); + }); + it("accepts the input when EOF occurs after the start rule", [&]() { auto result = build_parse_table(parse_grammar, lex_grammar); diff --git a/src/compiler/build_tables/build_parse_table.cc b/src/compiler/build_tables/build_parse_table.cc index 9319fdcd..89ecd877 100644 --- a/src/compiler/build_tables/build_parse_table.cc +++ b/src/compiler/build_tables/build_parse_table.cc @@ -127,6 +127,8 @@ namespace tree_sitter { ParseItem start_item(rules::START(), make_shared(0), 0); add_parse_state(item_set_closure(start_item, { rules::END_OF_INPUT() }, grammar)); + parse_table.symbols.insert(rules::ERROR()); + while (!item_sets_to_process.empty()) { auto pair = item_sets_to_process.back(); ParseItemSet &item_set = pair.first;