cue: elide comma after ...

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>
diff --git a/cue/parser/parser.go b/cue/parser/parser.go
index 6ba99cd..165d65f 100644
--- a/cue/parser/parser.go
+++ b/cue/parser/parser.go
@@ -746,6 +746,7 @@
 			p.next()
 			c.closeNode(p, ellipsis)
 			list = append(list, ellipsis)
+			p.consumeDeclComma()
 
 		default:
 			list = append(list, p.parseField())
diff --git a/cue/parser/parser_test.go b/cue/parser/parser_test.go
index 4f12c93..2df4fc9 100644
--- a/cue/parser/parser_test.go
+++ b/cue/parser/parser_test.go
@@ -24,6 +24,25 @@
 
 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", "{}", "{}",
@@ -149,13 +168,17 @@
 			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
@@ -664,6 +687,10 @@
 			`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) {
diff --git a/cue/scanner/scanner.go b/cue/scanner/scanner.go
index 6caaf11..9b08691 100644
--- a/cue/scanner/scanner.go
+++ b/cue/scanner/scanner.go
@@ -907,6 +907,7 @@
 				if s.ch == '.' {
 					s.next()
 					tok = token.ELLIPSIS
+					insertEOL = true
 				} else {
 					s.errf(s.file.Offset(pos), "illegal token '..'; expected '.'")
 				}
diff --git a/cue/scanner/scanner_test.go b/cue/scanner/scanner_test.go
index 38a1459..39dbcc9 100644
--- a/cue/scanner/scanner_test.go
+++ b/cue/scanner/scanner_test.go
@@ -403,7 +403,7 @@
 	"<=\n",
 	">=\n",
 	":=\n",
-	"...\n",
+	"...^\n",
 
 	"(\n",
 	"[\n",
diff --git a/doc/ref/spec.md b/doc/ref/spec.md
index ebbc1fc..4537492 100644
--- a/doc/ref/spec.md
+++ b/doc/ref/spec.md
@@ -166,6 +166,7 @@
 - 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