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

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

Issue 1822233002: Handle the case where a single-line comment is less than 3 characters long. (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 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 } 657 }
658 658
659 func (p *printer) writeSingleLineComment(comment lexer.Token) { 659 func (p *printer) writeSingleLineComment(comment lexer.Token) {
660 if comment.Kind != lexer.SingleLineComment { 660 if comment.Kind != lexer.SingleLineComment {
661 panic(fmt.Sprintf("This is not a SingleLineComment: %s", comment )) 661 panic(fmt.Sprintf("This is not a SingleLineComment: %s", comment ))
662 } 662 }
663 commentText := comment.Text 663 commentText := comment.Text
664 664
665 // We expect that the first 2 characters are // followed by a space or t ab. 665 // We expect that the first 2 characters are // followed by a space or t ab.
666 // If the third character is not a space or tab, we insert a space. 666 // If the third character is not a space or tab, we insert a space.
667 » space := commentText[2] 667 » if len(commentText) > 2 && commentText[2] != ' ' && commentText[2] != '\ t' {
668 » if space != ' ' && space != '\t' {
669 commentText = "// " + commentText[2:] 668 commentText = "// " + commentText[2:]
670 } 669 }
671 p.write(commentText) 670 p.write(commentText)
672 } 671 }
673 672
674 func (p *printer) writeMultiLineComment(comment lexer.Token) { 673 func (p *printer) writeMultiLineComment(comment lexer.Token) {
675 if comment.Kind != lexer.MultiLineComment { 674 if comment.Kind != lexer.MultiLineComment {
676 panic(fmt.Sprintf("This is not a MultiLineComment: %s", comment) ) 675 panic(fmt.Sprintf("This is not a MultiLineComment: %s", comment) )
677 } 676 }
678 677
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 944
946 // See sort.Interface. 945 // See sort.Interface.
947 func (ifs *importedFilesSorter) Less(i, j int) bool { 946 func (ifs *importedFilesSorter) Less(i, j int) bool {
948 return ifs.imports[i].SpecifiedName < ifs.imports[j].SpecifiedName 947 return ifs.imports[i].SpecifiedName < ifs.imports[j].SpecifiedName
949 } 948 }
950 949
951 // See sort.Interface. 950 // See sort.Interface.
952 func (ifs *importedFilesSorter) Swap(i, j int) { 951 func (ifs *importedFilesSorter) Swap(i, j int) {
953 ifs.imports[i], ifs.imports[j] = ifs.imports[j], ifs.imports[i] 952 ifs.imports[i], ifs.imports[j] = ifs.imports[j], ifs.imports[i]
954 } 953 }
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