Open mvdan opened 9 months ago
@rogpeppe correctly points out that this is indeed working as expected per the spec. https://cuelang.org/docs/references/spec/#commas explains that a newline inserts a comma if it immediately follows tokens like a string literal, so the parser effectively tries to interpret:
bar[
"baz",
]
However, the spec defines index expressions as:
Index = "[" Expression "]" .
Note the lack of a comma token, unlike lists, meaning that the inserted comma above isn't allowed:
ListLit = "[" [ ElementList [ "," ] ] "]" .
I think we would have to amend the spec grammar to:
Index = "[" Expression [ "," ] "]" .
Then it would be correct for the parser to allow a newline between an index expression and its closing square bracket.
To support my proposal, the Go spec allows a comma in index expressions too:
Index = "[" Expression [ "," ] "]" .
And it works as expected, allowing the splitting of an index expression with newlines:
$ cat f.go
package main
func main() {
x := []int{3}
println(x[0])
println(x[0,])
println(x[
0,
])
}
$ gofmt f.go
package main
func main() {
x := []int{3}
println(x[0])
println(x[0])
println(x[0])
}
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest stable release?
Yes; tested with v0.7.0
What did you do?
What did you expect to see?
Success; per the spec at https://cuelang.org/docs/references/spec/#tokens:
What did you see instead?