From f0c77ed99d74c1441ec8b18588da9998d0327fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 29 Sep 2024 22:11:30 +0200 Subject: [PATCH] encoding/json,encoding/yaml: remove long deprecated cue.Instance APIs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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í Change-Id: I10df893035a08b967ef9d9116650eb816f96e105 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201963 TryBot-Result: CUEcueckoo Unity-Result: CUE porcuepine Reviewed-by: Roger Peppe --- encoding/json/json.go | 28 +--------------------------- encoding/yaml/yaml.go | 12 ------------ 2 files changed, 1 insertion(+), 39 deletions(-) diff --git a/encoding/json/json.go b/encoding/json/json.go index 8ce020c13f2..2ef43739b57 100644 --- a/encoding/json/json.go +++ b/encoding/json/json.go @@ -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) { @@ -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, @@ -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 @@ -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 diff --git a/encoding/yaml/yaml.go b/encoding/yaml/yaml.go index 97a126e7a67..a06da8384f9 100644 --- a/encoding/yaml/yaml.go +++ b/encoding/yaml/yaml.go @@ -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())