From 249dcb5a8e9caaba80f8583bad23575c3507d7e3 Mon Sep 17 00:00:00 2001 From: Akira Komamura Date: Sun, 6 Feb 2022 00:48:12 +0900 Subject: [PATCH] fix: Handle odd number argument lists --- nix/parseParamsString.nix | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/nix/parseParamsString.nix b/nix/parseParamsString.nix index 1807d55..88882a8 100644 --- a/nix/parseParamsString.nix +++ b/nix/parseParamsString.nix @@ -1,11 +1,36 @@ with builtins; let + takeWhile = p: xs: + if length xs == 0 + then [ ] + else if p (head xs) + then [ (head xs) ] ++ takeWhile p (tail xs) + else [ ]; + + dropWhile = p: xs: + if length xs == 0 + then [ ] + else if p (head xs) + then dropWhile p (tail xs) + else xs; + + isKeyword = s: stringLength s > 0 && substring 0 1 s == ":"; + + notKeyword = s: !(isKeyword s); + + toValue = xs: + if length xs == 0 + then true + else if length xs == 1 + then head xs + else xs; + listToAttrs = xs: if length xs == 0 then { } - else if length xs == 1 - then throw "parseParamsString: Found an odd number of items: ${head xs}" - else { ${head xs} = elemAt xs 1; } // listToAttrs (tail (tail xs)); + else { + ${head xs} = toValue (takeWhile notKeyword (tail xs)); + } // listToAttrs (dropWhile notKeyword (tail xs)); stripPat = "[[:space:]]+(.*)";