encoding/protobuf: make names consistent with new convention
Change-Id: I090f104eb21dd1c234504101d89e575ee4834db7
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2443
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/import.go b/cmd/cue/cmd/import.go
index 44d48da..89a48ea 100644
--- a/cmd/cue/cmd/import.go
+++ b/cmd/cue/cmd/import.go
@@ -643,7 +643,7 @@
}
func handleProtoDef(cmd *cobra.Command, path string, r io.Reader) (f *ast.File, err error) {
- return protobuf.Parse(path, r, &protobuf.Config{Paths: flagProtoPath.StringArray(cmd)})
+ return protobuf.Extract(path, r, &protobuf.Config{Paths: flagProtoPath.StringArray(cmd)})
}
type hoister struct {
diff --git a/encoding/protobuf/examples_test.go b/encoding/protobuf/examples_test.go
index a3afe54..8d12d4d 100644
--- a/encoding/protobuf/examples_test.go
+++ b/encoding/protobuf/examples_test.go
@@ -24,13 +24,13 @@
"cuelang.org/go/encoding/protobuf"
)
-func ExampleParse() {
+func ExampleExtract() {
cwd, _ := os.Getwd()
var paths = []string{}
paths = append(paths, cwd)
paths = append(paths, filepath.Join(cwd, "testdata"))
- f, err := protobuf.Parse("examples/basic/basic.proto", nil, &protobuf.Config{
+ f, err := protobuf.Extract("examples/basic/basic.proto", nil, &protobuf.Config{
Paths: paths,
})
diff --git a/encoding/protobuf/parse.go b/encoding/protobuf/parse.go
index c918fd1..b3e7451 100644
--- a/encoding/protobuf/parse.go
+++ b/encoding/protobuf/parse.go
@@ -34,7 +34,7 @@
"github.com/emicklei/proto"
)
-func (s *Builder) parse(filename string, src interface{}) (p *protoConverter, err error) {
+func (s *Extractor) parse(filename string, src interface{}) (p *protoConverter, err error) {
if filename == "" {
return nil, errors.Newf(token.NoPos, "empty filename")
}
@@ -158,7 +158,7 @@
// A protoConverter converts a proto definition to CUE. Proto files map to
// CUE files one to one.
type protoConverter struct {
- state *Builder
+ state *Extractor
tfile *token.File
proto3 bool
diff --git a/encoding/protobuf/protobuf.go b/encoding/protobuf/protobuf.go
index c433022..17efb1e 100644
--- a/encoding/protobuf/protobuf.go
+++ b/encoding/protobuf/protobuf.go
@@ -61,7 +61,7 @@
Paths []string
}
-// A Builder converts a collection of proto files, typically belonging to one
+// An Extractor converts a collection of proto files, typically belonging to one
// repo or module, to CUE. It thereby observes the CUE package layout.
//
// CUE observes the same package layout as Go and requires .proto files to have
@@ -71,7 +71,7 @@
// All other imported files are assigned to the CUE pkg dir ($Root/pkg)
// according to their Go package import path.
//
-type Builder struct {
+type Extractor struct {
root string
cwd string
module string
@@ -90,12 +90,12 @@
err error
}
-// NewBuilder creates a Builder. If the configuration contained any errors it
-// will be observable by the Err method fo the Builder. It is safe, however, to
-// only check errors after building the output.
-func NewBuilder(c *Config) *Builder {
+// NewExtractor creates an Extractor. If the configuration contained any errors
+// it will be observable by the Err method fo the Extractor. It is safe,
+// however, to only check errors after building the output.
+func NewExtractor(c *Config) *Extractor {
cwd, _ := os.Getwd()
- b := &Builder{
+ b := &Extractor{
root: c.Root,
cwd: cwd,
paths: c.Paths,
@@ -113,11 +113,11 @@
// Err returns the errors accumulated during testing. The returned error may be
// of type cuelang.org/go/cue/errors.List.
-func (b *Builder) Err() error {
+func (b *Extractor) Err() error {
return b.errs.Err()
}
-func (b *Builder) addErr(err error) {
+func (b *Extractor) addErr(err error) {
switch err := err.(type) {
case errors.Error:
b.errs.Add(err)
@@ -134,7 +134,7 @@
// an error if it does not. Imports are resolved using the paths defined in
// Config.
//
-func (b *Builder) AddFile(filename string, src interface{}) error {
+func (b *Extractor) AddFile(filename string, src interface{}) error {
if b.done {
b.errs.Add(errors.Newf(token.NoPos, "protobuf: cannot call AddFile: Instances was already called"))
return b.Err()
@@ -150,7 +150,7 @@
// Files returns a File for each proto file that was added or imported,
// recursively.
-func (b *Builder) Files() (files []*ast.File, err error) {
+func (b *Extractor) Files() (files []*ast.File, err error) {
defer func() { err = b.Err() }()
b.done = true
@@ -177,7 +177,7 @@
// All import paths are located within the specified Root, where external
// packages are located under $Root/pkg. Instances for builtin (like time)
// packages may be omitted, and if not will have no associated files.
-func (b *Builder) Instances() (instances []*build.Instance, err error) {
+func (b *Extractor) Instances() (instances []*build.Instance, err error) {
defer func() { err = b.Err() }()
b.done = true
@@ -246,7 +246,7 @@
return instances, nil
}
-func (b *Builder) getInst(p *protoConverter) *build.Instance {
+func (b *Extractor) getInst(p *protoConverter) *build.Instance {
if b.errs != nil {
return nil
}
@@ -289,19 +289,19 @@
return inst
}
-// Parse parses a single proto file and returns its contents translated to a CUE
+// Extract parses a single proto file and returns its contents translated to a CUE
// file. If src is not nil, it will use this as the contents of the file. It may
-// be a string, []byte or io.Reader. Otherwise Parse will open the given file
+// be a string, []byte or io.Reader. Otherwise Extract will open the given file
// name at the fully qualified path.
//
-// Parse assumes the proto file compiles with protoc and may not report an error
+// Extract assumes the proto file compiles with protoc and may not report an error
// if it does not. Imports are resolved using the paths defined in Config.
//
-func Parse(filename string, src interface{}, c *Config) (f *ast.File, err error) {
+func Extract(filename string, src interface{}, c *Config) (f *ast.File, err error) {
if c == nil {
c = &Config{}
}
- b := NewBuilder(c)
+ b := NewExtractor(c)
p, err := b.parse(filename, src)
if err != nil {
diff --git a/encoding/protobuf/protobuf_test.go b/encoding/protobuf/protobuf_test.go
index 8e4a45b..fb0fe69 100644
--- a/encoding/protobuf/protobuf_test.go
+++ b/encoding/protobuf/protobuf_test.go
@@ -31,7 +31,7 @@
var update = flag.Bool("update", false, "update the test output")
-func TestParseDefinitions(t *testing.T) {
+func TestExtractDefinitions(t *testing.T) {
testCases := []string{
"networking/v1alpha3/gateway.proto",
"mixer/v1/attributes.proto",
@@ -47,7 +47,7 @@
out := &bytes.Buffer{}
- if f, err := Parse(filename, nil, c); err != nil {
+ if f, err := Extract(filename, nil, c); err != nil {
fmt.Fprintln(out, err)
} else {
b, _ := format.Node(f, format.Simplify())
@@ -84,7 +84,7 @@
},
}
- b := NewBuilder(c)
+ b := NewExtractor(c)
b.AddFile("networking/v1alpha3/gateway.proto", nil)
b.AddFile("mixer/v1/attributes.proto", nil)
b.AddFile("mixer/v1/mixer.proto", nil)