Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: tools/gn/tokenizer.cc

Issue 595753002: gn: handle continued suffix comments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-append-comment
Patch Set: only continue if at same column Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/parser_unittest.cc ('k') | tools/gn/tokenizer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } else if (type == Token::IDENTIFIER) { 113 } else if (type == Token::IDENTIFIER) {
114 if (token_value == "if") 114 if (token_value == "if")
115 type = Token::IF; 115 type = Token::IF;
116 else if (token_value == "else") 116 else if (token_value == "else")
117 type = Token::ELSE; 117 type = Token::ELSE;
118 else if (token_value == "true") 118 else if (token_value == "true")
119 type = Token::TRUE_TOKEN; 119 type = Token::TRUE_TOKEN;
120 else if (token_value == "false") 120 else if (token_value == "false")
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
125 // a previous line, then instead make it a continued suffix comment.
126 (tokens_.empty() || tokens_.back().type() != Token::SUFFIX_COMMENT ||
127 tokens_.back().location().line_number() + 1 !=
128 location.line_number() ||
129 tokens_.back().location().char_offset() != location.char_offset())) {
124 type = Token::LINE_COMMENT; 130 type = Token::LINE_COMMENT;
125 else 131 } else {
126 type = Token::SUFFIX_COMMENT; 132 type = Token::SUFFIX_COMMENT;
133 }
127 } 134 }
128 135
129 tokens_.push_back(Token(location, type, token_value)); 136 tokens_.push_back(Token(location, type, token_value));
130 } 137 }
131 if (err_->has_error()) 138 if (err_->has_error())
132 tokens_.clear(); 139 tokens_.clear();
133 return tokens_; 140 return tokens_;
134 } 141 }
135 142
136 // static 143 // static
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } else if (cur_char() == '/' && cur_ + 1 < input_.size() && 374 } else if (cur_char() == '/' && cur_ + 1 < input_.size() &&
368 (input_[cur_ + 1] == '/' || input_[cur_ + 1] == '*')) { 375 (input_[cur_ + 1] == '/' || input_[cur_ + 1] == '*')) {
369 // Different types of comments. 376 // Different types of comments.
370 help = "Comments should start with # instead"; 377 help = "Comments should start with # instead";
371 } else { 378 } else {
372 help = "I have no idea what this is."; 379 help = "I have no idea what this is.";
373 } 380 }
374 381
375 return Err(location, "Invalid token.", help); 382 return Err(location, "Invalid token.", help);
376 } 383 }
OLDNEW
« no previous file with comments | « tools/gn/parser_unittest.cc ('k') | tools/gn/tokenizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698