def canon
yaml-for-bend@0.1.1.0 · value.bend:108
import yaml-for-bend@0.1.1.0/value.bend as Value
import Base
108
109
110
111
112def canon(v: Yaml) -> String:
113 match v:
114 case Null{}:
115 "~"
116 case Boolean{on}:
117 Bool.pick(String, on, "t", "f")
118 case Int{t}:
119 "i" ++ t ++ ";"
120 case Float{t}:
121 "d" ++ t ++ ";"
122 case Str{+t}:
123 "s" ++ Nat.show(String.length(t)) ++ ":" ++ t
124 case Seq{xs}:
125 match xs:
126 case Nil{}:
127 "]"
128 case Con{x, rest}:
129 "[" ++ canon(x) ++ canon(Seq{rest})
130 case Mapping{es}:
131 match es:
132 case Nil{}:
133 "}"
134 case Con{Entry{k, x}, rest}:
135 "{" ++ canon(k) ++ canon(x) ++ canon(Mapping{rest})
136 case Tagged{+tag, x}:
137 "!" ++ Nat.show(String.length(tag)) ++ ":" ++ tag ++ canon(x)