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

Side by Side Diff: mojom/mojom_parser/formatter/printer.go

Issue 1829963003: Formatter: Handle the case where you have a whole line of forward slashes. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 9 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 | « mojo/public/tools/bindings/mojom_tool/bin/mac64/mojom.sha1 ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 package formatter 5 package formatter
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "mojom/mojom_parser/lexer" 10 "mojom/mojom_parser/lexer"
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 } 661 }
662 662
663 func (p *printer) writeSingleLineComment(comment lexer.Token) { 663 func (p *printer) writeSingleLineComment(comment lexer.Token) {
664 if comment.Kind != lexer.SingleLineComment { 664 if comment.Kind != lexer.SingleLineComment {
665 panic(fmt.Sprintf("This is not a SingleLineComment: %s", comment )) 665 panic(fmt.Sprintf("This is not a SingleLineComment: %s", comment ))
666 } 666 }
667 commentText := comment.Text 667 commentText := comment.Text
668 668
669 // We expect that the first 2 characters are // followed by a space or t ab. 669 // We expect that the first 2 characters are // followed by a space or t ab.
670 // If the third character is not a space or tab, we insert a space. 670 // If the third character is not a space or tab, we insert a space.
671 » if len(commentText) > 2 && commentText[2] != ' ' && commentText[2] != '\ t' { 671 » // There is an exception for three forward slashes which are allowed.
672 » if len(commentText) > 2 && !strings.ContainsAny(" \t/", commentText[2:3] ) {
672 commentText = "// " + commentText[2:] 673 commentText = "// " + commentText[2:]
673 } 674 }
674 p.write(commentText) 675 p.write(commentText)
675 } 676 }
676 677
677 func (p *printer) writeMultiLineComment(comment lexer.Token) { 678 func (p *printer) writeMultiLineComment(comment lexer.Token) {
678 if comment.Kind != lexer.MultiLineComment { 679 if comment.Kind != lexer.MultiLineComment {
679 panic(fmt.Sprintf("This is not a MultiLineComment: %s", comment) ) 680 panic(fmt.Sprintf("This is not a MultiLineComment: %s", comment) )
680 } 681 }
681 682
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 949
949 // See sort.Interface. 950 // See sort.Interface.
950 func (ifs *importedFilesSorter) Less(i, j int) bool { 951 func (ifs *importedFilesSorter) Less(i, j int) bool {
951 return ifs.imports[i].SpecifiedName < ifs.imports[j].SpecifiedName 952 return ifs.imports[i].SpecifiedName < ifs.imports[j].SpecifiedName
952 } 953 }
953 954
954 // See sort.Interface. 955 // See sort.Interface.
955 func (ifs *importedFilesSorter) Swap(i, j int) { 956 func (ifs *importedFilesSorter) Swap(i, j int) {
956 ifs.imports[i], ifs.imports[j] = ifs.imports[j], ifs.imports[i] 957 ifs.imports[i], ifs.imports[j] = ifs.imports[j], ifs.imports[i]
957 } 958 }
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/mojom_tool/bin/mac64/mojom.sha1 ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698