Skip to content

Commit

Permalink
doc/ref/spec.md: allow ... in an ast.File
Browse files Browse the repository at this point in the history
This is consistent with allowing ... in non-schema.

Other benefits:
- code generation can generate []Decl regardless of
whether it is used for a File or StructLit.
- once we have topological sort, `...` could be used
to hint insertion points when allowed at an arbitrary
position in the Decls list (although [string]: foo could
be used for that too).
- when adopting JSON Schema semantics, ...T may
has meaning at the file level as well.

Change-Id: Icfb299f951f5531119d33aeb5d89237eb64e33a1
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5940
Reviewed-by: roger peppe <rogpeppe@gmail.com>
  • Loading branch information
mpvl committed May 13, 2020
1 parent 5163831 commit c174a08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion cue/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,19 @@ func (v *astVisitor) walk(astNode ast.Node) (ret value) {
astState: v.astState,
object: obj,
}
for _, e := range n.Decls {
for i, e := range n.Decls {
switch x := e.(type) {
case *ast.EmbedDecl:
if v1.object.emit == nil {
v1.object.emit = v1.walk(x.Expr)
} else {
v1.object.emit = mkBin(v.ctx(), token.NoPos, opUnify, v1.object.emit, v1.walk(x.Expr))
}
case *ast.Ellipsis:
if i != len(n.Decls)-1 {
return v1.walk(x.Type) // Generate an error
}

default:
v1.walk(e)
}
Expand Down
3 changes: 2 additions & 1 deletion doc/ref/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -2859,8 +2859,9 @@ If the result of the unification of all embedded values is not a struct,
it will be output instead of its enclosing file when exporting CUE
to a data format

<!-- TODO: allow ... anywhere in SourceFile and struct. -->
```
SourceFile = [ PackageClause "," ] { ImportDecl "," } { Declaration "," } .
SourceFile = [ PackageClause "," ] { ImportDecl "," } { Declaration "," } [ "..." ] .
```

```
Expand Down

0 comments on commit c174a08

Please sign in to comment.