Skip to content

Instantly share code, notes, and snippets.

@Matts966
Created June 8, 2020 10:49
Show Gist options
  • Save Matts966/8ad0ac55b809d655dce4fcda0bd7ef79 to your computer and use it in GitHub Desktop.
Save Matts966/8ad0ac55b809d655dce4fcda0bd7ef79 to your computer and use it in GitHub Desktop.
// PrintCommentsPassedBy prints comments if they are before the given ParseLocationPoint
// and returns if comments are emitted.
bool Unparser::PrintCommentsPassedBy(const ParseLocationPoint point, void* data) {
if (data == nullptr) {
return false;
}
auto parse_tokens = static_cast<std::deque<std::pair<std::string, ParseLocationPoint>>*>(data);
if (parse_tokens == nullptr) {
return false;
}
bool emitted = false;
const int size = parse_tokens->size();
for (int i = 0; i < size; i++) {
if (parse_tokens->front().second < point) {
absl::string_view comment_string(parse_tokens->front().first);
absl::ConsumeSuffix(&comment_string, "\r\n");
absl::ConsumeSuffix(&comment_string, "\r");
absl::ConsumeSuffix(&comment_string, "\n");
parse_tokens->pop_front();
// println if multi-line comments
if (!emitted && i + 1 < size) {
if (parse_tokens->front().second < point) {
FlushLine();
}
}
println(std::string(comment_string));
emitted = true;
} else {
break;
}
}
return emitted;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment