Skip to content

Commit

Permalink
encoding/json,encoding/yaml: remove long deprecated cue.Instance APIs
Browse files Browse the repository at this point in the history
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í <mvdan@mvdan.cc>
Change-Id: I10df893035a08b967ef9d9116650eb816f96e105
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201963
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mvdan committed Sep 30, 2024
1 parent 02a694e commit f0c77ed
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 39 deletions.
28 changes: 1 addition & 27 deletions encoding/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ func Extract(path string, data []byte) (ast.Expr, error) {
return expr, nil
}

// Decode parses JSON-encoded data to a CUE value, using path for position
// information.
//
// Deprecated: use Extract and build using cue.Context.BuildExpr.
func Decode(r *cue.Runtime, path string, data []byte) (*cue.Instance, error) {
expr, err := extract(path, data)
if err != nil {
return nil, err
}
return r.CompileExpr(expr)
}

func extract(path string, b []byte) (ast.Expr, error) {
expr, err := parser.ParseExpr(path, b)
if err != nil || !json.Valid(b) {
Expand All @@ -104,13 +92,12 @@ func extract(path string, b []byte) (ast.Expr, error) {
// information with each node. The runtime may be nil if the decoder
// is only used to extract to CUE ast objects.
//
// The runtime may be nil if Decode isn't used.
// The runtime argument is a historical remnant and unused.
func NewDecoder(r *cue.Runtime, path string, src io.Reader) *Decoder {
b, err := source.ReadAll(path, src)
tokFile := token.NewFile(path, 0, len(b))
tokFile.SetLinesForContent(b)
return &Decoder{
r: r,
path: path,
dec: json.NewDecoder(bytes.NewReader(b)),
tokFile: tokFile,
Expand All @@ -120,7 +107,6 @@ func NewDecoder(r *cue.Runtime, path string, src io.Reader) *Decoder {

// A Decoder converts JSON values to CUE.
type Decoder struct {
r *cue.Runtime
path string
dec *json.Decoder

Expand Down Expand Up @@ -173,18 +159,6 @@ func (d *Decoder) patchPos(n ast.Node) {
ast.SetPos(n, realPos)
}

// Decode converts the current JSON value to a CUE instance. It returns io.EOF
// if the input has been exhausted.
//
// Deprecated: use Extract and build with cue.Context.BuildExpr.
func (d *Decoder) Decode() (*cue.Instance, error) {
expr, err := d.Extract()
if err != nil {
return nil, err
}
return d.r.CompileExpr(expr)
}

// patchExpr simplifies the AST parsed from JSON.
// TODO: some of the modifications are already done in format, but are
// a package deal of a more aggressive simplify. Other pieces of modification
Expand Down
12 changes: 0 additions & 12 deletions encoding/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@ func Extract(filename string, src interface{}) (*ast.File, error) {
return f, nil
}

// Decode converts a YAML file to a CUE value. Streams are returned as a list
// of the streamed values.
//
// Deprecated: use Extract and build the File with cue.Context.BuildFile.
func Decode(r *cue.Runtime, filename string, src interface{}) (*cue.Instance, error) {
file, err := Extract(filename, src)
if err != nil {
return nil, err
}
return r.CompileFile(file)
}

// Encode returns the YAML encoding of v.
func Encode(v cue.Value) ([]byte, error) {
n := v.Syntax(cue.Final())
Expand Down

0 comments on commit f0c77ed

Please sign in to comment.