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 if (AtStartOfLine(token_begin) && | 123 if (AtStartOfLine(token_begin) && |
124 // If it's a standalone comment, but is a continuation of a comment on | 124 // If it's a standalone comment, but is a continuation of a comment on |
125 // a previous line, then instead make it a continued suffix comment. | 125 // a previous line, then instead make it a continued suffix comment. |
126 (tokens_.empty() || tokens_.back().type() != Token::SUFFIX_COMMENT || | 126 (tokens_.empty() || tokens_.back().type() != Token::SUFFIX_COMMENT || |
127 tokens_.back().location().line_number() + 1 != | 127 tokens_.back().location().line_number() + 1 != |
128 location.line_number() || | 128 location.line_number() || |
129 tokens_.back().location().char_offset() != location.char_offset())) { | 129 tokens_.back().location().char_offset() != location.char_offset())) { |
130 type = Token::LINE_COMMENT; | 130 type = Token::LINE_COMMENT; |
| 131 Advance(); // The current \n. |
| 132 // If this comment is separated from the next syntax element, then we |
| 133 // want to tag it as a block comment. This will become a standalone |
| 134 // statement at the parser level to keep this comment separate, rather |
| 135 // than attached to the subsequent statement. |
| 136 while (!at_end() && IsCurrentWhitespace()) { |
| 137 if (IsCurrentNewline()) { |
| 138 type = Token::BLOCK_COMMENT; |
| 139 break; |
| 140 } |
| 141 Advance(); |
| 142 } |
131 } else { | 143 } else { |
132 type = Token::SUFFIX_COMMENT; | 144 type = Token::SUFFIX_COMMENT; |
133 } | 145 } |
134 } | 146 } |
135 | 147 |
136 tokens_.push_back(Token(location, type, token_value)); | 148 tokens_.push_back(Token(location, type, token_value)); |
137 } | 149 } |
138 if (err_->has_error()) | 150 if (err_->has_error()) |
139 tokens_.clear(); | 151 tokens_.clear(); |
140 return tokens_; | 152 return tokens_; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } else if (cur_char() == '/' && cur_ + 1 < input_.size() && | 387 } else if (cur_char() == '/' && cur_ + 1 < input_.size() && |
376 (input_[cur_ + 1] == '/' || input_[cur_ + 1] == '*')) { | 388 (input_[cur_ + 1] == '/' || input_[cur_ + 1] == '*')) { |
377 // Different types of comments. | 389 // Different types of comments. |
378 help = "Comments should start with # instead"; | 390 help = "Comments should start with # instead"; |
379 } else { | 391 } else { |
380 help = "I have no idea what this is."; | 392 help = "I have no idea what this is."; |
381 } | 393 } |
382 | 394 |
383 return Err(location, "Invalid token.", help); | 395 return Err(location, "Invalid token.", help); |
384 } | 396 } |
OLD | NEW |