this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue/...: remove remnants of /*block*/ comment support

https://cue-review.googlesource.com/c/cue/+/3983 and later
https//cuelang.org/cl/547012 meant to fully remove support for
block comments as explained in https://cuelang.org/issue/87,
but the documentation and bits of code and tests were left behind.

Note that tools/fix rewriting block comments as line comments
has been untested and broken since the two CLs above in 2019.
Given the amount of time that has passed, remove the fix code as well.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I8ade2b2461c665de1fd54d09e11cbfbf4a1d03a4
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196133
Reviewed-by: Aram Hăvărneanu <aram@cue.works>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+12 -86
+7 -14
cue/ast/ast.go
··· 176 176 *c.groups = cgs 177 177 } 178 178 179 - // A Comment node represents a single //-style or /*-style comment. 179 + // A Comment node represents a single //-style comment. 180 180 type Comment struct { 181 181 Slash token.Pos // position of "/" starting the comment 182 - Text string // comment text (excluding '\n' for //-style comments) 182 + Text string // comment text excluding '\n' 183 183 } 184 184 185 185 func (c *Comment) Comments() []*CommentGroup { return nil } ··· 226 226 } 227 227 228 228 // Text returns the text of the comment. 229 - // Comment markers (//, /*, and */), the first space of a line comment, and 229 + // Comment markers ("//"), the first space of a line comment, and 230 230 // leading and trailing empty lines are removed. Multiple empty lines are 231 231 // reduced to one, and trailing space on lines is trimmed. Unless the result 232 232 // is empty, it is newline-terminated. ··· 243 243 for _, c := range comments { 244 244 // Remove comment markers. 245 245 // The parser has given us exactly the comment text. 246 - switch c[1] { 247 - case '/': 248 - //-style comment (no newline at the end) 249 - c = c[2:] 250 - // strip first space - required for Example tests 251 - if len(c) > 0 && c[0] == ' ' { 252 - c = c[1:] 253 - } 254 - case '*': 255 - /*-style comment */ 256 - c = c[2 : len(c)-2] 246 + c = c[2:] 247 + // strip first space - required for Example tests 248 + if len(c) > 0 && c[0] == ' ' { 249 + c = c[1:] 257 250 } 258 251 259 252 // Split on newlines.
-12
cue/ast/ast_test.go
··· 41 41 {[]string{"// foo bar "}, "foo bar\n"}, 42 42 {[]string{"// foo", "// bar"}, "foo\nbar\n"}, 43 43 {[]string{"// foo", "//", "//", "//", "// bar"}, "foo\n\nbar\n"}, 44 - {[]string{"// foo", "/* bar */"}, "foo\n bar\n"}, 45 44 {[]string{"//", "//", "//", "// foo", "//", "//", "//"}, "foo\n"}, 46 - 47 - {[]string{"/**/"}, ""}, 48 - {[]string{"/* */"}, ""}, 49 - {[]string{"/**/", "/**/", "/* */"}, ""}, 50 - {[]string{"/* Foo */"}, " Foo\n"}, 51 - {[]string{"/* Foo Bar */"}, " Foo Bar\n"}, 52 - {[]string{"/* Foo*/", "/* Bar*/"}, " Foo\n Bar\n"}, 53 - {[]string{"/* Foo*/", "/**/", "/**/", "/**/", "// Bar"}, " Foo\n\nBar\n"}, 54 - {[]string{"/* Foo*/", "/*\n*/", "//", "/*\n*/", "// Bar"}, " Foo\n\nBar\n"}, 55 - {[]string{"/* Foo*/", "// Bar"}, " Foo\nBar\n"}, 56 - {[]string{"/* Foo\n Bar*/"}, " Foo\n Bar\n"}, 57 45 } 58 46 59 47 for i, c := range testCases {
+5 -13
cue/format/format.go
··· 25 25 import ( 26 26 "bytes" 27 27 "fmt" 28 - "strings" 29 28 "text/tabwriter" 30 29 31 30 "cuelang.org/go/cue/ast" ··· 320 319 printBlank = true 321 320 } 322 321 for _, c := range cg.List { 323 - isEnd := strings.HasPrefix(c.Text, "//") 324 322 if !printBlank { 325 - if isEnd { 326 - f.Print(vtab) 327 - } else { 328 - f.Print(blank) 329 - } 323 + f.Print(vtab) 330 324 } 331 325 f.Print(c.Slash) 332 326 f.Print(c) 333 - if isEnd { 334 - f.printingComment = true 335 - f.Print(newline) 336 - if cg.Doc { 337 - f.Print(nooverride) 338 - } 327 + f.printingComment = true 328 + f.Print(newline) 329 + if cg.Doc { 330 + f.Print(nooverride) 339 331 } 340 332 } 341 333 }
-12
cue/parser/parser.go
··· 274 274 275 275 // Consume a comment and return it and the line on which it ends. 276 276 func (p *parser) consumeComment() (comment *ast.Comment, endline int) { 277 - // /*-style comments may end on a different line than where they start. 278 - // Scan the comment for '\n' chars and adjust endline accordingly. 279 277 endline = p.file.Line(p.pos) 280 - if p.lit[1] == '*' { 281 - p.assertV0(p.pos, 0, 10, "block quotes") 282 - 283 - // don't use range here - no need to decode Unicode code points 284 - for i := 0; i < len(p.lit); i++ { 285 - if p.lit[i] == '\n' { 286 - endline++ 287 - } 288 - } 289 - } 290 278 291 279 comment = &ast.Comment{Slash: p.pos, Text: p.lit} 292 280 p.next0()
-35
tools/fix/fix.go
··· 20 20 package fix 21 21 22 22 import ( 23 - "strings" 24 - 25 23 "cuelang.org/go/cue/ast" 26 24 "cuelang.org/go/cue/ast/astutil" 27 25 "cuelang.org/go/cue/token" ··· 63 61 } 64 62 return true 65 63 }, nil).(*ast.File) 66 - 67 - // Rewrite block comments to regular comments. 68 - ast.Walk(f, func(n ast.Node) bool { 69 - switch x := n.(type) { 70 - case *ast.CommentGroup: 71 - comments := []*ast.Comment{} 72 - for _, c := range x.List { 73 - s := c.Text 74 - if !strings.HasPrefix(s, "/*") || !strings.HasSuffix(s, "*/") { 75 - comments = append(comments, c) 76 - continue 77 - } 78 - if x.Position > 0 { 79 - // Moving to the end doesn't work, as it still 80 - // may inject at a false line break position. 81 - x.Position = 0 82 - x.Doc = true 83 - } 84 - s = strings.TrimSpace(s[2 : len(s)-2]) 85 - for _, s := range strings.Split(s, "\n") { 86 - for i := 0; i < 3; i++ { 87 - if strings.HasPrefix(s, " ") || strings.HasPrefix(s, "*") { 88 - s = s[1:] 89 - } 90 - } 91 - comments = append(comments, &ast.Comment{Text: "// " + s}) 92 - } 93 - } 94 - x.List = comments 95 - return false 96 - } 97 - return true 98 - }, nil) 99 64 100 65 // TODO: we are probably reintroducing slices. Disable for now. 101 66 //