Skip to content

Commit

Permalink
mike-lischke#136 Extract overall results output to procedure
Browse files Browse the repository at this point in the history
Signed-off-by: vityaman <vityaman.dev@yandex.ru>
  • Loading branch information
vityaman authored and mike-lischke committed Aug 26, 2024
1 parent a9a7b2e commit e4e3480
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
70 changes: 37 additions & 33 deletions ports/cpp/source/antlr4-c3/CodeCompletionCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,39 +138,7 @@ CandidatesCollection CodeCompletionCore::collectCandidates(
following.erase(std::begin(removed), std::end(removed));
}

if (debugOptions.showResult) {
if (candidates.isCancelled) {
std::cout << "*** TIMED OUT ***\n";
}

std::cout << "States processed: " << statesProcessed << "\n\n";

std::cout << "Collected rules:\n";
for (const auto& [tokenIndex, rule] : candidates.rules) {
std::cout << ruleNames->at(tokenIndex);
std::cout << ", path: ";

for (const size_t token : rule.ruleList) {
std::cout << ruleNames->at(token) << " ";
}
}
std::cout << "\n\n";

std::set<std::string> sortedTokens;
for (const auto& [token, tokenList] : candidates.tokens) {
std::string value = vocabulary->getDisplayName(token);
for (const size_t following : tokenList) {
value += " " + vocabulary->getDisplayName(following);
}
sortedTokens.emplace(value);
}

std::cout << "Collected tokens:\n";
for (const std::string& symbol : sortedTokens) {
std::cout << symbol;
}
std::cout << "\n\n";
}
printOverallResults();

return candidates;
}
Expand Down Expand Up @@ -857,4 +825,40 @@ void CodeCompletionCore::printRuleState(RuleWithStartTokenList const& stack) {
std::cout << "\n";
}

void CodeCompletionCore::printOverallResults() {
if (debugOptions.showResult) {
if (candidates.isCancelled) {
std::cout << "*** TIMED OUT ***\n";
}

std::cout << "States processed: " << statesProcessed << "\n\n";

std::cout << "Collected rules:\n";
for (const auto& [tokenIndex, rule] : candidates.rules) {
std::cout << ruleNames->at(tokenIndex);
std::cout << ", path: ";

for (const size_t token : rule.ruleList) {
std::cout << ruleNames->at(token) << " ";
}
}
std::cout << "\n\n";

std::set<std::string> sortedTokens;
for (const auto& [token, tokenList] : candidates.tokens) {
std::string value = vocabulary->getDisplayName(token);
for (const size_t following : tokenList) {
value += " " + vocabulary->getDisplayName(following);
}
sortedTokens.emplace(value);
}

std::cout << "Collected tokens:\n";
for (const std::string& symbol : sortedTokens) {
std::cout << symbol;
}
std::cout << "\n\n";
}
}

} // namespace c3
2 changes: 2 additions & 0 deletions ports/cpp/source/antlr4-c3/CodeCompletionCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ class CodeCompletionCore {
);

void printRuleState(RuleWithStartTokenList const& stack);

void printOverallResults();
};

} // namespace c3

0 comments on commit e4e3480

Please sign in to comment.