gn: handle continued suffix comments
Rebased on https://codereview.chromium.org/588893006/
Comments that look like standalone line comments but immediately follow
a previous suffix comment should be considered suffix as well so they
can be added to the same node.
[email protected]
BUG=348474
Review URL: https://codereview.chromium.org/595753002
Cr-Commit-Position: refs/heads/master@{#296339}
diff --git a/tools/gn/tokenizer.cc b/tools/gn/tokenizer.cc
index b4f364f2..bc0b638 100644
--- a/tools/gn/tokenizer.cc
+++ b/tools/gn/tokenizer.cc
@@ -120,10 +120,17 @@
else if (token_value == "false")
type = Token::FALSE_TOKEN;
} else if (type == Token::UNCLASSIFIED_COMMENT) {
- if (AtStartOfLine(token_begin))
+ if (AtStartOfLine(token_begin) &&
+ // If it's a standalone comment, but is a continuation of a comment on
+ // a previous line, then instead make it a continued suffix comment.
+ (tokens_.empty() || tokens_.back().type() != Token::SUFFIX_COMMENT ||
+ tokens_.back().location().line_number() + 1 !=
+ location.line_number() ||
+ tokens_.back().location().char_offset() != location.char_offset())) {
type = Token::LINE_COMMENT;
- else
+ } else {
type = Token::SUFFIX_COMMENT;
+ }
}
tokens_.push_back(Token(location, type, token_value));