Fix unparsing of enums, avoid static type error

This commit is contained in:
Dave Cunningham 2017-11-08 11:27:10 -05:00
parent aeda6138e5
commit b04e73e163
6 changed files with 35181 additions and 34340 deletions

View File

@ -45,3 +45,11 @@ go get github.com/clipperhouse/set
export PATH=$PATH:$GOPATH/bin # If you haven't already
go generate
```
## Generated Stdlib
To regenerate the standard library, do:
```
./reset_stdast_go.sh && go run cmd/dumpstdlibast.go
```

File diff suppressed because it is too large Load Diff

View File

@ -188,26 +188,26 @@ func (s *dumpState) printPrimitivePointer(value reflect.Value, pointerName strin
printBool(s.w, v.Bool())
case reflect.Int:
printInt(s.w, v.Int(), 10, "int")
printInt(s.w, v)
case reflect.Int8:
printInt(s.w, v.Int(), 10, "int8")
printInt(s.w, v)
case reflect.Int16:
printInt(s.w, v.Int(), 10, "int16")
printInt(s.w, v)
case reflect.Int32:
printInt(s.w, v.Int(), 10, "int32")
printInt(s.w, v)
case reflect.Int64:
printInt(s.w, v.Int(), 10, "int64")
printInt(s.w, v)
case reflect.Uint:
printUint(s.w, v.Uint(), 10, "uint")
printUint(s.w, v)
case reflect.Uint8:
printUint(s.w, v.Uint(), 10, "uint8")
printUint(s.w, v)
case reflect.Uint16:
printUint(s.w, v.Uint(), 10, "uint16")
printUint(s.w, v)
case reflect.Uint32:
printUint(s.w, v.Uint(), 10, "uint32")
printUint(s.w, v)
case reflect.Uint64:
printUint(s.w, v.Uint(), 10, "uint64")
printUint(s.w, v)
case reflect.Float32:
printFloat(s.w, v.Float(), 32, "float32")
@ -341,26 +341,26 @@ func (s *dumpState) dumpVal(value reflect.Value) {
printBool(s.w, v.Bool())
case reflect.Int:
printInt(s.w, v.Int(), 10, "int")
printInt(s.w, v)
case reflect.Int8:
printInt(s.w, v.Int(), 10, "int8")
printInt(s.w, v)
case reflect.Int16:
printInt(s.w, v.Int(), 10, "int16")
printInt(s.w, v)
case reflect.Int32:
printInt(s.w, v.Int(), 10, "int32")
printInt(s.w, v)
case reflect.Int64:
printInt(s.w, v.Int(), 10, "int64")
printInt(s.w, v)
case reflect.Uint:
printUint(s.w, v.Uint(), 10, "uint")
printUint(s.w, v)
case reflect.Uint8:
printUint(s.w, v.Uint(), 10, "uint8")
printUint(s.w, v)
case reflect.Uint16:
printUint(s.w, v.Uint(), 10, "uint16")
printUint(s.w, v)
case reflect.Uint32:
printUint(s.w, v.Uint(), 10, "uint32")
printUint(s.w, v)
case reflect.Uint64:
printUint(s.w, v.Uint(), 10, "uint64")
printUint(s.w, v)
case reflect.Float32:
printFloat(s.w, v.Float(), 32, "float32")

View File

@ -21,18 +21,24 @@ import (
"io"
"reflect"
"strconv"
"strings"
)
func printBool(w io.Writer, value bool) {
w.Write([]byte(strconv.FormatBool(value)))
}
func printInt(w io.Writer, val int64, base int, intType string) {
w.Write([]byte(fmt.Sprintf("%s(%s)", intType, strconv.FormatInt(val, base))))
func printInt(w io.Writer, val reflect.Value) {
typeName := fmt.Sprintf("%s", val.Type())
if strings.HasPrefix(typeName, "ast.") {
typeName = typeName[4:]
}
w.Write([]byte(fmt.Sprintf("%s(%s)", typeName, strconv.FormatInt(val.Int(), 10))))
}
func printUint(w io.Writer, val uint64, base int, uintType string) {
w.Write([]byte(fmt.Sprintf("%s(%s)", uintType, strconv.FormatUint(val, base))))
func printUint(w io.Writer, val reflect.Value) {
typeName := fmt.Sprintf("%s", val.Type())
w.Write([]byte(fmt.Sprintf("%s(%s)", typeName, strconv.FormatUint(val.Uint(), 10))))
}
func printFloat(w io.Writer, val float64, precision int, floatType string) {

5
reset_stdast_go.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
echo 'package ast' > ast/stdast.go
echo 'var StdAst = &LiteralNull{}' >> ast/stdast.go

2
std.go
View File

@ -193,7 +193,7 @@ var _escData = map[string]*_escFile{
"/std/std.jsonnet": {
local: "std/std.jsonnet",
size: 42048,
modtime: 1509684595,
modtime: 1509761227,
compressed: `
H4sIAAAJbogC/+w9f3PbNrL/61MgfHUr1bRsy47bOHFn0iS9812b9Jr0en2KRkNRlESbIlWSsuXm8t3f
7gL8ARIAKTl5vXTO08tJIrC72F3sLhYL8PDLzrNodRf780XKBkfHD9lfomgeeOwydPvsaRAwepSw2Eu8