Skip to content

Commit 6354c40

Browse files
committed
cue/parser: allow ... anywhere in struct
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 <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent f0df4df commit 6354c40

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

cue/parser/parser.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -709,12 +709,19 @@ func (p *parser) parseFieldList() (list []ast.Decl) {
709709
p.openList()
710710
defer p.closeList()
711711

712-
for p.tok != token.RBRACE && p.tok != token.ELLIPSIS && p.tok != token.EOF {
712+
for p.tok != token.RBRACE && p.tok != token.EOF {
713713
switch p.tok {
714714
case token.ATTRIBUTE:
715715
list = append(list, p.parseAttribute())
716716
p.consumeDeclComma()
717717

718+
case token.ELLIPSIS:
719+
c := p.openComments()
720+
ellipsis := &ast.Ellipsis{Ellipsis: p.pos}
721+
p.next()
722+
c.closeNode(p, ellipsis)
723+
list = append(list, ellipsis)
724+
718725
default:
719726
list = append(list, p.parseField())
720727
}
@@ -732,13 +739,6 @@ func (p *parser) parseFieldList() (list []ast.Decl) {
732739
}
733740
}
734741

735-
if p.tok == token.ELLIPSIS {
736-
c := p.openComments()
737-
ellipsis := &ast.Ellipsis{Ellipsis: p.pos}
738-
p.next()
739-
c.closeNode(p, ellipsis)
740-
list = append(list, ellipsis)
741-
}
742742
return
743743
}
744744

cue/parser/parser_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,27 @@ func TestParse(t *testing.T) {
118118
`{V1, V2}`,
119119
}, {
120120
"expression embedding",
121-
`Def :: {
121+
`#Def: {
122122
a.b.c
123123
a > b < c
124124
-1<2
125125
126126
foo: 2
127127
}`,
128-
`Def :: {a.b.c, a>b<c, -1<2, foo: 2}`,
128+
`#Def: {a.b.c, a>b<c, -1<2, foo: 2}`,
129129
}, {
130130
"ellipsis in structs",
131-
`Def :: {
131+
`#Def: {
132132
b: "2"
133133
...
134134
}
135+
136+
#Def2: {
137+
...
138+
b: "2"
139+
}
135140
`,
136-
`Def :: {b: "2", ...}`,
141+
`#Def: {b: "2", ...}, #Def2: {..., b: "2"}`,
137142
}, {
138143
"emitted referencing non-emitted",
139144
`a: 1

0 commit comments

Comments
 (0)