def emit.go

cswap-bend-cli@0.1.0.0 · json.bend:250

import cswap-bend-cli@0.1.0.0/json.bend as Json
import Base
import cswap-bend-cli@0.1.0.0/json/quote.bend as Quote

250# The emitter. `j` shrinks on every call; `d` is the nesting depth.
251def emit.go(j: Json, +style: U32, +ascii: Bool, +d: Nat) -> String:
252  match j:
253    case JNull{}:
254      "null"
255    case JBool{b}:
256      bool.show(b)
257    case JNum{t}:
258      t
259    case JStr{s}:
260      Quote.quote(s, ascii)
261    case JArr{+items}:
262      emit.wrap("[", "]", items, emit.go(items, style, ascii, Nat.add(d, 1n)), style, d)
263    case JObj{+fields}:
264      emit.wrap("{", "}", fields, emit.go(fields, style, ascii, Nat.add(d, 1n)), style, d)
265    case JNil{}:
266      ""
267    case JCons{h, +t}:
268      emit.go(h, style, ascii, d) ++ sep.of(t, style, d) ++ emit.go(t, style, ascii, d)
269    case JField{k, v, +t}:
270      Quote.quote(k, ascii) ++ Quote.colon(style) ++ emit.go(v, style, ascii, d) ++ sep.of(t, style, d) ++ emit.go(t, style, ascii, d)

Uses (12)

Used by (5)