def emit
yaml-for-bend@0.1.1.0 · emit.bend:203
import yaml-for-bend@0.1.1.0/emit.bend as Emit
import Base
import yaml-for-bend@0.1.1.0/value.bend as V
203
204def emit(v: V.Yaml, +ind: Nat, +p: Pos) -> String:
205 match v:
206 case V.Seq{xs}:
207 match xs:
208 case Nil{}:
209 Bool.pick(String, is_more(p), "", scalar.lead(p, ind) ++ "[]\n")
210 case Con{x, rest}:
211 lead(p, ind) ++ "- " ++ emit(x, Nat.add(ind, 2n), Dash{}) ++ emit(V.Seq{rest}, ind, More{})
212 case V.Mapping{es}:
213 match es:
214 case Nil{}:
215 Bool.pick(String, is_more(p), "", scalar.lead(p, ind) ++ "{}\n")
216 case Con{V.Entry{+k, x}, rest}:
217 when(String, is_collection(k) || is_tagged(k),
218 u => lead(p, ind) ++ "? " ++ emit(k, Nat.add(ind, 2n), Dash{}) ++ spaces(ind) ++ ":",
219 u => lead(p, ind) ++ scalar.text(k) ++ ":") ++
220 emit(x, Nat.add(ind, 2n), Colon{}) ++ emit(V.Mapping{rest}, ind, More{})
221 case V.Tagged{+tag, +x}:
222 scalar.lead(p, ind) ++ tag.text(tag) ++ Bool.pick(String, is_collection(x), "", " ") ++
223 emit(x, ind, Bool.pick(Pos, is_collection(x), Colon{}, Dash{}))
224 case _:
225 scalar.lead(p, ind) ++ scalar.text(v) ++ "\n"