Skip to content

Instantly share code, notes, and snippets.

Created December 22, 2012 12:58
Show Gist options
  • Save anonymous/4358794 to your computer and use it in GitHub Desktop.
Save anonymous/4358794 to your computer and use it in GitHub Desktop.
int paren_count = 0;
bool stop = false;
for (unsigned i = 0; !stop && i < token_count; ++i) {
auto& token = tokens[i];
if (clang_getTokenKind(token) == CXToken_Punctuation) {
std::string spelling{clang_getCString(clang_getTokenSpelling(tu, token))};
if (spelling == "(") {
++paren_count;
} else if (spelling == ")") {
--paren_count;
if (paren_count <= 0) {
stop = true;
}
}
}
std::cout << clang_getCString(clang_getTokenSpelling(tu, token)) << ' ';
}
clang_disposeTokens(tu, tokens, token_count);
std::cout << '\n' << std::string(80, '=') << "\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment