MCPcopy
hub / github.com/google/go-jsonnet / unparse

Method unparse

internal/formatter/unparser.go:247–571  ·  view source on GitHub ↗
(expr ast.Node, crowded bool)

Source from the content-addressed store, hash-verified

245}
246
247func (u *unparser) unparse(expr ast.Node, crowded bool) {
248
249 if leftRecursive(expr) == nil {
250 u.fill(*expr.OpenFodder(), crowded, true)
251 }
252
253 switch node := expr.(type) {
254 case *ast.Apply:
255 u.unparse(node.Target, crowded)
256 u.fill(node.FodderLeft, false, false)
257 u.write("(")
258 first := true
259 for _, arg := range node.Arguments.Positional {
260 if !first {
261 u.write(",")
262 }
263 space := !first
264 u.unparse(arg.Expr, space)
265 u.fill(arg.CommaFodder, false, false)
266 first = false
267 }
268 for _, arg := range node.Arguments.Named {
269 if !first {
270 u.write(",")
271 }
272 space := !first
273 u.fill(arg.NameFodder, space, true)
274 u.unparseID(arg.Name)
275 space = false
276 u.write("=")
277 u.unparse(arg.Arg, space)
278 u.fill(arg.CommaFodder, false, false)
279 first = false
280 }
281 if node.TrailingComma {
282 u.write(",")
283 }
284 u.fill(node.FodderRight, false, false)
285 u.write(")")
286 if node.TailStrict {
287 u.fill(node.TailStrictFodder, true, true)
288 u.write("tailstrict")
289 }
290
291 case *ast.ApplyBrace:
292 u.unparse(node.Left, crowded)
293 u.unparse(node.Right, true)
294
295 case *ast.Array:
296 u.write("[")
297 first := true
298 for _, element := range node.Elements {
299 if !first {
300 u.write(",")
301 }
302 u.unparse(element.Expr, !first || u.options.PadArrays)
303 u.fill(element.CommaFodder, false, false)
304 first = false

Callers 4

unparseSpecsMethod · 0.95
unparseParamsMethod · 0.95
unparseFieldsMethod · 0.95
FormatNodeFunction · 0.95

Calls 9

fillMethod · 0.95
writeMethod · 0.95
unparseIDMethod · 0.95
unparseSpecsMethod · 0.95
unparseParamsMethod · 0.95
unparseFieldsMethod · 0.95
leftRecursiveFunction · 0.85
OpenFodderMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected