From b010e1667e769efc7dfee234d14ce354c11733f1 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 6 May 2014 12:51:38 -0700 Subject: [PATCH] Fix parse action equality method --- spec/compiler/build_tables/build_parse_table_spec.cc | 5 ++++- src/compiler/parse_table.cc | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/spec/compiler/build_tables/build_parse_table_spec.cc b/spec/compiler/build_tables/build_parse_table_spec.cc index ba9d80b9..462a442b 100644 --- a/spec/compiler/build_tables/build_parse_table_spec.cc +++ b/spec/compiler/build_tables/build_parse_table_spec.cc @@ -25,7 +25,10 @@ describe("building parse tables", []() { auto result = build_parse_table(parse_grammar, lex_grammar); AssertThat(result.first.states[0].actions, Equals(map({ + // start item { Symbol(0), ParseAction::Shift(1, { 0 }) }, + + // expanded from the item set closure of the start item { Symbol(1), ParseAction::Shift(2, { 0 }) }, { Symbol(2), ParseAction::Shift(2, { 0 }) }, { Symbol(0, SymbolOptionToken), ParseAction::Shift(3, { 0 }) }, @@ -45,7 +48,7 @@ describe("building parse tables", []() { auto result = build_parse_table(parse_grammar, lex_grammar); AssertThat(result.first.states[2].actions, Equals(map({ - { END_OF_INPUT(), ParseAction::Reduce(Symbol(1), 1, 0) }, + { END_OF_INPUT(), ParseAction::Reduce(Symbol(0), 1, 0) }, }))); }); }); diff --git a/src/compiler/parse_table.cc b/src/compiler/parse_table.cc index e9a7ef19..e5e791e3 100644 --- a/src/compiler/parse_table.cc +++ b/src/compiler/parse_table.cc @@ -44,9 +44,10 @@ namespace tree_sitter { bool ParseAction::operator==(const ParseAction &other) const { bool types_eq = type == other.type; + bool symbols_eq = symbol == other.symbol; bool state_indices_eq = state_index == other.state_index; bool consumed_symbol_counts_eq = consumed_symbol_count == other.consumed_symbol_count; - return types_eq && state_indices_eq && consumed_symbol_counts_eq; + return types_eq && symbols_eq && state_indices_eq && consumed_symbol_counts_eq; } ostream& operator<<(ostream &stream, const ParseAction &action) { @@ -58,7 +59,7 @@ namespace tree_sitter { case ParseActionTypeShift: return stream << (string("#"); case ParseActionTypeReduce: - return stream << (string("#"); + return stream << (string("#"); default: return stream; }