Skip to content

Commit

Permalink
cue/parser: allow ... anywhere in struct
Browse files Browse the repository at this point in the history
This fixes a current deviation from the spec.

Change-Id: I1c070cf969c5023573a7f5778665beb42c21c4cb
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7221
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Sep 29, 2020
1 parent f0df4df commit 6354c40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
16 changes: 8 additions & 8 deletions cue/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,19 @@ func (p *parser) parseFieldList() (list []ast.Decl) {
p.openList()
defer p.closeList()

for p.tok != token.RBRACE && p.tok != token.ELLIPSIS && p.tok != token.EOF {
for p.tok != token.RBRACE && p.tok != token.EOF {
switch p.tok {
case token.ATTRIBUTE:
list = append(list, p.parseAttribute())
p.consumeDeclComma()

case token.ELLIPSIS:
c := p.openComments()
ellipsis := &ast.Ellipsis{Ellipsis: p.pos}
p.next()
c.closeNode(p, ellipsis)
list = append(list, ellipsis)

default:
list = append(list, p.parseField())
}
Expand All @@ -732,13 +739,6 @@ func (p *parser) parseFieldList() (list []ast.Decl) {
}
}

if p.tok == token.ELLIPSIS {
c := p.openComments()
ellipsis := &ast.Ellipsis{Ellipsis: p.pos}
p.next()
c.closeNode(p, ellipsis)
list = append(list, ellipsis)
}
return
}

Expand Down
13 changes: 9 additions & 4 deletions cue/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,27 @@ func TestParse(t *testing.T) {
`{V1, V2}`,
}, {
"expression embedding",
`Def :: {
`#Def: {
a.b.c
a > b < c
-1<2
foo: 2
}`,
`Def :: {a.b.c, a>b<c, -1<2, foo: 2}`,
`#Def: {a.b.c, a>b<c, -1<2, foo: 2}`,
}, {
"ellipsis in structs",
`Def :: {
`#Def: {
b: "2"
...
}
#Def2: {
...
b: "2"
}
`,
`Def :: {b: "2", ...}`,
`#Def: {b: "2", ...}, #Def2: {..., b: "2"}`,
}, {
"emitted referencing non-emitted",
`a: 1
Expand Down

0 comments on commit 6354c40

Please sign in to comment.