2022-05-30 15:13:25 -07:00
|
|
|
{ lib }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
2022-05-30 15:42:27 -07:00
|
|
|
isSymbol = str: isNull (match "^'.+" str);
|
|
|
|
stripQuote = head (match "^'(.+)");
|
|
|
|
parseStr = str: if (isSymbol str) then (stripQuote str) else ''"${str}"'';
|
|
|
|
|
2022-05-30 15:13:25 -07:00
|
|
|
join-str = concatStringsSep " ";
|
|
|
|
toEDN = ds:
|
|
|
|
if isString ds then
|
2022-05-30 15:42:27 -07:00
|
|
|
parseStr ds
|
2022-05-30 15:13:25 -07:00
|
|
|
else
|
|
|
|
(if isInt ds then
|
|
|
|
ds
|
|
|
|
else
|
|
|
|
(if isList ds then
|
|
|
|
"[ ${join-str (map toEDN ds)} ]"
|
|
|
|
else
|
|
|
|
(if isAttrs ds then
|
|
|
|
"{ ${join-str (mapAttrs (k: v: ":${k} ${toEDN v}") ds)} }"
|
|
|
|
else
|
|
|
|
throw "unsupported type: ${builtins.typeOf ds}: ${ds}")));
|
|
|
|
|
|
|
|
in { ds }: toEDN ds
|