diff --git a/data/tuples.settings b/data/tuples.settings index e8b46aa..723571c 100644 --- a/data/tuples.settings +++ b/data/tuples.settings @@ -1,4 +1,7 @@ [org/gnome/tuples] +t0=() +t1=(5,) +t1-sp=(5, ) t2=(true, 'woman') t3=(false, 'man', -2) t4=('hello', 22, 'world', true) diff --git a/output/tuples.nix b/output/tuples.nix index 9468dbf..1af9b3a 100644 --- a/output/tuples.nix +++ b/output/tuples.nix @@ -8,6 +8,9 @@ with lib.hm.gvariant; "org/gnome/tuples" = { n1 = mkTuple [ false (mkTuple [ "xkb" "us" ]) "nested" ]; n2 = mkTuple [ "hi" (mkTuple [ true "us" (mkTuple [ (-787) "lvl" ]) ]) "super-nested" ]; + t0 = mkTuple []; + t1 = mkTuple [ 5 ]; + t1-sp = mkTuple [ 5 ]; t2 = mkTuple [ true "woman" ]; t3 = mkTuple [ false "man" (-2) ]; t4 = mkTuple [ "hello" 22 "world" true ]; diff --git a/src/DConf.hs b/src/DConf.hs index 5be30ff..d45ddc7 100644 --- a/src/DConf.hs +++ b/src/DConf.hs @@ -27,8 +27,22 @@ bracket s1 s2 pa = do _ <- string s2 return a +comma :: Parsec Text () () +comma = string "," >> spaces + commaSeparated :: Parsec Text () a -> Parsec Text () [a] -commaSeparated pa = sepBy pa $ string "," >> spaces +commaSeparated pa = sepBy pa comma + +-- Like 'sepEndBy' but the separator can only appear at the end when there is just a single item. +sepOneEndBy :: Show a => Parsec Text () a -> Parsec Text () sep -> Parsec Text () [a] +sepOneEndBy p sep = + do + { x <- p + ; _ <- sep + ; xs <- sepBy p sep + ; return (x:xs) + } + <|> return [] vBool :: Parsec Text () Value vBool = B False <$ string "false" <|> B True <$ string "true" @@ -58,11 +72,7 @@ vInt64 = try $ do I64 . read <$> many1 digit vTuple :: Parsec Text () Value -vTuple = do - rs <- bracket "(" ")" $ commaSeparated $ value - case rs of - xs@(_ : _ : _) -> pure $ T xs - _ -> fail "Not a tuple" +vTuple = T <$> (bracket "(" ")" $ sepOneEndBy value comma) vString :: Parsec Text () Text vString = T.pack <$> (single <|> double)