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. | 131 if (!at_end()) // Could be EOF. |
| 132 Advance(); // The current \n. |
132 // If this comment is separated from the next syntax element, then we | 133 // 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 // 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 // statement at the parser level to keep this comment separate, rather |
135 // than attached to the subsequent statement. | 136 // than attached to the subsequent statement. |
136 while (!at_end() && IsCurrentWhitespace()) { | 137 while (!at_end() && IsCurrentWhitespace()) { |
137 if (IsCurrentNewline()) { | 138 if (IsCurrentNewline()) { |
138 type = Token::BLOCK_COMMENT; | 139 type = Token::BLOCK_COMMENT; |
139 break; | 140 break; |
140 } | 141 } |
141 Advance(); | 142 Advance(); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 // Different types of comments. | 390 // Different types of comments. |
390 help = "Comments should start with # instead"; | 391 help = "Comments should start with # instead"; |
391 } else if (cur_char() == '\'') { | 392 } else if (cur_char() == '\'') { |
392 help = "Strings are delimited by \" characters, not apostrophes."; | 393 help = "Strings are delimited by \" characters, not apostrophes."; |
393 } else { | 394 } else { |
394 help = "I have no idea what this is."; | 395 help = "I have no idea what this is."; |
395 } | 396 } |
396 | 397 |
397 return Err(location, "Invalid token.", help); | 398 return Err(location, "Invalid token.", help); |
398 } | 399 } |
OLD | NEW |