OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/tokenizer.h" | 5 #include "tools/gn/tokenizer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "tools/gn/input_file.h" | 9 #include "tools/gn/input_file.h" |
10 | 10 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 type = Token::FALSE_TOKEN; | 121 type = Token::FALSE_TOKEN; |
122 } else if (type == Token::UNCLASSIFIED_COMMENT) { | 122 } else if (type == Token::UNCLASSIFIED_COMMENT) { |
123 // Find back to the previous \n, and trim. If it's only whitespace, then | 123 // Find back to the previous \n, and trim. If it's only whitespace, then |
124 // this is on a line alone, otherwise it's a suffix comment. | 124 // this is on a line alone, otherwise it's a suffix comment. |
125 size_t newline_location = input_.find_last_of('\n', token_begin); | 125 size_t newline_location = input_.find_last_of('\n', token_begin); |
126 base::StringPiece to_newline = input_.substr( | 126 base::StringPiece to_newline = input_.substr( |
127 newline_location + 1, token_begin - (newline_location + 1)); | 127 newline_location + 1, token_begin - (newline_location + 1)); |
128 std::string trimmed; | 128 std::string trimmed; |
129 // TODO(scottmg): Should write TrimWhitespace for StringPiece. | 129 // TODO(scottmg): Should write TrimWhitespace for StringPiece. |
130 base::TrimWhitespace(to_newline.as_string(), base::TRIM_ALL, &trimmed); | 130 base::TrimWhitespace(to_newline.as_string(), base::TRIM_ALL, &trimmed); |
131 if (trimmed.empty()) | 131 if (trimmed.empty() && |
| 132 // If it's a standalone comment, but is a continuation of a comment |
| 133 // on a previous line, then instead make it a continued suffix |
| 134 // comment. |
| 135 (tokens_.empty() || tokens_.back().type() != Token::SUFFIX_COMMENT || |
| 136 tokens_.back().location().line_number() + 1 != |
| 137 location.line_number())) { |
132 type = Token::LINE_COMMENT; | 138 type = Token::LINE_COMMENT; |
133 else | 139 } else { |
134 type = Token::SUFFIX_COMMENT; | 140 type = Token::SUFFIX_COMMENT; |
| 141 } |
135 } | 142 } |
136 | 143 |
137 tokens_.push_back(Token(location, type, token_value)); | 144 tokens_.push_back(Token(location, type, token_value)); |
138 } | 145 } |
139 if (err_->has_error()) | 146 if (err_->has_error()) |
140 tokens_.clear(); | 147 tokens_.clear(); |
141 return tokens_; | 148 return tokens_; |
142 } | 149 } |
143 | 150 |
144 // static | 151 // static |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } else if (cur_char() == '/' && cur_ + 1 < input_.size() && | 370 } else if (cur_char() == '/' && cur_ + 1 < input_.size() && |
364 (input_[cur_ + 1] == '/' || input_[cur_ + 1] == '*')) { | 371 (input_[cur_ + 1] == '/' || input_[cur_ + 1] == '*')) { |
365 // Different types of comments. | 372 // Different types of comments. |
366 help = "Comments should start with # instead"; | 373 help = "Comments should start with # instead"; |
367 } else { | 374 } else { |
368 help = "I have no idea what this is."; | 375 help = "I have no idea what this is."; |
369 } | 376 } |
370 | 377 |
371 return Err(location, "Invalid token.", help); | 378 return Err(location, "Invalid token.", help); |
372 } | 379 } |
OLD | NEW |