Skip to content

Commit f0c77ed

Browse files
committed
encoding/json,encoding/yaml: remove long deprecated cue.Instance APIs
These were all deprecated in April 2021 as part of the transition away from cue.Instance. After three years, and given how relatively simple it is to switch to Extract, remove them at this point. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I10df893035a08b967ef9d9116650eb816f96e105 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201963 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent 02a694e commit f0c77ed

File tree

2 files changed

+1
-39
lines changed

2 files changed

+1
-39
lines changed

encoding/json/json.go

+1-27
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,6 @@ func Extract(path string, data []byte) (ast.Expr, error) {
6666
return expr, nil
6767
}
6868

69-
// Decode parses JSON-encoded data to a CUE value, using path for position
70-
// information.
71-
//
72-
// Deprecated: use Extract and build using cue.Context.BuildExpr.
73-
func Decode(r *cue.Runtime, path string, data []byte) (*cue.Instance, error) {
74-
expr, err := extract(path, data)
75-
if err != nil {
76-
return nil, err
77-
}
78-
return r.CompileExpr(expr)
79-
}
80-
8169
func extract(path string, b []byte) (ast.Expr, error) {
8270
expr, err := parser.ParseExpr(path, b)
8371
if err != nil || !json.Valid(b) {
@@ -104,13 +92,12 @@ func extract(path string, b []byte) (ast.Expr, error) {
10492
// information with each node. The runtime may be nil if the decoder
10593
// is only used to extract to CUE ast objects.
10694
//
107-
// The runtime may be nil if Decode isn't used.
95+
// The runtime argument is a historical remnant and unused.
10896
func NewDecoder(r *cue.Runtime, path string, src io.Reader) *Decoder {
10997
b, err := source.ReadAll(path, src)
11098
tokFile := token.NewFile(path, 0, len(b))
11199
tokFile.SetLinesForContent(b)
112100
return &Decoder{
113-
r: r,
114101
path: path,
115102
dec: json.NewDecoder(bytes.NewReader(b)),
116103
tokFile: tokFile,
@@ -120,7 +107,6 @@ func NewDecoder(r *cue.Runtime, path string, src io.Reader) *Decoder {
120107

121108
// A Decoder converts JSON values to CUE.
122109
type Decoder struct {
123-
r *cue.Runtime
124110
path string
125111
dec *json.Decoder
126112

@@ -173,18 +159,6 @@ func (d *Decoder) patchPos(n ast.Node) {
173159
ast.SetPos(n, realPos)
174160
}
175161

176-
// Decode converts the current JSON value to a CUE instance. It returns io.EOF
177-
// if the input has been exhausted.
178-
//
179-
// Deprecated: use Extract and build with cue.Context.BuildExpr.
180-
func (d *Decoder) Decode() (*cue.Instance, error) {
181-
expr, err := d.Extract()
182-
if err != nil {
183-
return nil, err
184-
}
185-
return d.r.CompileExpr(expr)
186-
}
187-
188162
// patchExpr simplifies the AST parsed from JSON.
189163
// TODO: some of the modifications are already done in format, but are
190164
// a package deal of a more aggressive simplify. Other pieces of modification

encoding/yaml/yaml.go

-12
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,6 @@ func Extract(filename string, src interface{}) (*ast.File, error) {
6868
return f, nil
6969
}
7070

71-
// Decode converts a YAML file to a CUE value. Streams are returned as a list
72-
// of the streamed values.
73-
//
74-
// Deprecated: use Extract and build the File with cue.Context.BuildFile.
75-
func Decode(r *cue.Runtime, filename string, src interface{}) (*cue.Instance, error) {
76-
file, err := Extract(filename, src)
77-
if err != nil {
78-
return nil, err
79-
}
80-
return r.CompileFile(file)
81-
}
82-
8371
// Encode returns the YAML encoding of v.
8472
func Encode(v cue.Value) ([]byte, error) {
8573
n := v.Syntax(cue.Final())

0 commit comments

Comments
 (0)