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

Side by Side Diff: tools/gn/parser.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, 3 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/parse_tree.cc ('k') | tools/gn/parser_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/parser.h" 5 #include "tools/gn/parser.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "tools/gn/functions.h" 8 #include "tools/gn/functions.h"
9 #include "tools/gn/operators.h" 9 #include "tools/gn/operators.h"
10 #include "tools/gn/token.h" 10 #include "tools/gn/token.h"
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 TraverseOrder(file, &pre, &post); 543 TraverseOrder(file, &pre, &post);
544 544
545 // Assign line comments to syntax immediately following. 545 // Assign line comments to syntax immediately following.
546 int cur_comment = 0; 546 int cur_comment = 0;
547 for (std::vector<const ParseNode*>::const_iterator i = pre.begin(); 547 for (std::vector<const ParseNode*>::const_iterator i = pre.begin();
548 i != pre.end(); 548 i != pre.end();
549 ++i) { 549 ++i) {
550 const Location& start = (*i)->GetRange().begin(); 550 const Location& start = (*i)->GetRange().begin();
551 while (cur_comment < static_cast<int>(line_comment_tokens_.size())) { 551 while (cur_comment < static_cast<int>(line_comment_tokens_.size())) {
552 if (start.byte() >= line_comment_tokens_[cur_comment].location().byte()) { 552 if (start.byte() >= line_comment_tokens_[cur_comment].location().byte()) {
553 const_cast<ParseNode*>((*i))->comments_mutable()->append_before( 553 const_cast<ParseNode*>(*i)->comments_mutable()->append_before(
554 line_comment_tokens_[cur_comment]); 554 line_comment_tokens_[cur_comment]);
555 ++cur_comment; 555 ++cur_comment;
556 } else { 556 } else {
557 break; 557 break;
558 } 558 }
559 } 559 }
560 } 560 }
561 561
562 // Remaining line comments go at end of file. 562 // Remaining line comments go at end of file.
563 for (; cur_comment < static_cast<int>(line_comment_tokens_.size()); 563 for (; cur_comment < static_cast<int>(line_comment_tokens_.size());
(...skipping 18 matching lines...) Expand all
582 // 582 //
583 // sources = [ "a", 583 // sources = [ "a",
584 // "b" ] # comment 584 // "b" ] # comment
585 // 585 //
586 // it's attached to "b", not sources = [ ... ]. 586 // it's attached to "b", not sources = [ ... ].
587 if (start.line_number() != end.line_number()) 587 if (start.line_number() != end.line_number())
588 continue; 588 continue;
589 589
590 while (cur_comment >= 0) { 590 while (cur_comment >= 0) {
591 if (end.byte() <= suffix_comment_tokens_[cur_comment].location().byte()) { 591 if (end.byte() <= suffix_comment_tokens_[cur_comment].location().byte()) {
592 const_cast<ParseNode*>((*i))->comments_mutable()->append_suffix( 592 const_cast<ParseNode*>(*i)->comments_mutable()->append_suffix(
593 suffix_comment_tokens_[cur_comment]); 593 suffix_comment_tokens_[cur_comment]);
594 --cur_comment; 594 --cur_comment;
595 } else { 595 } else {
596 break; 596 break;
597 } 597 }
598 } 598 }
599
600 // Suffix comments were assigned in reverse, so if there were multiple on
601 // the same node, they need to be reversed.
602 const_cast<ParseNode*>(*i)->comments_mutable()->ReverseSuffix();
599 } 603 }
600 } 604 }
OLDNEW
« no previous file with comments | « tools/gn/parse_tree.cc ('k') | tools/gn/parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698