Handle newlines inside C comments
This commit is contained in:
parent
36d2a815a3
commit
a2929c0020
2 changed files with 31 additions and 12 deletions
|
|
@ -242,6 +242,17 @@ namespace
|
||||||
ptr_ += offset;
|
ptr_ += offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void skip_with_linecount() noexcept
|
||||||
|
{
|
||||||
|
if (*ptr_ == '\n' && write_ == true)
|
||||||
|
{
|
||||||
|
result_->push_back('\n');
|
||||||
|
++cur_line_;
|
||||||
|
}
|
||||||
|
|
||||||
|
++ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
void enable_write() noexcept
|
void enable_write() noexcept
|
||||||
{
|
{
|
||||||
write_.set();
|
write_.set();
|
||||||
|
|
@ -395,9 +406,11 @@ namespace
|
||||||
// remove trailing spaces
|
// remove trailing spaces
|
||||||
while (!result.comment.empty() && result.comment.back() == ' ')
|
while (!result.comment.empty() && result.comment.back() == ' ')
|
||||||
result.comment.pop_back();
|
result.comment.pop_back();
|
||||||
|
|
||||||
// skip newline
|
// skip newline
|
||||||
p.skip();
|
p.skip_with_linecount();
|
||||||
result.comment += '\n';
|
result.comment += '\n';
|
||||||
|
|
||||||
// skip indentation
|
// skip indentation
|
||||||
while (starts_with(p, " "))
|
while (starts_with(p, " "))
|
||||||
p.skip();
|
p.skip();
|
||||||
|
|
@ -447,17 +460,10 @@ namespace
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while (!starts_with(p, "*/"))
|
while (!starts_with(p, "*/"))
|
||||||
p.skip();
|
p.skip_with_linecount();
|
||||||
p.skip(2u);
|
p.skip(2u);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!starts_with(p, "\n"))
|
|
||||||
// ensure an additional newline after each C comment
|
|
||||||
// this allows matching documentation comments to entities generated from macros
|
|
||||||
// as the entity corresponding to the documentation comment will be on the next line
|
|
||||||
// otherwise all entities would have the same line number
|
|
||||||
p.write_str("\n");
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -162,15 +162,28 @@ foo {}
|
||||||
|
|
||||||
/// 23
|
/// 23
|
||||||
|
|
||||||
|
/* C comment
|
||||||
|
spanning
|
||||||
|
multiple
|
||||||
|
lines
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/// 27
|
/// 37
|
||||||
)";
|
)";
|
||||||
|
|
||||||
auto file = parse({}, "preprocessor_line_numbers.cpp", code);
|
auto file = parse({}, "preprocessor_line_numbers.cpp", code);
|
||||||
for (auto& comment : file->unmatched_comments())
|
for (auto& comment : file->unmatched_comments())
|
||||||
REQUIRE(comment.line == std::stoi(comment.content));
|
{
|
||||||
REQUIRE((file->unmatched_comments().size() == 6u));
|
if (comment.content[0] != '\n')
|
||||||
|
REQUIRE(comment.line == std::stoi(comment.content));
|
||||||
|
}
|
||||||
|
REQUIRE((file->unmatched_comments().size() == 6u + 1u));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("comment matching")
|
TEST_CASE("comment matching")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue