Skip to content

Commit

Permalink
cue: elide comma after ...
Browse files Browse the repository at this point in the history
Fixes #958
Fixes #768

Change-Id: Ic6c463dd305e4a326f73ce3b65ed1ca02f752dde
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9724
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
  • Loading branch information
mpvl committed May 10, 2021
1 parent 3fdad16 commit 5b8ab47
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions cue/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ func (p *parser) parseFieldList() (list []ast.Decl) {
p.next()
c.closeNode(p, ellipsis)
list = append(list, ellipsis)
p.consumeDeclComma()

default:
list = append(list, p.parseField())
Expand Down
29 changes: 28 additions & 1 deletion cue/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ import (

func TestParse(t *testing.T) {
testCases := []struct{ desc, in, out string }{{

"ellipsis in structs",
`#Def: {
b: "2"
...
}
...
#Def2: {
...
b: "2"
}
#Def3: {...
_}
...
`,
`#Def: {b: "2", ...}, ..., #Def2: {..., b: "2"}, #Def3: {..., _}, ...`,
}, {

"empty file", "", "",
}, {
"empty struct", "{}", "{}",
Expand Down Expand Up @@ -149,13 +168,17 @@ func TestParse(t *testing.T) {
b: "2"
...
}
...
#Def2: {
...
b: "2"
}
#Def3: {...
_}
...
`,
`#Def: {b: "2", ...}, #Def2: {..., b: "2"}`,
`#Def: {b: "2", ...}, ..., #Def2: {..., b: "2"}, #Def3: {..., _}, ...`,
}, {
"emitted referencing non-emitted",
`a: 1
Expand Down Expand Up @@ -664,6 +687,10 @@ func TestStrict(t *testing.T) {
`X=3`},
{"old-style alias 2",
`X={}`},

// Not yet supported
{"additional typed not yet supported",
`{...int}`},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions cue/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ scanAgain:
if s.ch == '.' {
s.next()
tok = token.ELLIPSIS
insertEOL = true
} else {
s.errf(s.file.Offset(pos), "illegal token '..'; expected '.'")
}
Expand Down
2 changes: 1 addition & 1 deletion cue/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ var lines = []string{
"<=\n",
">=\n",
":=\n",
"...\n",
"...^\n",

"(\n",
"[\n",
Expand Down
1 change: 1 addition & 0 deletions doc/ref/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ the token stream immediately after a line's final token if that token is
- an identifier, keyword, or bottom
- a number or string literal, including an interpolation
- one of the characters `)`, `]`, `}`, or `?`
- an ellipsis `...`


Although commas are automatically inserted, the parser will require
Expand Down

0 comments on commit 5b8ab47

Please sign in to comment.