Skip to content

Commit

Permalink
internal: add ToStruct helper.
Browse files Browse the repository at this point in the history
Change-Id: I2a26553db2ee2705a8a9d8ef5ae09ccca7e04867
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6564
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Jul 17, 2020
1 parent 0ccdee2 commit 8a0ac3e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,24 @@ func ToFile(n ast.Node) *ast.File {
}
}

// ToStruct gets the non-preamble declarations of a file and puts them in a
// struct.
func ToStruct(f *ast.File) *ast.StructLit {
start := 0
for i, d := range f.Decls {
switch d.(type) {
case *ast.Package, *ast.ImportDecl:
start = i + 1
case *ast.Attribute, *ast.CommentGroup:
default:
break
}
}
s := ast.NewStruct()
s.Elts = f.Decls[start:]
return s
}

func IsBulkField(d ast.Decl) bool {
if f, ok := d.(*ast.Field); ok {
if _, ok := f.Label.(*ast.ListLit); ok {
Expand Down

0 comments on commit 8a0ac3e

Please sign in to comment.