2022-05-30 15:13:25 -07:00
|
|
|
{ lib }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
2022-05-30 16:17:56 -07:00
|
|
|
isSymbol = str: !(isNull (builtins.match "^'.+" str));
|
2022-05-30 16:21:28 -07:00
|
|
|
stripQuote = str:
|
|
|
|
if (isSymbol str) then head (builtins.match "^'(.+)" str) else str;
|
2022-05-30 15:42:27 -07:00
|
|
|
parseStr = str: if (isSymbol str) then (stripQuote str) else ''"${str}"'';
|
2022-05-30 16:21:28 -07:00
|
|
|
parseKeyword = str: if (isSymbol str) then (stripQuote str) else ":${str}";
|
2022-05-30 15:13:25 -07:00
|
|
|
join-str = concatStringsSep " ";
|
2022-05-30 16:21:28 -07:00
|
|
|
|
2022-05-30 15:13:25 -07:00
|
|
|
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
|
2022-05-30 16:21:28 -07:00
|
|
|
"{ ${
|
|
|
|
join-str
|
2022-05-30 16:22:37 -07:00
|
|
|
(mapAttrsToList (k: v: "${parseKeyword k} ${toEDN v}") ds)
|
2022-05-30 16:21:28 -07:00
|
|
|
} }"
|
2022-05-30 15:13:25 -07:00
|
|
|
else
|
|
|
|
throw "unsupported type: ${builtins.typeOf ds}: ${ds}")));
|
|
|
|
|
2022-05-30 16:10:15 -07:00
|
|
|
in ds: toEDN ds
|