mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-25 03:02:17 +00:00
build(deps): bump github.com/BurntSushi/toml in /src/runtime
Bumps [github.com/BurntSushi/toml](https://github.com/BurntSushi/toml) from 1.3.2 to 1.5.0. - [Release notes](https://github.com/BurntSushi/toml/releases) - [Commits](https://github.com/BurntSushi/toml/compare/v1.3.2...v1.5.0) --- updated-dependencies: - dependency-name: github.com/BurntSushi/toml dependency-version: 1.5.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
parent
acae4480ac
commit
54364f5733
@ -8,7 +8,7 @@ go 1.23.0
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5
|
code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5
|
||||||
github.com/BurntSushi/toml v1.3.2
|
github.com/BurntSushi/toml v1.5.0
|
||||||
github.com/blang/semver v3.5.1+incompatible
|
github.com/blang/semver v3.5.1+incompatible
|
||||||
github.com/blang/semver/v4 v4.0.0
|
github.com/blang/semver/v4 v4.0.0
|
||||||
github.com/container-orchestrated-devices/container-device-interface v0.6.0
|
github.com/container-orchestrated-devices/container-device-interface v0.6.0
|
||||||
|
@ -6,8 +6,9 @@ github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h
|
|||||||
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 h1:59MxjQVfjXsBpLy+dbd2/ELV5ofnUkUZBvWSC85sheA=
|
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 h1:59MxjQVfjXsBpLy+dbd2/ELV5ofnUkUZBvWSC85sheA=
|
||||||
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0/go.mod h1:OahwfttHWG6eJ0clwcfBAHoDI6X/LV/15hx/wlMZSrU=
|
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0/go.mod h1:OahwfttHWG6eJ0clwcfBAHoDI6X/LV/15hx/wlMZSrU=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
|
|
||||||
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
|
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
||||||
|
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
||||||
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
||||||
github.com/Microsoft/hcsshim v0.12.0 h1:rbICA+XZFwrBef2Odk++0LjFvClNCJGRK+fsrP254Ts=
|
github.com/Microsoft/hcsshim v0.12.0 h1:rbICA+XZFwrBef2Odk++0LjFvClNCJGRK+fsrP254Ts=
|
||||||
|
4
src/runtime/vendor/github.com/BurntSushi/toml/README.md
generated
vendored
4
src/runtime/vendor/github.com/BurntSushi/toml/README.md
generated
vendored
@ -3,13 +3,13 @@ reflection interface similar to Go's standard library `json` and `xml` packages.
|
|||||||
|
|
||||||
Compatible with TOML version [v1.0.0](https://toml.io/en/v1.0.0).
|
Compatible with TOML version [v1.0.0](https://toml.io/en/v1.0.0).
|
||||||
|
|
||||||
Documentation: https://godocs.io/github.com/BurntSushi/toml
|
Documentation: https://pkg.go.dev/github.com/BurntSushi/toml
|
||||||
|
|
||||||
See the [releases page](https://github.com/BurntSushi/toml/releases) for a
|
See the [releases page](https://github.com/BurntSushi/toml/releases) for a
|
||||||
changelog; this information is also in the git tag annotations (e.g. `git show
|
changelog; this information is also in the git tag annotations (e.g. `git show
|
||||||
v0.4.0`).
|
v0.4.0`).
|
||||||
|
|
||||||
This library requires Go 1.13 or newer; add it to your go.mod with:
|
This library requires Go 1.18 or newer; add it to your go.mod with:
|
||||||
|
|
||||||
% go get github.com/BurntSushi/toml@latest
|
% go get github.com/BurntSushi/toml@latest
|
||||||
|
|
||||||
|
126
src/runtime/vendor/github.com/BurntSushi/toml/decode.go
generated
vendored
126
src/runtime/vendor/github.com/BurntSushi/toml/decode.go
generated
vendored
@ -6,7 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/fs"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -18,13 +18,13 @@ import (
|
|||||||
// Unmarshaler is the interface implemented by objects that can unmarshal a
|
// Unmarshaler is the interface implemented by objects that can unmarshal a
|
||||||
// TOML description of themselves.
|
// TOML description of themselves.
|
||||||
type Unmarshaler interface {
|
type Unmarshaler interface {
|
||||||
UnmarshalTOML(interface{}) error
|
UnmarshalTOML(any) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal decodes the contents of data in TOML format into a pointer v.
|
// Unmarshal decodes the contents of data in TOML format into a pointer v.
|
||||||
//
|
//
|
||||||
// See [Decoder] for a description of the decoding process.
|
// See [Decoder] for a description of the decoding process.
|
||||||
func Unmarshal(data []byte, v interface{}) error {
|
func Unmarshal(data []byte, v any) error {
|
||||||
_, err := NewDecoder(bytes.NewReader(data)).Decode(v)
|
_, err := NewDecoder(bytes.NewReader(data)).Decode(v)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -32,12 +32,12 @@ func Unmarshal(data []byte, v interface{}) error {
|
|||||||
// Decode the TOML data in to the pointer v.
|
// Decode the TOML data in to the pointer v.
|
||||||
//
|
//
|
||||||
// See [Decoder] for a description of the decoding process.
|
// See [Decoder] for a description of the decoding process.
|
||||||
func Decode(data string, v interface{}) (MetaData, error) {
|
func Decode(data string, v any) (MetaData, error) {
|
||||||
return NewDecoder(strings.NewReader(data)).Decode(v)
|
return NewDecoder(strings.NewReader(data)).Decode(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecodeFile reads the contents of a file and decodes it with [Decode].
|
// DecodeFile reads the contents of a file and decodes it with [Decode].
|
||||||
func DecodeFile(path string, v interface{}) (MetaData, error) {
|
func DecodeFile(path string, v any) (MetaData, error) {
|
||||||
fp, err := os.Open(path)
|
fp, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MetaData{}, err
|
return MetaData{}, err
|
||||||
@ -46,6 +46,17 @@ func DecodeFile(path string, v interface{}) (MetaData, error) {
|
|||||||
return NewDecoder(fp).Decode(v)
|
return NewDecoder(fp).Decode(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DecodeFS reads the contents of a file from [fs.FS] and decodes it with
|
||||||
|
// [Decode].
|
||||||
|
func DecodeFS(fsys fs.FS, path string, v any) (MetaData, error) {
|
||||||
|
fp, err := fsys.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return MetaData{}, err
|
||||||
|
}
|
||||||
|
defer fp.Close()
|
||||||
|
return NewDecoder(fp).Decode(v)
|
||||||
|
}
|
||||||
|
|
||||||
// Primitive is a TOML value that hasn't been decoded into a Go value.
|
// Primitive is a TOML value that hasn't been decoded into a Go value.
|
||||||
//
|
//
|
||||||
// This type can be used for any value, which will cause decoding to be delayed.
|
// This type can be used for any value, which will cause decoding to be delayed.
|
||||||
@ -58,7 +69,7 @@ func DecodeFile(path string, v interface{}) (MetaData, error) {
|
|||||||
// overhead of reflection. They can be useful when you don't know the exact type
|
// overhead of reflection. They can be useful when you don't know the exact type
|
||||||
// of TOML data until runtime.
|
// of TOML data until runtime.
|
||||||
type Primitive struct {
|
type Primitive struct {
|
||||||
undecoded interface{}
|
undecoded any
|
||||||
context Key
|
context Key
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +133,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Decode TOML data in to the pointer `v`.
|
// Decode TOML data in to the pointer `v`.
|
||||||
func (dec *Decoder) Decode(v interface{}) (MetaData, error) {
|
func (dec *Decoder) Decode(v any) (MetaData, error) {
|
||||||
rv := reflect.ValueOf(v)
|
rv := reflect.ValueOf(v)
|
||||||
if rv.Kind() != reflect.Ptr {
|
if rv.Kind() != reflect.Ptr {
|
||||||
s := "%q"
|
s := "%q"
|
||||||
@ -136,8 +147,8 @@ func (dec *Decoder) Decode(v interface{}) (MetaData, error) {
|
|||||||
return MetaData{}, fmt.Errorf("toml: cannot decode to nil value of %q", reflect.TypeOf(v))
|
return MetaData{}, fmt.Errorf("toml: cannot decode to nil value of %q", reflect.TypeOf(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is a supported type: struct, map, interface{}, or something
|
// Check if this is a supported type: struct, map, any, or something that
|
||||||
// that implements UnmarshalTOML or UnmarshalText.
|
// implements UnmarshalTOML or UnmarshalText.
|
||||||
rv = indirect(rv)
|
rv = indirect(rv)
|
||||||
rt := rv.Type()
|
rt := rv.Type()
|
||||||
if rv.Kind() != reflect.Struct && rv.Kind() != reflect.Map &&
|
if rv.Kind() != reflect.Struct && rv.Kind() != reflect.Map &&
|
||||||
@ -148,7 +159,7 @@ func (dec *Decoder) Decode(v interface{}) (MetaData, error) {
|
|||||||
|
|
||||||
// TODO: parser should read from io.Reader? Or at the very least, make it
|
// TODO: parser should read from io.Reader? Or at the very least, make it
|
||||||
// read from []byte rather than string
|
// read from []byte rather than string
|
||||||
data, err := ioutil.ReadAll(dec.r)
|
data, err := io.ReadAll(dec.r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MetaData{}, err
|
return MetaData{}, err
|
||||||
}
|
}
|
||||||
@ -179,18 +190,31 @@ func (dec *Decoder) Decode(v interface{}) (MetaData, error) {
|
|||||||
// will only reflect keys that were decoded. Namely, any keys hidden behind a
|
// will only reflect keys that were decoded. Namely, any keys hidden behind a
|
||||||
// Primitive will be considered undecoded. Executing this method will update the
|
// Primitive will be considered undecoded. Executing this method will update the
|
||||||
// undecoded keys in the meta data. (See the example.)
|
// undecoded keys in the meta data. (See the example.)
|
||||||
func (md *MetaData) PrimitiveDecode(primValue Primitive, v interface{}) error {
|
func (md *MetaData) PrimitiveDecode(primValue Primitive, v any) error {
|
||||||
md.context = primValue.context
|
md.context = primValue.context
|
||||||
defer func() { md.context = nil }()
|
defer func() { md.context = nil }()
|
||||||
return md.unify(primValue.undecoded, rvalue(v))
|
return md.unify(primValue.undecoded, rvalue(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// markDecodedRecursive is a helper to mark any key under the given tmap as
|
||||||
|
// decoded, recursing as needed
|
||||||
|
func markDecodedRecursive(md *MetaData, tmap map[string]any) {
|
||||||
|
for key := range tmap {
|
||||||
|
md.decoded[md.context.add(key).String()] = struct{}{}
|
||||||
|
if tmap, ok := tmap[key].(map[string]any); ok {
|
||||||
|
md.context = append(md.context, key)
|
||||||
|
markDecodedRecursive(md, tmap)
|
||||||
|
md.context = md.context[0 : len(md.context)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// unify performs a sort of type unification based on the structure of `rv`,
|
// unify performs a sort of type unification based on the structure of `rv`,
|
||||||
// which is the client representation.
|
// which is the client representation.
|
||||||
//
|
//
|
||||||
// Any type mismatch produces an error. Finding a type that we don't know
|
// Any type mismatch produces an error. Finding a type that we don't know
|
||||||
// how to handle produces an unsupported type error.
|
// how to handle produces an unsupported type error.
|
||||||
func (md *MetaData) unify(data interface{}, rv reflect.Value) error {
|
func (md *MetaData) unify(data any, rv reflect.Value) error {
|
||||||
// Special case. Look for a `Primitive` value.
|
// Special case. Look for a `Primitive` value.
|
||||||
// TODO: #76 would make this superfluous after implemented.
|
// TODO: #76 would make this superfluous after implemented.
|
||||||
if rv.Type() == primitiveType {
|
if rv.Type() == primitiveType {
|
||||||
@ -207,7 +231,21 @@ func (md *MetaData) unify(data interface{}, rv reflect.Value) error {
|
|||||||
|
|
||||||
rvi := rv.Interface()
|
rvi := rv.Interface()
|
||||||
if v, ok := rvi.(Unmarshaler); ok {
|
if v, ok := rvi.(Unmarshaler); ok {
|
||||||
return v.UnmarshalTOML(data)
|
err := v.UnmarshalTOML(data)
|
||||||
|
if err != nil {
|
||||||
|
return md.parseErr(err)
|
||||||
|
}
|
||||||
|
// Assume the Unmarshaler decoded everything, so mark all keys under
|
||||||
|
// this table as decoded.
|
||||||
|
if tmap, ok := data.(map[string]any); ok {
|
||||||
|
markDecodedRecursive(md, tmap)
|
||||||
|
}
|
||||||
|
if aot, ok := data.([]map[string]any); ok {
|
||||||
|
for _, tmap := range aot {
|
||||||
|
markDecodedRecursive(md, tmap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
if v, ok := rvi.(encoding.TextUnmarshaler); ok {
|
if v, ok := rvi.(encoding.TextUnmarshaler); ok {
|
||||||
return md.unifyText(data, v)
|
return md.unifyText(data, v)
|
||||||
@ -227,14 +265,6 @@ func (md *MetaData) unify(data interface{}, rv reflect.Value) error {
|
|||||||
return md.unifyInt(data, rv)
|
return md.unifyInt(data, rv)
|
||||||
}
|
}
|
||||||
switch k {
|
switch k {
|
||||||
case reflect.Ptr:
|
|
||||||
elem := reflect.New(rv.Type().Elem())
|
|
||||||
err := md.unify(data, reflect.Indirect(elem))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
rv.Set(elem)
|
|
||||||
return nil
|
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
return md.unifyStruct(data, rv)
|
return md.unifyStruct(data, rv)
|
||||||
case reflect.Map:
|
case reflect.Map:
|
||||||
@ -258,14 +288,13 @@ func (md *MetaData) unify(data interface{}, rv reflect.Value) error {
|
|||||||
return md.e("unsupported type %s", rv.Kind())
|
return md.e("unsupported type %s", rv.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) unifyStruct(mapping interface{}, rv reflect.Value) error {
|
func (md *MetaData) unifyStruct(mapping any, rv reflect.Value) error {
|
||||||
tmap, ok := mapping.(map[string]interface{})
|
tmap, ok := mapping.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
if mapping == nil {
|
if mapping == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return md.e("type mismatch for %s: expected table but found %T",
|
return md.e("type mismatch for %s: expected table but found %s", rv.Type().String(), fmtType(mapping))
|
||||||
rv.Type().String(), mapping)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, datum := range tmap {
|
for key, datum := range tmap {
|
||||||
@ -304,14 +333,14 @@ func (md *MetaData) unifyStruct(mapping interface{}, rv reflect.Value) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) unifyMap(mapping interface{}, rv reflect.Value) error {
|
func (md *MetaData) unifyMap(mapping any, rv reflect.Value) error {
|
||||||
keyType := rv.Type().Key().Kind()
|
keyType := rv.Type().Key().Kind()
|
||||||
if keyType != reflect.String && keyType != reflect.Interface {
|
if keyType != reflect.String && keyType != reflect.Interface {
|
||||||
return fmt.Errorf("toml: cannot decode to a map with non-string key type (%s in %q)",
|
return fmt.Errorf("toml: cannot decode to a map with non-string key type (%s in %q)",
|
||||||
keyType, rv.Type())
|
keyType, rv.Type())
|
||||||
}
|
}
|
||||||
|
|
||||||
tmap, ok := mapping.(map[string]interface{})
|
tmap, ok := mapping.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
if tmap == nil {
|
if tmap == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -347,7 +376,7 @@ func (md *MetaData) unifyMap(mapping interface{}, rv reflect.Value) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) unifyArray(data interface{}, rv reflect.Value) error {
|
func (md *MetaData) unifyArray(data any, rv reflect.Value) error {
|
||||||
datav := reflect.ValueOf(data)
|
datav := reflect.ValueOf(data)
|
||||||
if datav.Kind() != reflect.Slice {
|
if datav.Kind() != reflect.Slice {
|
||||||
if !datav.IsValid() {
|
if !datav.IsValid() {
|
||||||
@ -361,7 +390,7 @@ func (md *MetaData) unifyArray(data interface{}, rv reflect.Value) error {
|
|||||||
return md.unifySliceArray(datav, rv)
|
return md.unifySliceArray(datav, rv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) unifySlice(data interface{}, rv reflect.Value) error {
|
func (md *MetaData) unifySlice(data any, rv reflect.Value) error {
|
||||||
datav := reflect.ValueOf(data)
|
datav := reflect.ValueOf(data)
|
||||||
if datav.Kind() != reflect.Slice {
|
if datav.Kind() != reflect.Slice {
|
||||||
if !datav.IsValid() {
|
if !datav.IsValid() {
|
||||||
@ -388,7 +417,7 @@ func (md *MetaData) unifySliceArray(data, rv reflect.Value) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) unifyString(data interface{}, rv reflect.Value) error {
|
func (md *MetaData) unifyString(data any, rv reflect.Value) error {
|
||||||
_, ok := rv.Interface().(json.Number)
|
_, ok := rv.Interface().(json.Number)
|
||||||
if ok {
|
if ok {
|
||||||
if i, ok := data.(int64); ok {
|
if i, ok := data.(int64); ok {
|
||||||
@ -408,7 +437,7 @@ func (md *MetaData) unifyString(data interface{}, rv reflect.Value) error {
|
|||||||
return md.badtype("string", data)
|
return md.badtype("string", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) unifyFloat64(data interface{}, rv reflect.Value) error {
|
func (md *MetaData) unifyFloat64(data any, rv reflect.Value) error {
|
||||||
rvk := rv.Kind()
|
rvk := rv.Kind()
|
||||||
|
|
||||||
if num, ok := data.(float64); ok {
|
if num, ok := data.(float64); ok {
|
||||||
@ -429,7 +458,7 @@ func (md *MetaData) unifyFloat64(data interface{}, rv reflect.Value) error {
|
|||||||
if num, ok := data.(int64); ok {
|
if num, ok := data.(int64); ok {
|
||||||
if (rvk == reflect.Float32 && (num < -maxSafeFloat32Int || num > maxSafeFloat32Int)) ||
|
if (rvk == reflect.Float32 && (num < -maxSafeFloat32Int || num > maxSafeFloat32Int)) ||
|
||||||
(rvk == reflect.Float64 && (num < -maxSafeFloat64Int || num > maxSafeFloat64Int)) {
|
(rvk == reflect.Float64 && (num < -maxSafeFloat64Int || num > maxSafeFloat64Int)) {
|
||||||
return md.parseErr(errParseRange{i: num, size: rvk.String()})
|
return md.parseErr(errUnsafeFloat{i: num, size: rvk.String()})
|
||||||
}
|
}
|
||||||
rv.SetFloat(float64(num))
|
rv.SetFloat(float64(num))
|
||||||
return nil
|
return nil
|
||||||
@ -438,7 +467,7 @@ func (md *MetaData) unifyFloat64(data interface{}, rv reflect.Value) error {
|
|||||||
return md.badtype("float", data)
|
return md.badtype("float", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) unifyInt(data interface{}, rv reflect.Value) error {
|
func (md *MetaData) unifyInt(data any, rv reflect.Value) error {
|
||||||
_, ok := rv.Interface().(time.Duration)
|
_, ok := rv.Interface().(time.Duration)
|
||||||
if ok {
|
if ok {
|
||||||
// Parse as string duration, and fall back to regular integer parsing
|
// Parse as string duration, and fall back to regular integer parsing
|
||||||
@ -481,7 +510,7 @@ func (md *MetaData) unifyInt(data interface{}, rv reflect.Value) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) unifyBool(data interface{}, rv reflect.Value) error {
|
func (md *MetaData) unifyBool(data any, rv reflect.Value) error {
|
||||||
if b, ok := data.(bool); ok {
|
if b, ok := data.(bool); ok {
|
||||||
rv.SetBool(b)
|
rv.SetBool(b)
|
||||||
return nil
|
return nil
|
||||||
@ -489,12 +518,12 @@ func (md *MetaData) unifyBool(data interface{}, rv reflect.Value) error {
|
|||||||
return md.badtype("boolean", data)
|
return md.badtype("boolean", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) unifyAnything(data interface{}, rv reflect.Value) error {
|
func (md *MetaData) unifyAnything(data any, rv reflect.Value) error {
|
||||||
rv.Set(reflect.ValueOf(data))
|
rv.Set(reflect.ValueOf(data))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) unifyText(data interface{}, v encoding.TextUnmarshaler) error {
|
func (md *MetaData) unifyText(data any, v encoding.TextUnmarshaler) error {
|
||||||
var s string
|
var s string
|
||||||
switch sdata := data.(type) {
|
switch sdata := data.(type) {
|
||||||
case Marshaler:
|
case Marshaler:
|
||||||
@ -523,27 +552,29 @@ func (md *MetaData) unifyText(data interface{}, v encoding.TextUnmarshaler) erro
|
|||||||
return md.badtype("primitive (string-like)", data)
|
return md.badtype("primitive (string-like)", data)
|
||||||
}
|
}
|
||||||
if err := v.UnmarshalText([]byte(s)); err != nil {
|
if err := v.UnmarshalText([]byte(s)); err != nil {
|
||||||
return err
|
return md.parseErr(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) badtype(dst string, data interface{}) error {
|
func (md *MetaData) badtype(dst string, data any) error {
|
||||||
return md.e("incompatible types: TOML value has type %T; destination has type %s", data, dst)
|
return md.e("incompatible types: TOML value has type %s; destination has type %s", fmtType(data), dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) parseErr(err error) error {
|
func (md *MetaData) parseErr(err error) error {
|
||||||
k := md.context.String()
|
k := md.context.String()
|
||||||
|
d := string(md.data)
|
||||||
return ParseError{
|
return ParseError{
|
||||||
LastKey: k,
|
Message: err.Error(),
|
||||||
Position: md.keyInfo[k].pos,
|
|
||||||
Line: md.keyInfo[k].pos.Line,
|
|
||||||
err: err,
|
err: err,
|
||||||
input: string(md.data),
|
LastKey: k,
|
||||||
|
Position: md.keyInfo[k].pos.withCol(d),
|
||||||
|
Line: md.keyInfo[k].pos.Line,
|
||||||
|
input: d,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (md *MetaData) e(format string, args ...interface{}) error {
|
func (md *MetaData) e(format string, args ...any) error {
|
||||||
f := "toml: "
|
f := "toml: "
|
||||||
if len(md.context) > 0 {
|
if len(md.context) > 0 {
|
||||||
f = fmt.Sprintf("toml: (last key %q): ", md.context)
|
f = fmt.Sprintf("toml: (last key %q): ", md.context)
|
||||||
@ -556,7 +587,7 @@ func (md *MetaData) e(format string, args ...interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// rvalue returns a reflect.Value of `v`. All pointers are resolved.
|
// rvalue returns a reflect.Value of `v`. All pointers are resolved.
|
||||||
func rvalue(v interface{}) reflect.Value {
|
func rvalue(v any) reflect.Value {
|
||||||
return indirect(reflect.ValueOf(v))
|
return indirect(reflect.ValueOf(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,3 +631,8 @@ func isUnifiable(rv reflect.Value) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fmt %T with "interface {}" replaced with "any", which is far more readable.
|
||||||
|
func fmtType(t any) string {
|
||||||
|
return strings.ReplaceAll(fmt.Sprintf("%T", t), "interface {}", "any")
|
||||||
|
}
|
||||||
|
19
src/runtime/vendor/github.com/BurntSushi/toml/decode_go116.go
generated
vendored
19
src/runtime/vendor/github.com/BurntSushi/toml/decode_go116.go
generated
vendored
@ -1,19 +0,0 @@
|
|||||||
//go:build go1.16
|
|
||||||
// +build go1.16
|
|
||||||
|
|
||||||
package toml
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/fs"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DecodeFS reads the contents of a file from [fs.FS] and decodes it with
|
|
||||||
// [Decode].
|
|
||||||
func DecodeFS(fsys fs.FS, path string, v interface{}) (MetaData, error) {
|
|
||||||
fp, err := fsys.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return MetaData{}, err
|
|
||||||
}
|
|
||||||
defer fp.Close()
|
|
||||||
return NewDecoder(fp).Decode(v)
|
|
||||||
}
|
|
18
src/runtime/vendor/github.com/BurntSushi/toml/deprecated.go
generated
vendored
18
src/runtime/vendor/github.com/BurntSushi/toml/deprecated.go
generated
vendored
@ -15,15 +15,15 @@ type TextMarshaler encoding.TextMarshaler
|
|||||||
// Deprecated: use encoding.TextUnmarshaler
|
// Deprecated: use encoding.TextUnmarshaler
|
||||||
type TextUnmarshaler encoding.TextUnmarshaler
|
type TextUnmarshaler encoding.TextUnmarshaler
|
||||||
|
|
||||||
// PrimitiveDecode is an alias for MetaData.PrimitiveDecode().
|
|
||||||
//
|
|
||||||
// Deprecated: use MetaData.PrimitiveDecode.
|
|
||||||
func PrimitiveDecode(primValue Primitive, v interface{}) error {
|
|
||||||
md := MetaData{decoded: make(map[string]struct{})}
|
|
||||||
return md.unify(primValue.undecoded, rvalue(v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeReader is an alias for NewDecoder(r).Decode(v).
|
// DecodeReader is an alias for NewDecoder(r).Decode(v).
|
||||||
//
|
//
|
||||||
// Deprecated: use NewDecoder(reader).Decode(&value).
|
// Deprecated: use NewDecoder(reader).Decode(&value).
|
||||||
func DecodeReader(r io.Reader, v interface{}) (MetaData, error) { return NewDecoder(r).Decode(v) }
|
func DecodeReader(r io.Reader, v any) (MetaData, error) { return NewDecoder(r).Decode(v) }
|
||||||
|
|
||||||
|
// PrimitiveDecode is an alias for MetaData.PrimitiveDecode().
|
||||||
|
//
|
||||||
|
// Deprecated: use MetaData.PrimitiveDecode.
|
||||||
|
func PrimitiveDecode(primValue Primitive, v any) error {
|
||||||
|
md := MetaData{decoded: make(map[string]struct{})}
|
||||||
|
return md.unify(primValue.undecoded, rvalue(v))
|
||||||
|
}
|
||||||
|
3
src/runtime/vendor/github.com/BurntSushi/toml/doc.go
generated
vendored
3
src/runtime/vendor/github.com/BurntSushi/toml/doc.go
generated
vendored
@ -2,9 +2,6 @@
|
|||||||
//
|
//
|
||||||
// This package supports TOML v1.0.0, as specified at https://toml.io
|
// This package supports TOML v1.0.0, as specified at https://toml.io
|
||||||
//
|
//
|
||||||
// There is also support for delaying decoding with the Primitive type, and
|
|
||||||
// querying the set of keys in a TOML document with the MetaData type.
|
|
||||||
//
|
|
||||||
// The github.com/BurntSushi/toml/cmd/tomlv package implements a TOML validator,
|
// The github.com/BurntSushi/toml/cmd/tomlv package implements a TOML validator,
|
||||||
// and can be used to verify if TOML document is valid. It can also be used to
|
// and can be used to verify if TOML document is valid. It can also be used to
|
||||||
// print the type of each key.
|
// print the type of each key.
|
||||||
|
91
src/runtime/vendor/github.com/BurntSushi/toml/encode.go
generated
vendored
91
src/runtime/vendor/github.com/BurntSushi/toml/encode.go
generated
vendored
@ -2,6 +2,7 @@ package toml
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"encoding"
|
"encoding"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
@ -76,6 +77,17 @@ type Marshaler interface {
|
|||||||
MarshalTOML() ([]byte, error)
|
MarshalTOML() ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Marshal returns a TOML representation of the Go value.
|
||||||
|
//
|
||||||
|
// See [Encoder] for a description of the encoding process.
|
||||||
|
func Marshal(v any) ([]byte, error) {
|
||||||
|
buff := new(bytes.Buffer)
|
||||||
|
if err := NewEncoder(buff).Encode(v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return buff.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
// Encoder encodes a Go to a TOML document.
|
// Encoder encodes a Go to a TOML document.
|
||||||
//
|
//
|
||||||
// The mapping between Go values and TOML values should be precisely the same as
|
// The mapping between Go values and TOML values should be precisely the same as
|
||||||
@ -115,26 +127,21 @@ type Marshaler interface {
|
|||||||
// NOTE: only exported keys are encoded due to the use of reflection. Unexported
|
// NOTE: only exported keys are encoded due to the use of reflection. Unexported
|
||||||
// keys are silently discarded.
|
// keys are silently discarded.
|
||||||
type Encoder struct {
|
type Encoder struct {
|
||||||
// String to use for a single indentation level; default is two spaces.
|
Indent string // string for a single indentation level; default is two spaces.
|
||||||
Indent string
|
hasWritten bool // written any output to w yet?
|
||||||
|
|
||||||
w *bufio.Writer
|
w *bufio.Writer
|
||||||
hasWritten bool // written any output to w yet?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEncoder create a new Encoder.
|
// NewEncoder create a new Encoder.
|
||||||
func NewEncoder(w io.Writer) *Encoder {
|
func NewEncoder(w io.Writer) *Encoder {
|
||||||
return &Encoder{
|
return &Encoder{w: bufio.NewWriter(w), Indent: " "}
|
||||||
w: bufio.NewWriter(w),
|
|
||||||
Indent: " ",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode writes a TOML representation of the Go value to the [Encoder]'s writer.
|
// Encode writes a TOML representation of the Go value to the [Encoder]'s writer.
|
||||||
//
|
//
|
||||||
// An error is returned if the value given cannot be encoded to a valid TOML
|
// An error is returned if the value given cannot be encoded to a valid TOML
|
||||||
// document.
|
// document.
|
||||||
func (enc *Encoder) Encode(v interface{}) error {
|
func (enc *Encoder) Encode(v any) error {
|
||||||
rv := eindirect(reflect.ValueOf(v))
|
rv := eindirect(reflect.ValueOf(v))
|
||||||
err := enc.safeEncode(Key([]string{}), rv)
|
err := enc.safeEncode(Key([]string{}), rv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -280,18 +287,30 @@ func (enc *Encoder) eElement(rv reflect.Value) {
|
|||||||
case reflect.Float32:
|
case reflect.Float32:
|
||||||
f := rv.Float()
|
f := rv.Float()
|
||||||
if math.IsNaN(f) {
|
if math.IsNaN(f) {
|
||||||
|
if math.Signbit(f) {
|
||||||
|
enc.wf("-")
|
||||||
|
}
|
||||||
enc.wf("nan")
|
enc.wf("nan")
|
||||||
} else if math.IsInf(f, 0) {
|
} else if math.IsInf(f, 0) {
|
||||||
enc.wf("%cinf", map[bool]byte{true: '-', false: '+'}[math.Signbit(f)])
|
if math.Signbit(f) {
|
||||||
|
enc.wf("-")
|
||||||
|
}
|
||||||
|
enc.wf("inf")
|
||||||
} else {
|
} else {
|
||||||
enc.wf(floatAddDecimal(strconv.FormatFloat(f, 'f', -1, 32)))
|
enc.wf(floatAddDecimal(strconv.FormatFloat(f, 'f', -1, 32)))
|
||||||
}
|
}
|
||||||
case reflect.Float64:
|
case reflect.Float64:
|
||||||
f := rv.Float()
|
f := rv.Float()
|
||||||
if math.IsNaN(f) {
|
if math.IsNaN(f) {
|
||||||
|
if math.Signbit(f) {
|
||||||
|
enc.wf("-")
|
||||||
|
}
|
||||||
enc.wf("nan")
|
enc.wf("nan")
|
||||||
} else if math.IsInf(f, 0) {
|
} else if math.IsInf(f, 0) {
|
||||||
enc.wf("%cinf", map[bool]byte{true: '-', false: '+'}[math.Signbit(f)])
|
if math.Signbit(f) {
|
||||||
|
enc.wf("-")
|
||||||
|
}
|
||||||
|
enc.wf("inf")
|
||||||
} else {
|
} else {
|
||||||
enc.wf(floatAddDecimal(strconv.FormatFloat(f, 'f', -1, 64)))
|
enc.wf(floatAddDecimal(strconv.FormatFloat(f, 'f', -1, 64)))
|
||||||
}
|
}
|
||||||
@ -304,7 +323,7 @@ func (enc *Encoder) eElement(rv reflect.Value) {
|
|||||||
case reflect.Interface:
|
case reflect.Interface:
|
||||||
enc.eElement(rv.Elem())
|
enc.eElement(rv.Elem())
|
||||||
default:
|
default:
|
||||||
encPanic(fmt.Errorf("unexpected type: %T", rv.Interface()))
|
encPanic(fmt.Errorf("unexpected type: %s", fmtType(rv.Interface())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,31 +402,30 @@ func (enc *Encoder) eMap(key Key, rv reflect.Value, inline bool) {
|
|||||||
|
|
||||||
// Sort keys so that we have deterministic output. And write keys directly
|
// Sort keys so that we have deterministic output. And write keys directly
|
||||||
// underneath this key first, before writing sub-structs or sub-maps.
|
// underneath this key first, before writing sub-structs or sub-maps.
|
||||||
var mapKeysDirect, mapKeysSub []string
|
var mapKeysDirect, mapKeysSub []reflect.Value
|
||||||
for _, mapKey := range rv.MapKeys() {
|
for _, mapKey := range rv.MapKeys() {
|
||||||
k := mapKey.String()
|
|
||||||
if typeIsTable(tomlTypeOfGo(eindirect(rv.MapIndex(mapKey)))) {
|
if typeIsTable(tomlTypeOfGo(eindirect(rv.MapIndex(mapKey)))) {
|
||||||
mapKeysSub = append(mapKeysSub, k)
|
mapKeysSub = append(mapKeysSub, mapKey)
|
||||||
} else {
|
} else {
|
||||||
mapKeysDirect = append(mapKeysDirect, k)
|
mapKeysDirect = append(mapKeysDirect, mapKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var writeMapKeys = func(mapKeys []string, trailC bool) {
|
writeMapKeys := func(mapKeys []reflect.Value, trailC bool) {
|
||||||
sort.Strings(mapKeys)
|
sort.Slice(mapKeys, func(i, j int) bool { return mapKeys[i].String() < mapKeys[j].String() })
|
||||||
for i, mapKey := range mapKeys {
|
for i, mapKey := range mapKeys {
|
||||||
val := eindirect(rv.MapIndex(reflect.ValueOf(mapKey)))
|
val := eindirect(rv.MapIndex(mapKey))
|
||||||
if isNil(val) {
|
if isNil(val) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if inline {
|
if inline {
|
||||||
enc.writeKeyValue(Key{mapKey}, val, true)
|
enc.writeKeyValue(Key{mapKey.String()}, val, true)
|
||||||
if trailC || i != len(mapKeys)-1 {
|
if trailC || i != len(mapKeys)-1 {
|
||||||
enc.wf(", ")
|
enc.wf(", ")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
enc.encode(key.add(mapKey), val)
|
enc.encode(key.add(mapKey.String()), val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -422,8 +440,6 @@ func (enc *Encoder) eMap(key Key, rv reflect.Value, inline bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const is32Bit = (32 << (^uint(0) >> 63)) == 32
|
|
||||||
|
|
||||||
func pointerTo(t reflect.Type) reflect.Type {
|
func pointerTo(t reflect.Type) reflect.Type {
|
||||||
if t.Kind() == reflect.Ptr {
|
if t.Kind() == reflect.Ptr {
|
||||||
return pointerTo(t.Elem())
|
return pointerTo(t.Elem())
|
||||||
@ -458,15 +474,14 @@ func (enc *Encoder) eStruct(key Key, rv reflect.Value, inline bool) {
|
|||||||
|
|
||||||
frv := eindirect(rv.Field(i))
|
frv := eindirect(rv.Field(i))
|
||||||
|
|
||||||
if is32Bit {
|
// Need to make a copy because ... ehm, I don't know why... I guess
|
||||||
// Copy so it works correct on 32bit archs; not clear why this
|
// allocating a new array can cause it to fail(?)
|
||||||
// is needed. See #314, and https://www.reddit.com/r/golang/comments/pnx8v4
|
//
|
||||||
// This also works fine on 64bit, but 32bit archs are somewhat
|
// Done for: https://github.com/BurntSushi/toml/issues/430
|
||||||
// rare and this is a wee bit faster.
|
// Previously only on 32bit for: https://github.com/BurntSushi/toml/issues/314
|
||||||
copyStart := make([]int, len(start))
|
copyStart := make([]int, len(start))
|
||||||
copy(copyStart, start)
|
copy(copyStart, start)
|
||||||
start = copyStart
|
start = copyStart
|
||||||
}
|
|
||||||
|
|
||||||
// Treat anonymous struct fields with tag names as though they are
|
// Treat anonymous struct fields with tag names as though they are
|
||||||
// not anonymous, like encoding/json does.
|
// not anonymous, like encoding/json does.
|
||||||
@ -488,7 +503,7 @@ func (enc *Encoder) eStruct(key Key, rv reflect.Value, inline bool) {
|
|||||||
}
|
}
|
||||||
addFields(rt, rv, nil)
|
addFields(rt, rv, nil)
|
||||||
|
|
||||||
writeFields := func(fields [][]int) {
|
writeFields := func(fields [][]int, totalFields int) {
|
||||||
for _, fieldIndex := range fields {
|
for _, fieldIndex := range fields {
|
||||||
fieldType := rt.FieldByIndex(fieldIndex)
|
fieldType := rt.FieldByIndex(fieldIndex)
|
||||||
fieldVal := rv.FieldByIndex(fieldIndex)
|
fieldVal := rv.FieldByIndex(fieldIndex)
|
||||||
@ -518,7 +533,7 @@ func (enc *Encoder) eStruct(key Key, rv reflect.Value, inline bool) {
|
|||||||
|
|
||||||
if inline {
|
if inline {
|
||||||
enc.writeKeyValue(Key{keyName}, fieldVal, true)
|
enc.writeKeyValue(Key{keyName}, fieldVal, true)
|
||||||
if fieldIndex[0] != len(fields)-1 {
|
if fieldIndex[0] != totalFields-1 {
|
||||||
enc.wf(", ")
|
enc.wf(", ")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -530,8 +545,10 @@ func (enc *Encoder) eStruct(key Key, rv reflect.Value, inline bool) {
|
|||||||
if inline {
|
if inline {
|
||||||
enc.wf("{")
|
enc.wf("{")
|
||||||
}
|
}
|
||||||
writeFields(fieldsDirect)
|
|
||||||
writeFields(fieldsSub)
|
l := len(fieldsDirect) + len(fieldsSub)
|
||||||
|
writeFields(fieldsDirect, l)
|
||||||
|
writeFields(fieldsSub, l)
|
||||||
if inline {
|
if inline {
|
||||||
enc.wf("}")
|
enc.wf("}")
|
||||||
}
|
}
|
||||||
@ -712,7 +729,7 @@ func (enc *Encoder) writeKeyValue(key Key, val reflect.Value, inline bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (enc *Encoder) wf(format string, v ...interface{}) {
|
func (enc *Encoder) wf(format string, v ...any) {
|
||||||
_, err := fmt.Fprintf(enc.w, format, v...)
|
_, err := fmt.Fprintf(enc.w, format, v...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
encPanic(err)
|
encPanic(err)
|
||||||
|
168
src/runtime/vendor/github.com/BurntSushi/toml/error.go
generated
vendored
168
src/runtime/vendor/github.com/BurntSushi/toml/error.go
generated
vendored
@ -67,21 +67,36 @@ type ParseError struct {
|
|||||||
// Position of an error.
|
// Position of an error.
|
||||||
type Position struct {
|
type Position struct {
|
||||||
Line int // Line number, starting at 1.
|
Line int // Line number, starting at 1.
|
||||||
|
Col int // Error column, starting at 1.
|
||||||
Start int // Start of error, as byte offset starting at 0.
|
Start int // Start of error, as byte offset starting at 0.
|
||||||
Len int // Lenght in bytes.
|
Len int // Length of the error in bytes.
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Position) withCol(tomlFile string) Position {
|
||||||
|
var (
|
||||||
|
pos int
|
||||||
|
lines = strings.Split(tomlFile, "\n")
|
||||||
|
)
|
||||||
|
for i := range lines {
|
||||||
|
ll := len(lines[i]) + 1 // +1 for the removed newline
|
||||||
|
if pos+ll >= p.Start {
|
||||||
|
p.Col = p.Start - pos + 1
|
||||||
|
if p.Col < 1 { // Should never happen, but just in case.
|
||||||
|
p.Col = 1
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
pos += ll
|
||||||
|
}
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pe ParseError) Error() string {
|
func (pe ParseError) Error() string {
|
||||||
msg := pe.Message
|
|
||||||
if msg == "" { // Error from errorf()
|
|
||||||
msg = pe.err.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
if pe.LastKey == "" {
|
if pe.LastKey == "" {
|
||||||
return fmt.Sprintf("toml: line %d: %s", pe.Position.Line, msg)
|
return fmt.Sprintf("toml: line %d: %s", pe.Position.Line, pe.Message)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("toml: line %d (last key %q): %s",
|
return fmt.Sprintf("toml: line %d (last key %q): %s",
|
||||||
pe.Position.Line, pe.LastKey, msg)
|
pe.Position.Line, pe.LastKey, pe.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrorWithPosition returns the error with detailed location context.
|
// ErrorWithPosition returns the error with detailed location context.
|
||||||
@ -92,35 +107,37 @@ func (pe ParseError) ErrorWithPosition() string {
|
|||||||
return pe.Error()
|
return pe.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
lines = strings.Split(pe.input, "\n")
|
|
||||||
col = pe.column(lines)
|
|
||||||
b = new(strings.Builder)
|
|
||||||
)
|
|
||||||
|
|
||||||
msg := pe.Message
|
|
||||||
if msg == "" {
|
|
||||||
msg = pe.err.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: don't show control characters as literals? This may not show up
|
// TODO: don't show control characters as literals? This may not show up
|
||||||
// well everywhere.
|
// well everywhere.
|
||||||
|
|
||||||
|
var (
|
||||||
|
lines = strings.Split(pe.input, "\n")
|
||||||
|
b = new(strings.Builder)
|
||||||
|
)
|
||||||
if pe.Position.Len == 1 {
|
if pe.Position.Len == 1 {
|
||||||
fmt.Fprintf(b, "toml: error: %s\n\nAt line %d, column %d:\n\n",
|
fmt.Fprintf(b, "toml: error: %s\n\nAt line %d, column %d:\n\n",
|
||||||
msg, pe.Position.Line, col+1)
|
pe.Message, pe.Position.Line, pe.Position.Col)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(b, "toml: error: %s\n\nAt line %d, column %d-%d:\n\n",
|
fmt.Fprintf(b, "toml: error: %s\n\nAt line %d, column %d-%d:\n\n",
|
||||||
msg, pe.Position.Line, col, col+pe.Position.Len)
|
pe.Message, pe.Position.Line, pe.Position.Col, pe.Position.Col+pe.Position.Len-1)
|
||||||
}
|
}
|
||||||
if pe.Position.Line > 2 {
|
if pe.Position.Line > 2 {
|
||||||
fmt.Fprintf(b, "% 7d | %s\n", pe.Position.Line-2, lines[pe.Position.Line-3])
|
fmt.Fprintf(b, "% 7d | %s\n", pe.Position.Line-2, expandTab(lines[pe.Position.Line-3]))
|
||||||
}
|
}
|
||||||
if pe.Position.Line > 1 {
|
if pe.Position.Line > 1 {
|
||||||
fmt.Fprintf(b, "% 7d | %s\n", pe.Position.Line-1, lines[pe.Position.Line-2])
|
fmt.Fprintf(b, "% 7d | %s\n", pe.Position.Line-1, expandTab(lines[pe.Position.Line-2]))
|
||||||
}
|
}
|
||||||
fmt.Fprintf(b, "% 7d | %s\n", pe.Position.Line, lines[pe.Position.Line-1])
|
|
||||||
fmt.Fprintf(b, "% 10s%s%s\n", "", strings.Repeat(" ", col), strings.Repeat("^", pe.Position.Len))
|
/// Expand tabs, so that the ^^^s are at the correct position, but leave
|
||||||
|
/// "column 10-13" intact. Adjusting this to the visual column would be
|
||||||
|
/// better, but we don't know the tabsize of the user in their editor, which
|
||||||
|
/// can be 8, 4, 2, or something else. We can't know. So leaving it as the
|
||||||
|
/// character index is probably the "most correct".
|
||||||
|
expanded := expandTab(lines[pe.Position.Line-1])
|
||||||
|
diff := len(expanded) - len(lines[pe.Position.Line-1])
|
||||||
|
|
||||||
|
fmt.Fprintf(b, "% 7d | %s\n", pe.Position.Line, expanded)
|
||||||
|
fmt.Fprintf(b, "% 10s%s%s\n", "", strings.Repeat(" ", pe.Position.Col-1+diff), strings.Repeat("^", pe.Position.Len))
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,34 +159,47 @@ func (pe ParseError) ErrorWithUsage() string {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pe ParseError) column(lines []string) int {
|
func expandTab(s string) string {
|
||||||
var pos, col int
|
var (
|
||||||
for i := range lines {
|
b strings.Builder
|
||||||
ll := len(lines[i]) + 1 // +1 for the removed newline
|
l int
|
||||||
if pos+ll >= pe.Position.Start {
|
fill = func(n int) string {
|
||||||
col = pe.Position.Start - pos
|
b := make([]byte, n)
|
||||||
if col < 0 { // Should never happen, but just in case.
|
for i := range b {
|
||||||
col = 0
|
b[i] = ' '
|
||||||
}
|
}
|
||||||
break
|
return string(b)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
b.Grow(len(s))
|
||||||
|
for _, r := range s {
|
||||||
|
switch r {
|
||||||
|
case '\t':
|
||||||
|
tw := 8 - l%8
|
||||||
|
b.WriteString(fill(tw))
|
||||||
|
l += tw
|
||||||
|
default:
|
||||||
|
b.WriteRune(r)
|
||||||
|
l += 1
|
||||||
}
|
}
|
||||||
pos += ll
|
|
||||||
}
|
}
|
||||||
|
return b.String()
|
||||||
return col
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
errLexControl struct{ r rune }
|
errLexControl struct{ r rune }
|
||||||
errLexEscape struct{ r rune }
|
errLexEscape struct{ r rune }
|
||||||
errLexUTF8 struct{ b byte }
|
errLexUTF8 struct{ b byte }
|
||||||
errLexInvalidNum struct{ v string }
|
errParseDate struct{ v string }
|
||||||
errLexInvalidDate struct{ v string }
|
|
||||||
errLexInlineTableNL struct{}
|
errLexInlineTableNL struct{}
|
||||||
errLexStringNL struct{}
|
errLexStringNL struct{}
|
||||||
errParseRange struct {
|
errParseRange struct {
|
||||||
i interface{} // int or float
|
i any // int or float
|
||||||
size string // "int64", "uint16", etc.
|
size string // "int64", "uint16", etc.
|
||||||
|
}
|
||||||
|
errUnsafeFloat struct {
|
||||||
|
i interface{} // float32 or float64
|
||||||
|
size string // "float32" or "float64"
|
||||||
}
|
}
|
||||||
errParseDuration struct{ d string }
|
errParseDuration struct{ d string }
|
||||||
)
|
)
|
||||||
@ -183,18 +213,20 @@ func (e errLexEscape) Error() string { return fmt.Sprintf(`invalid escape
|
|||||||
func (e errLexEscape) Usage() string { return usageEscape }
|
func (e errLexEscape) Usage() string { return usageEscape }
|
||||||
func (e errLexUTF8) Error() string { return fmt.Sprintf("invalid UTF-8 byte: 0x%02x", e.b) }
|
func (e errLexUTF8) Error() string { return fmt.Sprintf("invalid UTF-8 byte: 0x%02x", e.b) }
|
||||||
func (e errLexUTF8) Usage() string { return "" }
|
func (e errLexUTF8) Usage() string { return "" }
|
||||||
func (e errLexInvalidNum) Error() string { return fmt.Sprintf("invalid number: %q", e.v) }
|
func (e errParseDate) Error() string { return fmt.Sprintf("invalid datetime: %q", e.v) }
|
||||||
func (e errLexInvalidNum) Usage() string { return "" }
|
func (e errParseDate) Usage() string { return usageDate }
|
||||||
func (e errLexInvalidDate) Error() string { return fmt.Sprintf("invalid date: %q", e.v) }
|
|
||||||
func (e errLexInvalidDate) Usage() string { return "" }
|
|
||||||
func (e errLexInlineTableNL) Error() string { return "newlines not allowed within inline tables" }
|
func (e errLexInlineTableNL) Error() string { return "newlines not allowed within inline tables" }
|
||||||
func (e errLexInlineTableNL) Usage() string { return usageInlineNewline }
|
func (e errLexInlineTableNL) Usage() string { return usageInlineNewline }
|
||||||
func (e errLexStringNL) Error() string { return "strings cannot contain newlines" }
|
func (e errLexStringNL) Error() string { return "strings cannot contain newlines" }
|
||||||
func (e errLexStringNL) Usage() string { return usageStringNewline }
|
func (e errLexStringNL) Usage() string { return usageStringNewline }
|
||||||
func (e errParseRange) Error() string { return fmt.Sprintf("%v is out of range for %s", e.i, e.size) }
|
func (e errParseRange) Error() string { return fmt.Sprintf("%v is out of range for %s", e.i, e.size) }
|
||||||
func (e errParseRange) Usage() string { return usageIntOverflow }
|
func (e errParseRange) Usage() string { return usageIntOverflow }
|
||||||
func (e errParseDuration) Error() string { return fmt.Sprintf("invalid duration: %q", e.d) }
|
func (e errUnsafeFloat) Error() string {
|
||||||
func (e errParseDuration) Usage() string { return usageDuration }
|
return fmt.Sprintf("%v is out of the safe %s range", e.i, e.size)
|
||||||
|
}
|
||||||
|
func (e errUnsafeFloat) Usage() string { return usageUnsafeFloat }
|
||||||
|
func (e errParseDuration) Error() string { return fmt.Sprintf("invalid duration: %q", e.d) }
|
||||||
|
func (e errParseDuration) Usage() string { return usageDuration }
|
||||||
|
|
||||||
const usageEscape = `
|
const usageEscape = `
|
||||||
A '\' inside a "-delimited string is interpreted as an escape character.
|
A '\' inside a "-delimited string is interpreted as an escape character.
|
||||||
@ -251,19 +283,35 @@ bug in the program that uses too small of an integer.
|
|||||||
The maximum and minimum values are:
|
The maximum and minimum values are:
|
||||||
|
|
||||||
size │ lowest │ highest
|
size │ lowest │ highest
|
||||||
───────┼────────────────┼──────────
|
───────┼────────────────┼──────────────
|
||||||
int8 │ -128 │ 127
|
int8 │ -128 │ 127
|
||||||
int16 │ -32,768 │ 32,767
|
int16 │ -32,768 │ 32,767
|
||||||
int32 │ -2,147,483,648 │ 2,147,483,647
|
int32 │ -2,147,483,648 │ 2,147,483,647
|
||||||
int64 │ -9.2 × 10¹⁷ │ 9.2 × 10¹⁷
|
int64 │ -9.2 × 10¹⁷ │ 9.2 × 10¹⁷
|
||||||
uint8 │ 0 │ 255
|
uint8 │ 0 │ 255
|
||||||
uint16 │ 0 │ 65535
|
uint16 │ 0 │ 65,535
|
||||||
uint32 │ 0 │ 4294967295
|
uint32 │ 0 │ 4,294,967,295
|
||||||
uint64 │ 0 │ 1.8 × 10¹⁸
|
uint64 │ 0 │ 1.8 × 10¹⁸
|
||||||
|
|
||||||
int refers to int32 on 32-bit systems and int64 on 64-bit systems.
|
int refers to int32 on 32-bit systems and int64 on 64-bit systems.
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const usageUnsafeFloat = `
|
||||||
|
This number is outside of the "safe" range for floating point numbers; whole
|
||||||
|
(non-fractional) numbers outside the below range can not always be represented
|
||||||
|
accurately in a float, leading to some loss of accuracy.
|
||||||
|
|
||||||
|
Explicitly mark a number as a fractional unit by adding ".0", which will incur
|
||||||
|
some loss of accuracy; for example:
|
||||||
|
|
||||||
|
f = 2_000_000_000.0
|
||||||
|
|
||||||
|
Accuracy ranges:
|
||||||
|
|
||||||
|
float32 = 16,777,215
|
||||||
|
float64 = 9,007,199,254,740,991
|
||||||
|
`
|
||||||
|
|
||||||
const usageDuration = `
|
const usageDuration = `
|
||||||
A duration must be as "number<unit>", without any spaces. Valid units are:
|
A duration must be as "number<unit>", without any spaces. Valid units are:
|
||||||
|
|
||||||
@ -277,3 +325,23 @@ A duration must be as "number<unit>", without any spaces. Valid units are:
|
|||||||
You can combine multiple units; for example "5m10s" for 5 minutes and 10
|
You can combine multiple units; for example "5m10s" for 5 minutes and 10
|
||||||
seconds.
|
seconds.
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const usageDate = `
|
||||||
|
A TOML datetime must be in one of the following formats:
|
||||||
|
|
||||||
|
2006-01-02T15:04:05Z07:00 Date and time, with timezone.
|
||||||
|
2006-01-02T15:04:05 Date and time, but without timezone.
|
||||||
|
2006-01-02 Date without a time or timezone.
|
||||||
|
15:04:05 Just a time, without any timezone.
|
||||||
|
|
||||||
|
Seconds may optionally have a fraction, up to nanosecond precision:
|
||||||
|
|
||||||
|
15:04:05.123
|
||||||
|
15:04:05.856018510
|
||||||
|
`
|
||||||
|
|
||||||
|
// TOML 1.1:
|
||||||
|
// The seconds part in times is optional, and may be omitted:
|
||||||
|
// 2006-01-02T15:04Z07:00
|
||||||
|
// 2006-01-02T15:04
|
||||||
|
// 15:04
|
||||||
|
83
src/runtime/vendor/github.com/BurntSushi/toml/lex.go
generated
vendored
83
src/runtime/vendor/github.com/BurntSushi/toml/lex.go
generated
vendored
@ -17,6 +17,7 @@ const (
|
|||||||
itemEOF
|
itemEOF
|
||||||
itemText
|
itemText
|
||||||
itemString
|
itemString
|
||||||
|
itemStringEsc
|
||||||
itemRawString
|
itemRawString
|
||||||
itemMultilineString
|
itemMultilineString
|
||||||
itemRawMultilineString
|
itemRawMultilineString
|
||||||
@ -53,6 +54,7 @@ type lexer struct {
|
|||||||
state stateFn
|
state stateFn
|
||||||
items chan item
|
items chan item
|
||||||
tomlNext bool
|
tomlNext bool
|
||||||
|
esc bool
|
||||||
|
|
||||||
// Allow for backing up up to 4 runes. This is necessary because TOML
|
// Allow for backing up up to 4 runes. This is necessary because TOML
|
||||||
// contains 3-rune tokens (""" and ''').
|
// contains 3-rune tokens (""" and ''').
|
||||||
@ -164,7 +166,7 @@ func (lx *lexer) next() (r rune) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
r, w := utf8.DecodeRuneInString(lx.input[lx.pos:])
|
r, w := utf8.DecodeRuneInString(lx.input[lx.pos:])
|
||||||
if r == utf8.RuneError {
|
if r == utf8.RuneError && w == 1 {
|
||||||
lx.error(errLexUTF8{lx.input[lx.pos]})
|
lx.error(errLexUTF8{lx.input[lx.pos]})
|
||||||
return utf8.RuneError
|
return utf8.RuneError
|
||||||
}
|
}
|
||||||
@ -270,10 +272,12 @@ func (lx *lexer) errorPos(start, length int, err error) stateFn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// errorf is like error, and creates a new error.
|
// errorf is like error, and creates a new error.
|
||||||
func (lx *lexer) errorf(format string, values ...interface{}) stateFn {
|
func (lx *lexer) errorf(format string, values ...any) stateFn {
|
||||||
if lx.atEOF {
|
if lx.atEOF {
|
||||||
pos := lx.getPos()
|
pos := lx.getPos()
|
||||||
pos.Line--
|
if lx.pos >= 1 && lx.input[lx.pos-1] == '\n' {
|
||||||
|
pos.Line--
|
||||||
|
}
|
||||||
pos.Len = 1
|
pos.Len = 1
|
||||||
pos.Start = lx.pos - 1
|
pos.Start = lx.pos - 1
|
||||||
lx.items <- item{typ: itemError, pos: pos, err: fmt.Errorf(format, values...)}
|
lx.items <- item{typ: itemError, pos: pos, err: fmt.Errorf(format, values...)}
|
||||||
@ -333,9 +337,7 @@ func lexTopEnd(lx *lexer) stateFn {
|
|||||||
lx.emit(itemEOF)
|
lx.emit(itemEOF)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return lx.errorf(
|
return lx.errorf("expected a top-level item to end with a newline, comment, or EOF, but got %q instead", r)
|
||||||
"expected a top-level item to end with a newline, comment, or EOF, but got %q instead",
|
|
||||||
r)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// lexTable lexes the beginning of a table. Namely, it makes sure that
|
// lexTable lexes the beginning of a table. Namely, it makes sure that
|
||||||
@ -492,6 +494,9 @@ func lexKeyEnd(lx *lexer) stateFn {
|
|||||||
lx.emit(itemKeyEnd)
|
lx.emit(itemKeyEnd)
|
||||||
return lexSkip(lx, lexValue)
|
return lexSkip(lx, lexValue)
|
||||||
default:
|
default:
|
||||||
|
if r == '\n' {
|
||||||
|
return lx.errorPrevLine(fmt.Errorf("expected '.' or '=', but got %q instead", r))
|
||||||
|
}
|
||||||
return lx.errorf("expected '.' or '=', but got %q instead", r)
|
return lx.errorf("expected '.' or '=', but got %q instead", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -560,6 +565,9 @@ func lexValue(lx *lexer) stateFn {
|
|||||||
if r == eof {
|
if r == eof {
|
||||||
return lx.errorf("unexpected EOF; expected value")
|
return lx.errorf("unexpected EOF; expected value")
|
||||||
}
|
}
|
||||||
|
if r == '\n' {
|
||||||
|
return lx.errorPrevLine(fmt.Errorf("expected value but found %q instead", r))
|
||||||
|
}
|
||||||
return lx.errorf("expected value but found %q instead", r)
|
return lx.errorf("expected value but found %q instead", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -698,7 +706,12 @@ func lexString(lx *lexer) stateFn {
|
|||||||
return lexStringEscape
|
return lexStringEscape
|
||||||
case r == '"':
|
case r == '"':
|
||||||
lx.backup()
|
lx.backup()
|
||||||
lx.emit(itemString)
|
if lx.esc {
|
||||||
|
lx.esc = false
|
||||||
|
lx.emit(itemStringEsc)
|
||||||
|
} else {
|
||||||
|
lx.emit(itemString)
|
||||||
|
}
|
||||||
lx.next()
|
lx.next()
|
||||||
lx.ignore()
|
lx.ignore()
|
||||||
return lx.pop()
|
return lx.pop()
|
||||||
@ -748,6 +761,7 @@ func lexMultilineString(lx *lexer) stateFn {
|
|||||||
lx.backup() /// backup: don't include the """ in the item.
|
lx.backup() /// backup: don't include the """ in the item.
|
||||||
lx.backup()
|
lx.backup()
|
||||||
lx.backup()
|
lx.backup()
|
||||||
|
lx.esc = false
|
||||||
lx.emit(itemMultilineString)
|
lx.emit(itemMultilineString)
|
||||||
lx.next() /// Read over ''' again and discard it.
|
lx.next() /// Read over ''' again and discard it.
|
||||||
lx.next()
|
lx.next()
|
||||||
@ -837,6 +851,7 @@ func lexMultilineStringEscape(lx *lexer) stateFn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func lexStringEscape(lx *lexer) stateFn {
|
func lexStringEscape(lx *lexer) stateFn {
|
||||||
|
lx.esc = true
|
||||||
r := lx.next()
|
r := lx.next()
|
||||||
switch r {
|
switch r {
|
||||||
case 'e':
|
case 'e':
|
||||||
@ -879,10 +894,8 @@ func lexHexEscape(lx *lexer) stateFn {
|
|||||||
var r rune
|
var r rune
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
r = lx.next()
|
r = lx.next()
|
||||||
if !isHexadecimal(r) {
|
if !isHex(r) {
|
||||||
return lx.errorf(
|
return lx.errorf(`expected two hexadecimal digits after '\x', but got %q instead`, lx.current())
|
||||||
`expected two hexadecimal digits after '\x', but got %q instead`,
|
|
||||||
lx.current())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lx.pop()
|
return lx.pop()
|
||||||
@ -892,10 +905,8 @@ func lexShortUnicodeEscape(lx *lexer) stateFn {
|
|||||||
var r rune
|
var r rune
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
r = lx.next()
|
r = lx.next()
|
||||||
if !isHexadecimal(r) {
|
if !isHex(r) {
|
||||||
return lx.errorf(
|
return lx.errorf(`expected four hexadecimal digits after '\u', but got %q instead`, lx.current())
|
||||||
`expected four hexadecimal digits after '\u', but got %q instead`,
|
|
||||||
lx.current())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lx.pop()
|
return lx.pop()
|
||||||
@ -905,10 +916,8 @@ func lexLongUnicodeEscape(lx *lexer) stateFn {
|
|||||||
var r rune
|
var r rune
|
||||||
for i := 0; i < 8; i++ {
|
for i := 0; i < 8; i++ {
|
||||||
r = lx.next()
|
r = lx.next()
|
||||||
if !isHexadecimal(r) {
|
if !isHex(r) {
|
||||||
return lx.errorf(
|
return lx.errorf(`expected eight hexadecimal digits after '\U', but got %q instead`, lx.current())
|
||||||
`expected eight hexadecimal digits after '\U', but got %q instead`,
|
|
||||||
lx.current())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lx.pop()
|
return lx.pop()
|
||||||
@ -975,7 +984,7 @@ func lexDatetime(lx *lexer) stateFn {
|
|||||||
// lexHexInteger consumes a hexadecimal integer after seeing the '0x' prefix.
|
// lexHexInteger consumes a hexadecimal integer after seeing the '0x' prefix.
|
||||||
func lexHexInteger(lx *lexer) stateFn {
|
func lexHexInteger(lx *lexer) stateFn {
|
||||||
r := lx.next()
|
r := lx.next()
|
||||||
if isHexadecimal(r) {
|
if isHex(r) {
|
||||||
return lexHexInteger
|
return lexHexInteger
|
||||||
}
|
}
|
||||||
switch r {
|
switch r {
|
||||||
@ -1109,8 +1118,8 @@ func lexBaseNumberOrDate(lx *lexer) stateFn {
|
|||||||
return lexOctalInteger
|
return lexOctalInteger
|
||||||
case 'x':
|
case 'x':
|
||||||
r = lx.peek()
|
r = lx.peek()
|
||||||
if !isHexadecimal(r) {
|
if !isHex(r) {
|
||||||
lx.errorf("not a hexidecimal number: '%s%c'", lx.current(), r)
|
lx.errorf("not a hexadecimal number: '%s%c'", lx.current(), r)
|
||||||
}
|
}
|
||||||
return lexHexInteger
|
return lexHexInteger
|
||||||
}
|
}
|
||||||
@ -1207,7 +1216,7 @@ func (itype itemType) String() string {
|
|||||||
return "EOF"
|
return "EOF"
|
||||||
case itemText:
|
case itemText:
|
||||||
return "Text"
|
return "Text"
|
||||||
case itemString, itemRawString, itemMultilineString, itemRawMultilineString:
|
case itemString, itemStringEsc, itemRawString, itemMultilineString, itemRawMultilineString:
|
||||||
return "String"
|
return "String"
|
||||||
case itemBool:
|
case itemBool:
|
||||||
return "Bool"
|
return "Bool"
|
||||||
@ -1240,7 +1249,7 @@ func (itype itemType) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (item item) String() string {
|
func (item item) String() string {
|
||||||
return fmt.Sprintf("(%s, %s)", item.typ.String(), item.val)
|
return fmt.Sprintf("(%s, %s)", item.typ, item.val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isWhitespace(r rune) bool { return r == '\t' || r == ' ' }
|
func isWhitespace(r rune) bool { return r == '\t' || r == ' ' }
|
||||||
@ -1256,28 +1265,8 @@ func isControl(r rune) bool { // Control characters except \t, \r, \n
|
|||||||
func isDigit(r rune) bool { return r >= '0' && r <= '9' }
|
func isDigit(r rune) bool { return r >= '0' && r <= '9' }
|
||||||
func isBinary(r rune) bool { return r == '0' || r == '1' }
|
func isBinary(r rune) bool { return r == '0' || r == '1' }
|
||||||
func isOctal(r rune) bool { return r >= '0' && r <= '7' }
|
func isOctal(r rune) bool { return r >= '0' && r <= '7' }
|
||||||
func isHexadecimal(r rune) bool {
|
func isHex(r rune) bool { return (r >= '0' && r <= '9') || (r|0x20 >= 'a' && r|0x20 <= 'f') }
|
||||||
return (r >= '0' && r <= '9') || (r >= 'a' && r <= 'f') || (r >= 'A' && r <= 'F')
|
|
||||||
}
|
|
||||||
|
|
||||||
func isBareKeyChar(r rune, tomlNext bool) bool {
|
func isBareKeyChar(r rune, tomlNext bool) bool {
|
||||||
if tomlNext {
|
return (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') ||
|
||||||
return (r >= 'A' && r <= 'Z') ||
|
(r >= '0' && r <= '9') || r == '_' || r == '-'
|
||||||
(r >= 'a' && r <= 'z') ||
|
|
||||||
(r >= '0' && r <= '9') ||
|
|
||||||
r == '_' || r == '-' ||
|
|
||||||
r == 0xb2 || r == 0xb3 || r == 0xb9 || (r >= 0xbc && r <= 0xbe) ||
|
|
||||||
(r >= 0xc0 && r <= 0xd6) || (r >= 0xd8 && r <= 0xf6) || (r >= 0xf8 && r <= 0x037d) ||
|
|
||||||
(r >= 0x037f && r <= 0x1fff) ||
|
|
||||||
(r >= 0x200c && r <= 0x200d) || (r >= 0x203f && r <= 0x2040) ||
|
|
||||||
(r >= 0x2070 && r <= 0x218f) || (r >= 0x2460 && r <= 0x24ff) ||
|
|
||||||
(r >= 0x2c00 && r <= 0x2fef) || (r >= 0x3001 && r <= 0xd7ff) ||
|
|
||||||
(r >= 0xf900 && r <= 0xfdcf) || (r >= 0xfdf0 && r <= 0xfffd) ||
|
|
||||||
(r >= 0x10000 && r <= 0xeffff)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (r >= 'A' && r <= 'Z') ||
|
|
||||||
(r >= 'a' && r <= 'z') ||
|
|
||||||
(r >= '0' && r <= '9') ||
|
|
||||||
r == '_' || r == '-'
|
|
||||||
}
|
}
|
||||||
|
46
src/runtime/vendor/github.com/BurntSushi/toml/meta.go
generated
vendored
46
src/runtime/vendor/github.com/BurntSushi/toml/meta.go
generated
vendored
@ -13,7 +13,7 @@ type MetaData struct {
|
|||||||
context Key // Used only during decoding.
|
context Key // Used only during decoding.
|
||||||
|
|
||||||
keyInfo map[string]keyInfo
|
keyInfo map[string]keyInfo
|
||||||
mapping map[string]interface{}
|
mapping map[string]any
|
||||||
keys []Key
|
keys []Key
|
||||||
decoded map[string]struct{}
|
decoded map[string]struct{}
|
||||||
data []byte // Input file; for errors.
|
data []byte // Input file; for errors.
|
||||||
@ -31,12 +31,12 @@ func (md *MetaData) IsDefined(key ...string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
hash map[string]interface{}
|
hash map[string]any
|
||||||
ok bool
|
ok bool
|
||||||
hashOrVal interface{} = md.mapping
|
hashOrVal any = md.mapping
|
||||||
)
|
)
|
||||||
for _, k := range key {
|
for _, k := range key {
|
||||||
if hash, ok = hashOrVal.(map[string]interface{}); !ok {
|
if hash, ok = hashOrVal.(map[string]any); !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if hashOrVal, ok = hash[k]; !ok {
|
if hashOrVal, ok = hash[k]; !ok {
|
||||||
@ -94,28 +94,52 @@ func (md *MetaData) Undecoded() []Key {
|
|||||||
type Key []string
|
type Key []string
|
||||||
|
|
||||||
func (k Key) String() string {
|
func (k Key) String() string {
|
||||||
ss := make([]string, len(k))
|
// This is called quite often, so it's a bit funky to make it faster.
|
||||||
for i := range k {
|
var b strings.Builder
|
||||||
ss[i] = k.maybeQuoted(i)
|
b.Grow(len(k) * 25)
|
||||||
|
outer:
|
||||||
|
for i, kk := range k {
|
||||||
|
if i > 0 {
|
||||||
|
b.WriteByte('.')
|
||||||
|
}
|
||||||
|
if kk == "" {
|
||||||
|
b.WriteString(`""`)
|
||||||
|
} else {
|
||||||
|
for _, r := range kk {
|
||||||
|
// "Inline" isBareKeyChar
|
||||||
|
if !((r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') || r == '_' || r == '-') {
|
||||||
|
b.WriteByte('"')
|
||||||
|
b.WriteString(dblQuotedReplacer.Replace(kk))
|
||||||
|
b.WriteByte('"')
|
||||||
|
continue outer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.WriteString(kk)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return strings.Join(ss, ".")
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Key) maybeQuoted(i int) string {
|
func (k Key) maybeQuoted(i int) string {
|
||||||
if k[i] == "" {
|
if k[i] == "" {
|
||||||
return `""`
|
return `""`
|
||||||
}
|
}
|
||||||
for _, c := range k[i] {
|
for _, r := range k[i] {
|
||||||
if !isBareKeyChar(c, false) {
|
if (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') || r == '_' || r == '-' {
|
||||||
return `"` + dblQuotedReplacer.Replace(k[i]) + `"`
|
continue
|
||||||
}
|
}
|
||||||
|
return `"` + dblQuotedReplacer.Replace(k[i]) + `"`
|
||||||
}
|
}
|
||||||
return k[i]
|
return k[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Like append(), but only increase the cap by 1.
|
||||||
func (k Key) add(piece string) Key {
|
func (k Key) add(piece string) Key {
|
||||||
newKey := make(Key, len(k)+1)
|
newKey := make(Key, len(k)+1)
|
||||||
copy(newKey, k)
|
copy(newKey, k)
|
||||||
newKey[len(k)] = piece
|
newKey[len(k)] = piece
|
||||||
return newKey
|
return newKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (k Key) parent() Key { return k[:len(k)-1] } // all except the last piece.
|
||||||
|
func (k Key) last() string { return k[len(k)-1] } // last piece of this key.
|
||||||
|
282
src/runtime/vendor/github.com/BurntSushi/toml/parse.go
generated
vendored
282
src/runtime/vendor/github.com/BurntSushi/toml/parse.go
generated
vendored
@ -2,6 +2,7 @@ package toml
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -20,9 +21,9 @@ type parser struct {
|
|||||||
|
|
||||||
ordered []Key // List of keys in the order that they appear in the TOML data.
|
ordered []Key // List of keys in the order that they appear in the TOML data.
|
||||||
|
|
||||||
keyInfo map[string]keyInfo // Map keyname → info about the TOML key.
|
keyInfo map[string]keyInfo // Map keyname → info about the TOML key.
|
||||||
mapping map[string]interface{} // Map keyname → key value.
|
mapping map[string]any // Map keyname → key value.
|
||||||
implicits map[string]struct{} // Record implicit keys (e.g. "key.group.names").
|
implicits map[string]struct{} // Record implicit keys (e.g. "key.group.names").
|
||||||
}
|
}
|
||||||
|
|
||||||
type keyInfo struct {
|
type keyInfo struct {
|
||||||
@ -63,7 +64,7 @@ func parse(data string) (p *parser, err error) {
|
|||||||
if i := strings.IndexRune(data[:ex], 0); i > -1 {
|
if i := strings.IndexRune(data[:ex], 0); i > -1 {
|
||||||
return nil, ParseError{
|
return nil, ParseError{
|
||||||
Message: "files cannot contain NULL bytes; probably using UTF-16; TOML files must be UTF-8",
|
Message: "files cannot contain NULL bytes; probably using UTF-16; TOML files must be UTF-8",
|
||||||
Position: Position{Line: 1, Start: i, Len: 1},
|
Position: Position{Line: 1, Col: 1, Start: i, Len: 1},
|
||||||
Line: 1,
|
Line: 1,
|
||||||
input: data,
|
input: data,
|
||||||
}
|
}
|
||||||
@ -71,7 +72,7 @@ func parse(data string) (p *parser, err error) {
|
|||||||
|
|
||||||
p = &parser{
|
p = &parser{
|
||||||
keyInfo: make(map[string]keyInfo),
|
keyInfo: make(map[string]keyInfo),
|
||||||
mapping: make(map[string]interface{}),
|
mapping: make(map[string]any),
|
||||||
lx: lex(data, tomlNext),
|
lx: lex(data, tomlNext),
|
||||||
ordered: make([]Key, 0),
|
ordered: make([]Key, 0),
|
||||||
implicits: make(map[string]struct{}),
|
implicits: make(map[string]struct{}),
|
||||||
@ -90,26 +91,27 @@ func parse(data string) (p *parser, err error) {
|
|||||||
|
|
||||||
func (p *parser) panicErr(it item, err error) {
|
func (p *parser) panicErr(it item, err error) {
|
||||||
panic(ParseError{
|
panic(ParseError{
|
||||||
|
Message: err.Error(),
|
||||||
err: err,
|
err: err,
|
||||||
Position: it.pos,
|
Position: it.pos.withCol(p.lx.input),
|
||||||
Line: it.pos.Len,
|
Line: it.pos.Len,
|
||||||
LastKey: p.current(),
|
LastKey: p.current(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) panicItemf(it item, format string, v ...interface{}) {
|
func (p *parser) panicItemf(it item, format string, v ...any) {
|
||||||
panic(ParseError{
|
panic(ParseError{
|
||||||
Message: fmt.Sprintf(format, v...),
|
Message: fmt.Sprintf(format, v...),
|
||||||
Position: it.pos,
|
Position: it.pos.withCol(p.lx.input),
|
||||||
Line: it.pos.Len,
|
Line: it.pos.Len,
|
||||||
LastKey: p.current(),
|
LastKey: p.current(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) panicf(format string, v ...interface{}) {
|
func (p *parser) panicf(format string, v ...any) {
|
||||||
panic(ParseError{
|
panic(ParseError{
|
||||||
Message: fmt.Sprintf(format, v...),
|
Message: fmt.Sprintf(format, v...),
|
||||||
Position: p.pos,
|
Position: p.pos.withCol(p.lx.input),
|
||||||
Line: p.pos.Line,
|
Line: p.pos.Line,
|
||||||
LastKey: p.current(),
|
LastKey: p.current(),
|
||||||
})
|
})
|
||||||
@ -121,10 +123,11 @@ func (p *parser) next() item {
|
|||||||
if it.typ == itemError {
|
if it.typ == itemError {
|
||||||
if it.err != nil {
|
if it.err != nil {
|
||||||
panic(ParseError{
|
panic(ParseError{
|
||||||
Position: it.pos,
|
Message: it.err.Error(),
|
||||||
|
err: it.err,
|
||||||
|
Position: it.pos.withCol(p.lx.input),
|
||||||
Line: it.pos.Line,
|
Line: it.pos.Line,
|
||||||
LastKey: p.current(),
|
LastKey: p.current(),
|
||||||
err: it.err,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +142,7 @@ func (p *parser) nextPos() item {
|
|||||||
return it
|
return it
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) bug(format string, v ...interface{}) {
|
func (p *parser) bug(format string, v ...any) {
|
||||||
panic(fmt.Sprintf("BUG: "+format+"\n\n", v...))
|
panic(fmt.Sprintf("BUG: "+format+"\n\n", v...))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,11 +197,11 @@ func (p *parser) topLevel(item item) {
|
|||||||
p.assertEqual(itemKeyEnd, k.typ)
|
p.assertEqual(itemKeyEnd, k.typ)
|
||||||
|
|
||||||
/// The current key is the last part.
|
/// The current key is the last part.
|
||||||
p.currentKey = key[len(key)-1]
|
p.currentKey = key.last()
|
||||||
|
|
||||||
/// All the other parts (if any) are the context; need to set each part
|
/// All the other parts (if any) are the context; need to set each part
|
||||||
/// as implicit.
|
/// as implicit.
|
||||||
context := key[:len(key)-1]
|
context := key.parent()
|
||||||
for i := range context {
|
for i := range context {
|
||||||
p.addImplicitContext(append(p.context, context[i:i+1]...))
|
p.addImplicitContext(append(p.context, context[i:i+1]...))
|
||||||
}
|
}
|
||||||
@ -207,7 +210,8 @@ func (p *parser) topLevel(item item) {
|
|||||||
/// Set value.
|
/// Set value.
|
||||||
vItem := p.next()
|
vItem := p.next()
|
||||||
val, typ := p.value(vItem, false)
|
val, typ := p.value(vItem, false)
|
||||||
p.set(p.currentKey, val, typ, vItem.pos)
|
p.setValue(p.currentKey, val)
|
||||||
|
p.setType(p.currentKey, typ, vItem.pos)
|
||||||
|
|
||||||
/// Remove the context we added (preserving any context from [tbl] lines).
|
/// Remove the context we added (preserving any context from [tbl] lines).
|
||||||
p.context = outerContext
|
p.context = outerContext
|
||||||
@ -222,7 +226,7 @@ func (p *parser) keyString(it item) string {
|
|||||||
switch it.typ {
|
switch it.typ {
|
||||||
case itemText:
|
case itemText:
|
||||||
return it.val
|
return it.val
|
||||||
case itemString, itemMultilineString,
|
case itemString, itemStringEsc, itemMultilineString,
|
||||||
itemRawString, itemRawMultilineString:
|
itemRawString, itemRawMultilineString:
|
||||||
s, _ := p.value(it, false)
|
s, _ := p.value(it, false)
|
||||||
return s.(string)
|
return s.(string)
|
||||||
@ -239,9 +243,11 @@ var datetimeRepl = strings.NewReplacer(
|
|||||||
|
|
||||||
// value translates an expected value from the lexer into a Go value wrapped
|
// value translates an expected value from the lexer into a Go value wrapped
|
||||||
// as an empty interface.
|
// as an empty interface.
|
||||||
func (p *parser) value(it item, parentIsArray bool) (interface{}, tomlType) {
|
func (p *parser) value(it item, parentIsArray bool) (any, tomlType) {
|
||||||
switch it.typ {
|
switch it.typ {
|
||||||
case itemString:
|
case itemString:
|
||||||
|
return it.val, p.typeOfPrimitive(it)
|
||||||
|
case itemStringEsc:
|
||||||
return p.replaceEscapes(it, it.val), p.typeOfPrimitive(it)
|
return p.replaceEscapes(it, it.val), p.typeOfPrimitive(it)
|
||||||
case itemMultilineString:
|
case itemMultilineString:
|
||||||
return p.replaceEscapes(it, p.stripEscapedNewlines(stripFirstNewline(it.val))), p.typeOfPrimitive(it)
|
return p.replaceEscapes(it, p.stripEscapedNewlines(stripFirstNewline(it.val))), p.typeOfPrimitive(it)
|
||||||
@ -274,7 +280,7 @@ func (p *parser) value(it item, parentIsArray bool) (interface{}, tomlType) {
|
|||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) valueInteger(it item) (interface{}, tomlType) {
|
func (p *parser) valueInteger(it item) (any, tomlType) {
|
||||||
if !numUnderscoresOK(it.val) {
|
if !numUnderscoresOK(it.val) {
|
||||||
p.panicItemf(it, "Invalid integer %q: underscores must be surrounded by digits", it.val)
|
p.panicItemf(it, "Invalid integer %q: underscores must be surrounded by digits", it.val)
|
||||||
}
|
}
|
||||||
@ -298,7 +304,7 @@ func (p *parser) valueInteger(it item) (interface{}, tomlType) {
|
|||||||
return num, p.typeOfPrimitive(it)
|
return num, p.typeOfPrimitive(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) valueFloat(it item) (interface{}, tomlType) {
|
func (p *parser) valueFloat(it item) (any, tomlType) {
|
||||||
parts := strings.FieldsFunc(it.val, func(r rune) bool {
|
parts := strings.FieldsFunc(it.val, func(r rune) bool {
|
||||||
switch r {
|
switch r {
|
||||||
case '.', 'e', 'E':
|
case '.', 'e', 'E':
|
||||||
@ -322,7 +328,9 @@ func (p *parser) valueFloat(it item) (interface{}, tomlType) {
|
|||||||
p.panicItemf(it, "Invalid float %q: '.' must be followed by one or more digits", it.val)
|
p.panicItemf(it, "Invalid float %q: '.' must be followed by one or more digits", it.val)
|
||||||
}
|
}
|
||||||
val := strings.Replace(it.val, "_", "", -1)
|
val := strings.Replace(it.val, "_", "", -1)
|
||||||
if val == "+nan" || val == "-nan" { // Go doesn't support this, but TOML spec does.
|
signbit := false
|
||||||
|
if val == "+nan" || val == "-nan" {
|
||||||
|
signbit = val == "-nan"
|
||||||
val = "nan"
|
val = "nan"
|
||||||
}
|
}
|
||||||
num, err := strconv.ParseFloat(val, 64)
|
num, err := strconv.ParseFloat(val, 64)
|
||||||
@ -333,6 +341,9 @@ func (p *parser) valueFloat(it item) (interface{}, tomlType) {
|
|||||||
p.panicItemf(it, "Invalid float value: %q", it.val)
|
p.panicItemf(it, "Invalid float value: %q", it.val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if signbit {
|
||||||
|
num = math.Copysign(num, -1)
|
||||||
|
}
|
||||||
return num, p.typeOfPrimitive(it)
|
return num, p.typeOfPrimitive(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,7 +363,7 @@ var dtTypes = []struct {
|
|||||||
{"15:04", internal.LocalTime, true},
|
{"15:04", internal.LocalTime, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) valueDatetime(it item) (interface{}, tomlType) {
|
func (p *parser) valueDatetime(it item) (any, tomlType) {
|
||||||
it.val = datetimeRepl.Replace(it.val)
|
it.val = datetimeRepl.Replace(it.val)
|
||||||
var (
|
var (
|
||||||
t time.Time
|
t time.Time
|
||||||
@ -365,26 +376,44 @@ func (p *parser) valueDatetime(it item) (interface{}, tomlType) {
|
|||||||
}
|
}
|
||||||
t, err = time.ParseInLocation(dt.fmt, it.val, dt.zone)
|
t, err = time.ParseInLocation(dt.fmt, it.val, dt.zone)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
if missingLeadingZero(it.val, dt.fmt) {
|
||||||
|
p.panicErr(it, errParseDate{it.val})
|
||||||
|
}
|
||||||
ok = true
|
ok = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
p.panicItemf(it, "Invalid TOML Datetime: %q.", it.val)
|
p.panicErr(it, errParseDate{it.val})
|
||||||
}
|
}
|
||||||
return t, p.typeOfPrimitive(it)
|
return t, p.typeOfPrimitive(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) valueArray(it item) (interface{}, tomlType) {
|
// Go's time.Parse() will accept numbers without a leading zero; there isn't any
|
||||||
|
// way to require it. https://github.com/golang/go/issues/29911
|
||||||
|
//
|
||||||
|
// Depend on the fact that the separators (- and :) should always be at the same
|
||||||
|
// location.
|
||||||
|
func missingLeadingZero(d, l string) bool {
|
||||||
|
for i, c := range []byte(l) {
|
||||||
|
if c == '.' || c == 'Z' {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (c < '0' || c > '9') && d[i] != c {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *parser) valueArray(it item) (any, tomlType) {
|
||||||
p.setType(p.currentKey, tomlArray, it.pos)
|
p.setType(p.currentKey, tomlArray, it.pos)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
types []tomlType
|
// Initialize to a non-nil slice to make it consistent with how S = []
|
||||||
|
// decodes into a non-nil slice inside something like struct { S
|
||||||
// Initialize to a non-nil empty slice. This makes it consistent with
|
// []string }. See #338
|
||||||
// how S = [] decodes into a non-nil slice inside something like struct
|
array = make([]any, 0, 2)
|
||||||
// { S []string }. See #338
|
|
||||||
array = []interface{}{}
|
|
||||||
)
|
)
|
||||||
for it = p.next(); it.typ != itemArrayEnd; it = p.next() {
|
for it = p.next(); it.typ != itemArrayEnd; it = p.next() {
|
||||||
if it.typ == itemCommentStart {
|
if it.typ == itemCommentStart {
|
||||||
@ -394,21 +423,20 @@ func (p *parser) valueArray(it item) (interface{}, tomlType) {
|
|||||||
|
|
||||||
val, typ := p.value(it, true)
|
val, typ := p.value(it, true)
|
||||||
array = append(array, val)
|
array = append(array, val)
|
||||||
types = append(types, typ)
|
|
||||||
|
|
||||||
// XXX: types isn't used here, we need it to record the accurate type
|
// XXX: type isn't used here, we need it to record the accurate type
|
||||||
// information.
|
// information.
|
||||||
//
|
//
|
||||||
// Not entirely sure how to best store this; could use "key[0]",
|
// Not entirely sure how to best store this; could use "key[0]",
|
||||||
// "key[1]" notation, or maybe store it on the Array type?
|
// "key[1]" notation, or maybe store it on the Array type?
|
||||||
_ = types
|
_ = typ
|
||||||
}
|
}
|
||||||
return array, tomlArray
|
return array, tomlArray
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) valueInlineTable(it item, parentIsArray bool) (interface{}, tomlType) {
|
func (p *parser) valueInlineTable(it item, parentIsArray bool) (any, tomlType) {
|
||||||
var (
|
var (
|
||||||
hash = make(map[string]interface{})
|
topHash = make(map[string]any)
|
||||||
outerContext = p.context
|
outerContext = p.context
|
||||||
outerKey = p.currentKey
|
outerKey = p.currentKey
|
||||||
)
|
)
|
||||||
@ -436,11 +464,11 @@ func (p *parser) valueInlineTable(it item, parentIsArray bool) (interface{}, tom
|
|||||||
p.assertEqual(itemKeyEnd, k.typ)
|
p.assertEqual(itemKeyEnd, k.typ)
|
||||||
|
|
||||||
/// The current key is the last part.
|
/// The current key is the last part.
|
||||||
p.currentKey = key[len(key)-1]
|
p.currentKey = key.last()
|
||||||
|
|
||||||
/// All the other parts (if any) are the context; need to set each part
|
/// All the other parts (if any) are the context; need to set each part
|
||||||
/// as implicit.
|
/// as implicit.
|
||||||
context := key[:len(key)-1]
|
context := key.parent()
|
||||||
for i := range context {
|
for i := range context {
|
||||||
p.addImplicitContext(append(p.context, context[i:i+1]...))
|
p.addImplicitContext(append(p.context, context[i:i+1]...))
|
||||||
}
|
}
|
||||||
@ -448,7 +476,21 @@ func (p *parser) valueInlineTable(it item, parentIsArray bool) (interface{}, tom
|
|||||||
|
|
||||||
/// Set the value.
|
/// Set the value.
|
||||||
val, typ := p.value(p.next(), false)
|
val, typ := p.value(p.next(), false)
|
||||||
p.set(p.currentKey, val, typ, it.pos)
|
p.setValue(p.currentKey, val)
|
||||||
|
p.setType(p.currentKey, typ, it.pos)
|
||||||
|
|
||||||
|
hash := topHash
|
||||||
|
for _, c := range context {
|
||||||
|
h, ok := hash[c]
|
||||||
|
if !ok {
|
||||||
|
h = make(map[string]any)
|
||||||
|
hash[c] = h
|
||||||
|
}
|
||||||
|
hash, ok = h.(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
p.panicf("%q is not a table", p.context)
|
||||||
|
}
|
||||||
|
}
|
||||||
hash[p.currentKey] = val
|
hash[p.currentKey] = val
|
||||||
|
|
||||||
/// Restore context.
|
/// Restore context.
|
||||||
@ -456,7 +498,7 @@ func (p *parser) valueInlineTable(it item, parentIsArray bool) (interface{}, tom
|
|||||||
}
|
}
|
||||||
p.context = outerContext
|
p.context = outerContext
|
||||||
p.currentKey = outerKey
|
p.currentKey = outerKey
|
||||||
return hash, tomlHash
|
return topHash, tomlHash
|
||||||
}
|
}
|
||||||
|
|
||||||
// numHasLeadingZero checks if this number has leading zeroes, allowing for '0',
|
// numHasLeadingZero checks if this number has leading zeroes, allowing for '0',
|
||||||
@ -486,9 +528,9 @@ func numUnderscoresOK(s string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// isHexadecimal is a superset of all the permissable characters
|
// isHex is a superset of all the permissible characters surrounding an
|
||||||
// surrounding an underscore.
|
// underscore.
|
||||||
accept = isHexadecimal(r)
|
accept = isHex(r)
|
||||||
}
|
}
|
||||||
return accept
|
return accept
|
||||||
}
|
}
|
||||||
@ -511,21 +553,19 @@ func numPeriodsOK(s string) bool {
|
|||||||
// Establishing the context also makes sure that the key isn't a duplicate, and
|
// Establishing the context also makes sure that the key isn't a duplicate, and
|
||||||
// will create implicit hashes automatically.
|
// will create implicit hashes automatically.
|
||||||
func (p *parser) addContext(key Key, array bool) {
|
func (p *parser) addContext(key Key, array bool) {
|
||||||
var ok bool
|
/// Always start at the top level and drill down for our context.
|
||||||
|
|
||||||
// Always start at the top level and drill down for our context.
|
|
||||||
hashContext := p.mapping
|
hashContext := p.mapping
|
||||||
keyContext := make(Key, 0)
|
keyContext := make(Key, 0, len(key)-1)
|
||||||
|
|
||||||
// We only need implicit hashes for key[0:-1]
|
/// We only need implicit hashes for the parents.
|
||||||
for _, k := range key[0 : len(key)-1] {
|
for _, k := range key.parent() {
|
||||||
_, ok = hashContext[k]
|
_, ok := hashContext[k]
|
||||||
keyContext = append(keyContext, k)
|
keyContext = append(keyContext, k)
|
||||||
|
|
||||||
// No key? Make an implicit hash and move on.
|
// No key? Make an implicit hash and move on.
|
||||||
if !ok {
|
if !ok {
|
||||||
p.addImplicit(keyContext)
|
p.addImplicit(keyContext)
|
||||||
hashContext[k] = make(map[string]interface{})
|
hashContext[k] = make(map[string]any)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the hash context is actually an array of tables, then set
|
// If the hash context is actually an array of tables, then set
|
||||||
@ -534,9 +574,9 @@ func (p *parser) addContext(key Key, array bool) {
|
|||||||
// Otherwise, it better be a table, since this MUST be a key group (by
|
// Otherwise, it better be a table, since this MUST be a key group (by
|
||||||
// virtue of it not being the last element in a key).
|
// virtue of it not being the last element in a key).
|
||||||
switch t := hashContext[k].(type) {
|
switch t := hashContext[k].(type) {
|
||||||
case []map[string]interface{}:
|
case []map[string]any:
|
||||||
hashContext = t[len(t)-1]
|
hashContext = t[len(t)-1]
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
hashContext = t
|
hashContext = t
|
||||||
default:
|
default:
|
||||||
p.panicf("Key '%s' was already created as a hash.", keyContext)
|
p.panicf("Key '%s' was already created as a hash.", keyContext)
|
||||||
@ -547,39 +587,33 @@ func (p *parser) addContext(key Key, array bool) {
|
|||||||
if array {
|
if array {
|
||||||
// If this is the first element for this array, then allocate a new
|
// If this is the first element for this array, then allocate a new
|
||||||
// list of tables for it.
|
// list of tables for it.
|
||||||
k := key[len(key)-1]
|
k := key.last()
|
||||||
if _, ok := hashContext[k]; !ok {
|
if _, ok := hashContext[k]; !ok {
|
||||||
hashContext[k] = make([]map[string]interface{}, 0, 4)
|
hashContext[k] = make([]map[string]any, 0, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a new table. But make sure the key hasn't already been used
|
// Add a new table. But make sure the key hasn't already been used
|
||||||
// for something else.
|
// for something else.
|
||||||
if hash, ok := hashContext[k].([]map[string]interface{}); ok {
|
if hash, ok := hashContext[k].([]map[string]any); ok {
|
||||||
hashContext[k] = append(hash, make(map[string]interface{}))
|
hashContext[k] = append(hash, make(map[string]any))
|
||||||
} else {
|
} else {
|
||||||
p.panicf("Key '%s' was already created and cannot be used as an array.", key)
|
p.panicf("Key '%s' was already created and cannot be used as an array.", key)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p.setValue(key[len(key)-1], make(map[string]interface{}))
|
p.setValue(key.last(), make(map[string]any))
|
||||||
}
|
}
|
||||||
p.context = append(p.context, key[len(key)-1])
|
p.context = append(p.context, key.last())
|
||||||
}
|
|
||||||
|
|
||||||
// set calls setValue and setType.
|
|
||||||
func (p *parser) set(key string, val interface{}, typ tomlType, pos Position) {
|
|
||||||
p.setValue(key, val)
|
|
||||||
p.setType(key, typ, pos)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setValue sets the given key to the given value in the current context.
|
// setValue sets the given key to the given value in the current context.
|
||||||
// It will make sure that the key hasn't already been defined, account for
|
// It will make sure that the key hasn't already been defined, account for
|
||||||
// implicit key groups.
|
// implicit key groups.
|
||||||
func (p *parser) setValue(key string, value interface{}) {
|
func (p *parser) setValue(key string, value any) {
|
||||||
var (
|
var (
|
||||||
tmpHash interface{}
|
tmpHash any
|
||||||
ok bool
|
ok bool
|
||||||
hash = p.mapping
|
hash = p.mapping
|
||||||
keyContext Key
|
keyContext = make(Key, 0, len(p.context)+1)
|
||||||
)
|
)
|
||||||
for _, k := range p.context {
|
for _, k := range p.context {
|
||||||
keyContext = append(keyContext, k)
|
keyContext = append(keyContext, k)
|
||||||
@ -587,11 +621,11 @@ func (p *parser) setValue(key string, value interface{}) {
|
|||||||
p.bug("Context for key '%s' has not been established.", keyContext)
|
p.bug("Context for key '%s' has not been established.", keyContext)
|
||||||
}
|
}
|
||||||
switch t := tmpHash.(type) {
|
switch t := tmpHash.(type) {
|
||||||
case []map[string]interface{}:
|
case []map[string]any:
|
||||||
// The context is a table of hashes. Pick the most recent table
|
// The context is a table of hashes. Pick the most recent table
|
||||||
// defined as the current hash.
|
// defined as the current hash.
|
||||||
hash = t[len(t)-1]
|
hash = t[len(t)-1]
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
hash = t
|
hash = t
|
||||||
default:
|
default:
|
||||||
p.panicf("Key '%s' has already been defined.", keyContext)
|
p.panicf("Key '%s' has already been defined.", keyContext)
|
||||||
@ -618,9 +652,8 @@ func (p *parser) setValue(key string, value interface{}) {
|
|||||||
p.removeImplicit(keyContext)
|
p.removeImplicit(keyContext)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Otherwise, we have a concrete key trying to override a previous key,
|
||||||
// Otherwise, we have a concrete key trying to override a previous
|
// which is *always* wrong.
|
||||||
// key, which is *always* wrong.
|
|
||||||
p.panicf("Key '%s' has already been defined.", keyContext)
|
p.panicf("Key '%s' has already been defined.", keyContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -683,8 +716,11 @@ func stripFirstNewline(s string) string {
|
|||||||
// the next newline. After a line-ending backslash, all whitespace is removed
|
// the next newline. After a line-ending backslash, all whitespace is removed
|
||||||
// until the next non-whitespace character.
|
// until the next non-whitespace character.
|
||||||
func (p *parser) stripEscapedNewlines(s string) string {
|
func (p *parser) stripEscapedNewlines(s string) string {
|
||||||
var b strings.Builder
|
var (
|
||||||
var i int
|
b strings.Builder
|
||||||
|
i int
|
||||||
|
)
|
||||||
|
b.Grow(len(s))
|
||||||
for {
|
for {
|
||||||
ix := strings.Index(s[i:], `\`)
|
ix := strings.Index(s[i:], `\`)
|
||||||
if ix < 0 {
|
if ix < 0 {
|
||||||
@ -714,9 +750,8 @@ func (p *parser) stripEscapedNewlines(s string) string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !strings.Contains(s[i:j], "\n") {
|
if !strings.Contains(s[i:j], "\n") {
|
||||||
// This is not a line-ending backslash.
|
// This is not a line-ending backslash. (It's a bad escape sequence,
|
||||||
// (It's a bad escape sequence, but we can let
|
// but we can let replaceEscapes catch it.)
|
||||||
// replaceEscapes catch it.)
|
|
||||||
i++
|
i++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -727,79 +762,78 @@ func (p *parser) stripEscapedNewlines(s string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) replaceEscapes(it item, str string) string {
|
func (p *parser) replaceEscapes(it item, str string) string {
|
||||||
replaced := make([]rune, 0, len(str))
|
var (
|
||||||
s := []byte(str)
|
b strings.Builder
|
||||||
r := 0
|
skip = 0
|
||||||
for r < len(s) {
|
)
|
||||||
if s[r] != '\\' {
|
b.Grow(len(str))
|
||||||
c, size := utf8.DecodeRune(s[r:])
|
for i, c := range str {
|
||||||
r += size
|
if skip > 0 {
|
||||||
replaced = append(replaced, c)
|
skip--
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
r += 1
|
if c != '\\' {
|
||||||
if r >= len(s) {
|
b.WriteRune(c)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if i >= len(str) {
|
||||||
p.bug("Escape sequence at end of string.")
|
p.bug("Escape sequence at end of string.")
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
switch s[r] {
|
switch str[i+1] {
|
||||||
default:
|
default:
|
||||||
p.bug("Expected valid escape code after \\, but got %q.", s[r])
|
p.bug("Expected valid escape code after \\, but got %q.", str[i+1])
|
||||||
case ' ', '\t':
|
case ' ', '\t':
|
||||||
p.panicItemf(it, "invalid escape: '\\%c'", s[r])
|
p.panicItemf(it, "invalid escape: '\\%c'", str[i+1])
|
||||||
case 'b':
|
case 'b':
|
||||||
replaced = append(replaced, rune(0x0008))
|
b.WriteByte(0x08)
|
||||||
r += 1
|
skip = 1
|
||||||
case 't':
|
case 't':
|
||||||
replaced = append(replaced, rune(0x0009))
|
b.WriteByte(0x09)
|
||||||
r += 1
|
skip = 1
|
||||||
case 'n':
|
case 'n':
|
||||||
replaced = append(replaced, rune(0x000A))
|
b.WriteByte(0x0a)
|
||||||
r += 1
|
skip = 1
|
||||||
case 'f':
|
case 'f':
|
||||||
replaced = append(replaced, rune(0x000C))
|
b.WriteByte(0x0c)
|
||||||
r += 1
|
skip = 1
|
||||||
case 'r':
|
case 'r':
|
||||||
replaced = append(replaced, rune(0x000D))
|
b.WriteByte(0x0d)
|
||||||
r += 1
|
skip = 1
|
||||||
case 'e':
|
case 'e':
|
||||||
if p.tomlNext {
|
if p.tomlNext {
|
||||||
replaced = append(replaced, rune(0x001B))
|
b.WriteByte(0x1b)
|
||||||
r += 1
|
skip = 1
|
||||||
}
|
}
|
||||||
case '"':
|
case '"':
|
||||||
replaced = append(replaced, rune(0x0022))
|
b.WriteByte(0x22)
|
||||||
r += 1
|
skip = 1
|
||||||
case '\\':
|
case '\\':
|
||||||
replaced = append(replaced, rune(0x005C))
|
b.WriteByte(0x5c)
|
||||||
r += 1
|
skip = 1
|
||||||
|
// The lexer guarantees the correct number of characters are present;
|
||||||
|
// don't need to check here.
|
||||||
case 'x':
|
case 'x':
|
||||||
if p.tomlNext {
|
if p.tomlNext {
|
||||||
escaped := p.asciiEscapeToUnicode(it, s[r+1:r+3])
|
escaped := p.asciiEscapeToUnicode(it, str[i+2:i+4])
|
||||||
replaced = append(replaced, escaped)
|
b.WriteRune(escaped)
|
||||||
r += 3
|
skip = 3
|
||||||
}
|
}
|
||||||
case 'u':
|
case 'u':
|
||||||
// At this point, we know we have a Unicode escape of the form
|
escaped := p.asciiEscapeToUnicode(it, str[i+2:i+6])
|
||||||
// `uXXXX` at [r, r+5). (Because the lexer guarantees this
|
b.WriteRune(escaped)
|
||||||
// for us.)
|
skip = 5
|
||||||
escaped := p.asciiEscapeToUnicode(it, s[r+1:r+5])
|
|
||||||
replaced = append(replaced, escaped)
|
|
||||||
r += 5
|
|
||||||
case 'U':
|
case 'U':
|
||||||
// At this point, we know we have a Unicode escape of the form
|
escaped := p.asciiEscapeToUnicode(it, str[i+2:i+10])
|
||||||
// `uXXXX` at [r, r+9). (Because the lexer guarantees this
|
b.WriteRune(escaped)
|
||||||
// for us.)
|
skip = 9
|
||||||
escaped := p.asciiEscapeToUnicode(it, s[r+1:r+9])
|
|
||||||
replaced = append(replaced, escaped)
|
|
||||||
r += 9
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return string(replaced)
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) asciiEscapeToUnicode(it item, bs []byte) rune {
|
func (p *parser) asciiEscapeToUnicode(it item, s string) rune {
|
||||||
s := string(bs)
|
|
||||||
hex, err := strconv.ParseUint(strings.ToLower(s), 16, 32)
|
hex, err := strconv.ParseUint(strings.ToLower(s), 16, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.bug("Could not parse '%s' as a hexadecimal number, but the lexer claims it's OK: %s", s, err)
|
p.bug("Could not parse '%s' as a hexadecimal number, but the lexer claims it's OK: %s", s, err)
|
||||||
|
8
src/runtime/vendor/github.com/BurntSushi/toml/type_fields.go
generated
vendored
8
src/runtime/vendor/github.com/BurntSushi/toml/type_fields.go
generated
vendored
@ -25,10 +25,8 @@ type field struct {
|
|||||||
// breaking ties with index sequence.
|
// breaking ties with index sequence.
|
||||||
type byName []field
|
type byName []field
|
||||||
|
|
||||||
func (x byName) Len() int { return len(x) }
|
func (x byName) Len() int { return len(x) }
|
||||||
|
|
||||||
func (x byName) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
func (x byName) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
||||||
|
|
||||||
func (x byName) Less(i, j int) bool {
|
func (x byName) Less(i, j int) bool {
|
||||||
if x[i].name != x[j].name {
|
if x[i].name != x[j].name {
|
||||||
return x[i].name < x[j].name
|
return x[i].name < x[j].name
|
||||||
@ -45,10 +43,8 @@ func (x byName) Less(i, j int) bool {
|
|||||||
// byIndex sorts field by index sequence.
|
// byIndex sorts field by index sequence.
|
||||||
type byIndex []field
|
type byIndex []field
|
||||||
|
|
||||||
func (x byIndex) Len() int { return len(x) }
|
func (x byIndex) Len() int { return len(x) }
|
||||||
|
|
||||||
func (x byIndex) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
func (x byIndex) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
||||||
|
|
||||||
func (x byIndex) Less(i, j int) bool {
|
func (x byIndex) Less(i, j int) bool {
|
||||||
for k, xik := range x[i].index {
|
for k, xik := range x[i].index {
|
||||||
if k >= len(x[j].index) {
|
if k >= len(x[j].index) {
|
||||||
|
11
src/runtime/vendor/github.com/BurntSushi/toml/type_toml.go
generated
vendored
11
src/runtime/vendor/github.com/BurntSushi/toml/type_toml.go
generated
vendored
@ -22,13 +22,8 @@ func typeIsTable(t tomlType) bool {
|
|||||||
|
|
||||||
type tomlBaseType string
|
type tomlBaseType string
|
||||||
|
|
||||||
func (btype tomlBaseType) typeString() string {
|
func (btype tomlBaseType) typeString() string { return string(btype) }
|
||||||
return string(btype)
|
func (btype tomlBaseType) String() string { return btype.typeString() }
|
||||||
}
|
|
||||||
|
|
||||||
func (btype tomlBaseType) String() string {
|
|
||||||
return btype.typeString()
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tomlInteger tomlBaseType = "Integer"
|
tomlInteger tomlBaseType = "Integer"
|
||||||
@ -54,7 +49,7 @@ func (p *parser) typeOfPrimitive(lexItem item) tomlType {
|
|||||||
return tomlFloat
|
return tomlFloat
|
||||||
case itemDatetime:
|
case itemDatetime:
|
||||||
return tomlDatetime
|
return tomlDatetime
|
||||||
case itemString:
|
case itemString, itemStringEsc:
|
||||||
return tomlString
|
return tomlString
|
||||||
case itemMultilineString:
|
case itemMultilineString:
|
||||||
return tomlString
|
return tomlString
|
||||||
|
4
src/runtime/vendor/modules.txt
vendored
4
src/runtime/vendor/modules.txt
vendored
@ -7,8 +7,8 @@ github.com/AdaLogics/go-fuzz-headers
|
|||||||
# github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0
|
# github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
github.com/AdamKorcz/go-118-fuzz-build/testing
|
github.com/AdamKorcz/go-118-fuzz-build/testing
|
||||||
# github.com/BurntSushi/toml v1.3.2
|
# github.com/BurntSushi/toml v1.5.0
|
||||||
## explicit; go 1.16
|
## explicit; go 1.18
|
||||||
github.com/BurntSushi/toml
|
github.com/BurntSushi/toml
|
||||||
github.com/BurntSushi/toml/internal
|
github.com/BurntSushi/toml/internal
|
||||||
# github.com/Microsoft/go-winio v0.6.2
|
# github.com/Microsoft/go-winio v0.6.2
|
||||||
|
Loading…
Reference in New Issue
Block a user