mirror of
https://github.com/google/go-jsonnet.git
synced 2025-09-29 17:31:02 +02:00
Add std. manifestJsonMinified (#492)
Pick up std changes in cpp and update builtinManifestJSONEx
This commit is contained in:
parent
4beab6633f
commit
7d3bda3911
32332
astgen/stdast.go
32332
astgen/stdast.go
File diff suppressed because it is too large
Load Diff
39
builtins.go
39
builtins.go
@ -1211,13 +1211,30 @@ func jsonEncode(v interface{}) (string, error) {
|
|||||||
// These should ideally be unified
|
// These should ideally be unified
|
||||||
// For backwards compatibility reasons, we are manually marshalling to json so we can control formatting
|
// For backwards compatibility reasons, we are manually marshalling to json so we can control formatting
|
||||||
// In the future, it might be apt to use a library [pretty-printing] function
|
// In the future, it might be apt to use a library [pretty-printing] function
|
||||||
func builtinManifestJSONEx(i *interpreter, obj, indent value) (value, error) {
|
func builtinManifestJSONEx(i *interpreter, arguments []value) (value, error) {
|
||||||
vindent, err := i.getString(indent)
|
obj, err := i.getObject(arguments[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
vindent, err := i.getString(arguments[1])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
vnewline, err := i.getString(arguments[2])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
vkvSep, err := i.getString(arguments[3])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sindent := vindent.getGoString()
|
sindent := vindent.getGoString()
|
||||||
|
newline := vnewline.getGoString()
|
||||||
|
kvSep := vkvSep.getGoString()
|
||||||
|
|
||||||
var path []string
|
var path []string
|
||||||
|
|
||||||
@ -1245,7 +1262,7 @@ func builtinManifestJSONEx(i *interpreter, obj, indent value) (value, error) {
|
|||||||
return "", i.Error(fmt.Sprintf("tried to manifest function at %s", path))
|
return "", i.Error(fmt.Sprintf("tried to manifest function at %s", path))
|
||||||
case *valueArray:
|
case *valueArray:
|
||||||
newIndent := cindent + sindent
|
newIndent := cindent + sindent
|
||||||
lines := []string{"[\n"}
|
lines := []string{"[" + newline}
|
||||||
|
|
||||||
var arrayLines []string
|
var arrayLines []string
|
||||||
for aI, cThunk := range v.elements {
|
for aI, cThunk := range v.elements {
|
||||||
@ -1261,12 +1278,12 @@ func builtinManifestJSONEx(i *interpreter, obj, indent value) (value, error) {
|
|||||||
}
|
}
|
||||||
arrayLines = append(arrayLines, newIndent+s)
|
arrayLines = append(arrayLines, newIndent+s)
|
||||||
}
|
}
|
||||||
lines = append(lines, strings.Join(arrayLines, ",\n"))
|
lines = append(lines, strings.Join(arrayLines, ","+newline))
|
||||||
lines = append(lines, "\n"+cindent+"]")
|
lines = append(lines, newline+cindent+"]")
|
||||||
return strings.Join(lines, ""), nil
|
return strings.Join(lines, ""), nil
|
||||||
case *valueObject:
|
case *valueObject:
|
||||||
newIndent := cindent + sindent
|
newIndent := cindent + sindent
|
||||||
lines := []string{"{\n"}
|
lines := []string{"{" + newline}
|
||||||
|
|
||||||
fields := objectFields(v, withoutHidden)
|
fields := objectFields(v, withoutHidden)
|
||||||
sort.Strings(fields)
|
sort.Strings(fields)
|
||||||
@ -1288,11 +1305,11 @@ func builtinManifestJSONEx(i *interpreter, obj, indent value) (value, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
line := newIndent + string(fieldNameMarshalled) + ": " + mvs
|
line := newIndent + string(fieldNameMarshalled) + kvSep + mvs
|
||||||
objectLines = append(objectLines, line)
|
objectLines = append(objectLines, line)
|
||||||
}
|
}
|
||||||
lines = append(lines, strings.Join(objectLines, ",\n"))
|
lines = append(lines, strings.Join(objectLines, ","+newline))
|
||||||
lines = append(lines, "\n"+cindent+"}")
|
lines = append(lines, newline+cindent+"}")
|
||||||
return strings.Join(lines, ""), nil
|
return strings.Join(lines, ""), nil
|
||||||
default:
|
default:
|
||||||
return "", i.Error(fmt.Sprintf("unknown type to marshal to JSON: %s", reflect.TypeOf(v)))
|
return "", i.Error(fmt.Sprintf("unknown type to marshal to JSON: %s", reflect.TypeOf(v)))
|
||||||
@ -1607,7 +1624,9 @@ var funcBuiltins = buildBuiltinMap([]builtin{
|
|||||||
&unaryBuiltin{name: "base64Decode", function: builtinBase64Decode, params: ast.Identifiers{"str"}},
|
&unaryBuiltin{name: "base64Decode", function: builtinBase64Decode, params: ast.Identifiers{"str"}},
|
||||||
&unaryBuiltin{name: "base64DecodeBytes", function: builtinBase64DecodeBytes, params: ast.Identifiers{"str"}},
|
&unaryBuiltin{name: "base64DecodeBytes", function: builtinBase64DecodeBytes, params: ast.Identifiers{"str"}},
|
||||||
&unaryBuiltin{name: "parseJson", function: builtinParseJSON, params: ast.Identifiers{"str"}},
|
&unaryBuiltin{name: "parseJson", function: builtinParseJSON, params: ast.Identifiers{"str"}},
|
||||||
&binaryBuiltin{name: "manifestJsonEx", function: builtinManifestJSONEx, params: ast.Identifiers{"value", "indent"}},
|
&generalBuiltin{name: "manifestJsonEx", function: builtinManifestJSONEx, params: []generalBuiltinParameter{{name: "value"}, {name: "indent"},
|
||||||
|
{name: "newline", defaultValue: &valueFlatString{value: []rune("\n")}},
|
||||||
|
{name: "key_val_sep", defaultValue: &valueFlatString{value: []rune(": ")}}}},
|
||||||
&unaryBuiltin{name: "base64", function: builtinBase64, params: ast.Identifiers{"input"}},
|
&unaryBuiltin{name: "base64", function: builtinBase64, params: ast.Identifiers{"input"}},
|
||||||
&unaryBuiltin{name: "encodeUTF8", function: builtinEncodeUTF8, params: ast.Identifiers{"str"}},
|
&unaryBuiltin{name: "encodeUTF8", function: builtinEncodeUTF8, params: ast.Identifiers{"str"}},
|
||||||
&unaryBuiltin{name: "decodeUTF8", function: builtinDecodeUTF8, params: ast.Identifiers{"arr"}},
|
&unaryBuiltin{name: "decodeUTF8", function: builtinDecodeUTF8, params: ast.Identifiers{"arr"}},
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit ed11b012a4e1487727c595380bff8866d40f2529
|
Subproject commit 89ed89ce1213c6c363e721c81c4387db72f62a29
|
Loading…
x
Reference in New Issue
Block a user