mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-04-28 12:02:03 -04:00
vendor: go get github.com/zclconf/go-cty-yaml@v1.0.2
This commit is contained in:
6
vendor/github.com/zclconf/go-cty-yaml/CHANGELOG.md
generated
vendored
6
vendor/github.com/zclconf/go-cty-yaml/CHANGELOG.md
generated
vendored
@@ -1,3 +1,9 @@
|
||||
# 1.0.2 (June 17, 2020)
|
||||
|
||||
* The YAML decoder now follows the YAML specification more closely when parsing
|
||||
numeric values.
|
||||
([#6](https://github.com/zclconf/go-cty-yaml/pull/6))
|
||||
|
||||
# 1.0.1 (July 30, 2019)
|
||||
|
||||
* The YAML decoder is now correctly treating quoted scalars as verbatim literal
|
||||
|
||||
45
vendor/github.com/zclconf/go-cty-yaml/resolve.go
generated
vendored
45
vendor/github.com/zclconf/go-cty-yaml/resolve.go
generated
vendored
@@ -20,6 +20,25 @@ type resolveMapItem struct {
|
||||
var resolveTable = make([]byte, 256)
|
||||
var resolveMap = make(map[string]resolveMapItem)
|
||||
|
||||
// Numeric literal regular expressions from the YAML 1.2 spec:
|
||||
//
|
||||
// https://yaml.org/spec/1.2/spec.html#id2805071
|
||||
var integerLiteralRegexp = regexp.MustCompile(`` +
|
||||
// start of string, optional sign, and one of:
|
||||
`\A[-+]?(` +
|
||||
// octal literal with 0o prefix and optional _ spaces
|
||||
`|0o[0-7_]+` +
|
||||
// decimal literal and optional _ spaces
|
||||
`|[0-9_]+` +
|
||||
// hexadecimal literal with 0x prefix and optional _ spaces
|
||||
`|0x[0-9a-fA-F_]+` +
|
||||
// end of group, and end of string
|
||||
`)\z`,
|
||||
)
|
||||
var floatLiteralRegexp = regexp.MustCompile(
|
||||
`\A[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?\z`,
|
||||
)
|
||||
|
||||
func init() {
|
||||
t := resolveTable
|
||||
t[int('+')] = 'S' // Sign
|
||||
@@ -140,12 +159,13 @@ func (c *Converter) resolveScalar(tag string, src string, style yaml_scalar_styl
|
||||
}
|
||||
}
|
||||
|
||||
plain := strings.Replace(src, "_", "", -1)
|
||||
if numberVal, err := cty.ParseNumberVal(plain); err == nil {
|
||||
return numberVal, nil
|
||||
}
|
||||
if strings.HasPrefix(plain, "0b") || strings.HasPrefix(plain, "-0b") {
|
||||
if integerLiteralRegexp.MatchString(src) {
|
||||
tag = yaml_INT_TAG // will handle parsing below in our tag switch
|
||||
break
|
||||
}
|
||||
if floatLiteralRegexp.MatchString(src) {
|
||||
tag = yaml_FLOAT_TAG // will handle parsing below in our tag switch
|
||||
break
|
||||
}
|
||||
default:
|
||||
panic(fmt.Sprintf("cannot resolve tag %q with source %q", tag, src))
|
||||
@@ -187,21 +207,6 @@ func (c *Converter) resolveScalar(tag string, src string, style yaml_scalar_styl
|
||||
if uintv, err := strconv.ParseUint(plain, 0, 64); err == nil { // handles 0x and 00 prefixes
|
||||
return cty.NumberUIntVal(uintv), nil
|
||||
}
|
||||
if strings.HasPrefix(plain, "0b") {
|
||||
intv, err := strconv.ParseInt(plain[2:], 2, 64)
|
||||
if err == nil {
|
||||
return cty.NumberIntVal(intv), nil
|
||||
}
|
||||
uintv, err := strconv.ParseUint(plain[2:], 2, 64)
|
||||
if err == nil {
|
||||
return cty.NumberUIntVal(uintv), nil
|
||||
}
|
||||
} else if strings.HasPrefix(plain, "-0b") {
|
||||
intv, err := strconv.ParseInt("-"+plain[3:], 2, 64)
|
||||
if err == nil {
|
||||
return cty.NumberIntVal(intv), nil
|
||||
}
|
||||
}
|
||||
return cty.NilVal, fmt.Errorf("cannot parse %q as %s", src, tag)
|
||||
case yaml_TIMESTAMP_TAG:
|
||||
t, ok := parseTimestamp(src)
|
||||
|
||||
Reference in New Issue
Block a user