diff --git a/src/compiler/build_tables/lex_table_builder.cc b/src/compiler/build_tables/lex_table_builder.cc index fa8b86f3..1d873ae8 100644 --- a/src/compiler/build_tables/lex_table_builder.cc +++ b/src/compiler/build_tables/lex_table_builder.cc @@ -117,6 +117,7 @@ class LexTableBuilderImpl : public LexTableBuilder { if (following_tokens != following_tokens_by_token.end()) { following_tokens->second.for_each([&](Symbol following_token) { following_character_aggregator.apply(grammar.variables[following_token.index].rule); + return true; }); } @@ -177,7 +178,9 @@ class LexTableBuilderImpl : public LexTableBuilder { keyword_symbols.for_each([&](Symbol keyword_symbol) { if (!conflict_manager.possible_homonyms[symbol.index].count(keyword_symbol.index)) { matches_all_keywords = false; + return false; } + return true; }); if (!matches_all_keywords) continue; @@ -484,6 +487,7 @@ class LexTableBuilderImpl : public LexTableBuilder { } } } + return true; }); return result; } diff --git a/src/compiler/build_tables/lookahead_set.cc b/src/compiler/build_tables/lookahead_set.cc index 8b16add4..80ec58e1 100644 --- a/src/compiler/build_tables/lookahead_set.cc +++ b/src/compiler/build_tables/lookahead_set.cc @@ -35,7 +35,11 @@ bool LookaheadSet::contains(const Symbol &symbol) const { bool LookaheadSet::intersects(const LookaheadSet &other) const { bool result = false; for_each([&](Symbol symbol) { - if (other.contains(symbol)) result = true; + if (other.contains(symbol)) { + result = true; + return false; + } + return true; }); return result; } diff --git a/src/compiler/build_tables/lookahead_set.h b/src/compiler/build_tables/lookahead_set.h index 6898b5a2..bb9eeff9 100644 --- a/src/compiler/build_tables/lookahead_set.h +++ b/src/compiler/build_tables/lookahead_set.h @@ -32,12 +32,12 @@ class LookaheadSet { iter != end; ++iter) { if (*iter) { - callback(rules::Symbol::external(iter - begin)); + if (!callback(rules::Symbol::external(iter - begin))) return; } } if (eof) { - callback(rules::END_OF_INPUT()); + if (!callback(rules::END_OF_INPUT())) return; } for (auto begin = terminal_bits.begin(), @@ -46,7 +46,7 @@ class LookaheadSet { iter != end; ++iter) { if (*iter) { - callback(rules::Symbol::terminal(iter - begin)); + if (!callback(rules::Symbol::terminal(iter - begin))) return; } } } diff --git a/src/compiler/build_tables/parse_item.cc b/src/compiler/build_tables/parse_item.cc index 7e4d0c64..729cdc28 100644 --- a/src/compiler/build_tables/parse_item.cc +++ b/src/compiler/build_tables/parse_item.cc @@ -187,6 +187,7 @@ size_t hash::operator()(const ParseItemSet &item_set) const { hash_combine(&result, lookahead_set.size()); lookahead_set.for_each([&result](Symbol symbol) { hash_combine(&result, symbol); + return true; }); } return result; diff --git a/src/compiler/build_tables/parse_table_builder.cc b/src/compiler/build_tables/parse_table_builder.cc index cd2f2aff..f6a3ce60 100644 --- a/src/compiler/build_tables/parse_table_builder.cc +++ b/src/compiler/build_tables/parse_table_builder.cc @@ -239,6 +239,8 @@ class ParseTableBuilderImpl : public ParseTableBuilder { } } } + + return true; }); // If the item is unfinished, create a new item by advancing one symbol. @@ -835,13 +837,15 @@ class ParseTableBuilderImpl : public ParseTableBuilder { if (!left_tokens.empty() && !right_tokens.empty()) { left_tokens.for_each([&](Symbol left_symbol) { - if (!left_symbol.is_non_terminal() && !left_symbol.is_built_in()) { + if (left_symbol.is_terminal() && !left_symbol.is_built_in()) { right_tokens.for_each([&](Symbol right_symbol) { if (right_symbol.is_terminal() && !right_symbol.is_built_in()) { following_tokens_by_token[left_symbol].insert(right_symbol); } + return true; }); } + return true; }); } } diff --git a/test/helpers/stream_methods.cc b/test/helpers/stream_methods.cc index 5e20eb34..1ff791b6 100644 --- a/test/helpers/stream_methods.cc +++ b/test/helpers/stream_methods.cc @@ -210,6 +210,7 @@ ostream &operator<<(ostream &stream, const LookaheadSet &lookaheads) { stream << "(LookaheadSet"; lookaheads.for_each([&stream](Symbol symbol) { stream << " " << symbol; + return true; }); return stream << ")"; }