Allow for symbol keywords too
This commit is contained in:
parent
730709b4e2
commit
6e708bcd8d
11
to-edn.nix
11
to-edn.nix
|
@ -3,10 +3,12 @@
|
|||
with lib;
|
||||
let
|
||||
isSymbol = str: !(isNull (builtins.match "^'.+" str));
|
||||
stripQuote = str: head (builtins.match "^'(.+)" str);
|
||||
stripQuote = str:
|
||||
if (isSymbol str) then head (builtins.match "^'(.+)" str) else str;
|
||||
parseStr = str: if (isSymbol str) then (stripQuote str) else ''"${str}"'';
|
||||
|
||||
parseKeyword = str: if (isSymbol str) then (stripQuote str) else ":${str}";
|
||||
join-str = concatStringsSep " ";
|
||||
|
||||
toEDN = ds:
|
||||
if isString ds then
|
||||
parseStr ds
|
||||
|
@ -18,7 +20,10 @@ let
|
|||
"[ ${join-str (map toEDN ds)} ]"
|
||||
else
|
||||
(if isAttrs ds then
|
||||
"{ ${join-str (mapAttrsToList (k: v: ":${k} ${toEDN v}") ds)} }"
|
||||
"{ ${
|
||||
join-str
|
||||
(mapAttrsToList (k: v: ":${parseKeyword k} ${toEDN v}") ds)
|
||||
} }"
|
||||
else
|
||||
throw "unsupported type: ${builtins.typeOf ds}: ${ds}")));
|
||||
|
||||
|
|
Loading…
Reference in New Issue