Allow LookaheadSet::for_each to terminate early
This commit is contained in:
parent
43e14332ed
commit
a8bc67ac42
6 changed files with 19 additions and 5 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ size_t hash<ParseItemSet>::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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 << ")";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue