diff --git a/data/dconf.settings b/data/dconf.settings index cc5899d..ea91d17 100644 --- a/data/dconf.settings +++ b/data/dconf.settings @@ -173,6 +173,9 @@ initial-size=(890, 550) maximized=false sidebar-width=189 +[org/gnome/settings-daemon/plugins/color] +night-light-last-coordinates=(43.684199280057591, -79.347200000000001) + [org/gnome/settings-daemon/plugins/media-keys] custom-keybindings=['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/'] @@ -296,3 +299,6 @@ foo_bar='test' [com/github/wwmm/easyeffects/streamoutputs/compressor#0] sidechain-input-device='alsa_input.platform-snd_aloop.0.analog-stereo' + +[org/gnome/gnome-commander/preferences/general] +file-list-tabs=[('file:///home/alice', byte 0x00, byte 0x01, false, false), ('file:///home/alice', 0x01, 0x01, false, false)] diff --git a/data/negative.settings b/data/negative.settings deleted file mode 100644 index 8d98bc5..0000000 --- a/data/negative.settings +++ /dev/null @@ -1,2 +0,0 @@ -[org/gnome/settings-daemon/plugins/color] -night-light-last-coordinates=(43.684199280057591, -79.347200000000001) diff --git a/data/numbers.settings b/data/numbers.settings new file mode 100644 index 0000000..27a107b --- /dev/null +++ b/data/numbers.settings @@ -0,0 +1,35 @@ +[floats] +avogadro=6.283185307179586 +basic=1234567890.1234567890 +negative=-72.02 +positive=+72.02 +sci=6.022e23 +sci-exp-neg=7.51e-9 +sci-neg=-72.02e3 +sci-neg-exp-neg=-9.11e-17 +zero=0.0 +zero-neg=-0.0 +zero-pos=+0.0 + +[int] +dec=1234567890 +dec-neg=-987654321 +dec-pos=+987654321 +dec-one=1 +dec-zero=0 +hex=0x123456789abcdef0 +hex-dec-only=0x1234567890 +hex-neg=-0x1234 +hex-neg-e=-0x1e +hex-neg-e2=-0x1e2 +hex-pos=+0x1234 +hex-zero=0x0 +hex-zero-neg=-0x0 +hex-zero-pos=+0x0 +oct=012345670 +oct-byte-max=0377 +oct-neg=-0377 +oct-pos=+0377 +oct-zero=00 +oct-zero-neg=-00 +oct-zero-pos=+00 diff --git a/output/dconf.nix b/output/dconf.nix index 089f352..1b22914 100644 --- a/output/dconf.nix +++ b/output/dconf.nix @@ -220,6 +220,10 @@ with lib.hm.gvariant; sidebar-width = 189; }; + "org/gnome/settings-daemon/plugins/color" = { + night-light-last-coordinates = mkTuple [ 43.68419928005759 (-79.3472) ]; + }; + "org/gnome/settings-daemon/plugins/media-keys" = { custom-keybindings = [ "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/" ]; }; @@ -374,5 +378,9 @@ with lib.hm.gvariant; sidechain-input-device = "alsa_input.platform-snd_aloop.0.analog-stereo"; }; + "org/gnome/gnome-commander/preferences/general" = { + file-list-tabs = [ (mkTuple [ "file:///home/alice" (mkUchar 0) (mkUchar 1) false false ]) (mkTuple [ "file:///home/alice" 1 1 false false ]) ]; + }; + }; } diff --git a/output/negative.nix b/output/negative.nix deleted file mode 100644 index 5a7fc09..0000000 --- a/output/negative.nix +++ /dev/null @@ -1,13 +0,0 @@ -# Generated via dconf2nix: https://github.com/nix-commmunity/dconf2nix -{ lib, ... }: - -with lib.hm.gvariant; - -{ - dconf.settings = { - "org/gnome/settings-daemon/plugins/color" = { - night-light-last-coordinates = mkTuple [ 43.68419928005759 (-79.3472) ]; - }; - - }; -} diff --git a/output/numbers.nix b/output/numbers.nix new file mode 100644 index 0000000..3c8cca3 --- /dev/null +++ b/output/numbers.nix @@ -0,0 +1,47 @@ +# Generated via dconf2nix: https://github.com/nix-commmunity/dconf2nix +{ lib, ... }: + +with lib.hm.gvariant; + +{ + dconf.settings = { + "floats" = { + avogadro = 6.283185307179586; + basic = 1.2345678901234567e9; + negative = -72.02; + positive = 72.02; + sci = 6.022e23; + sci-exp-neg = 7.51e-9; + sci-neg = -72020.0; + sci-neg-exp-neg = -9.11e-17; + zero = 0.0; + zero-neg = -0.0; + zero-pos = 0.0; + }; + + "int" = { + dec = 1234567890; + dec-neg = -987654321; + dec-one = 1; + dec-pos = 987654321; + dec-zero = 0; + hex = 1311768467463790320; + hex-dec-only = 78187493520; + hex-neg = -4660; + hex-neg-e = -30; + hex-neg-e2 = -482; + hex-pos = 4660; + hex-zero = 0; + hex-zero-neg = 0; + hex-zero-pos = 0; + oct = 2739128; + oct-byte-max = 255; + oct-neg = -255; + oct-pos = 255; + oct-zero = 0; + oct-zero-neg = 0; + oct-zero-pos = 0; + }; + + }; +} diff --git a/src/DConf.hs b/src/DConf.hs index 1854cf5..b29062f 100644 --- a/src/DConf.hs +++ b/src/DConf.hs @@ -53,19 +53,36 @@ vBool = B False <$ string "false" <|> B True <$ string "true" vNothing :: Parsec Text () Value vNothing = No <$ string "nothing" + +numSign :: Num a => Parsec Text () a +numSign = + (pure (-1) <* string "-") + <|> (pure 1 <* string "+") + <|> pure 1 + vDouble :: Parsec Text () Value vDouble = try $ do - s <- option "" $ string "-" + s <- numSign n <- many1 digit d <- string "." e <- many1 (digit <|> oneOf "eEdD-") - pure . D $ read (s <> n <> d <> e) + pure . D $ s * read (n <> d <> e) vInt :: Parsec Text () Value vInt = try $ do - s <- option "" $ string "-" - n <- many1 digit <* notFollowedBy (char '.') - pure . I $ read (s <> n) + s <- numSign + (base, digitParser) <- prefix + n <- (many1 digitParser <* notFollowedBy (char '.')) + -- There was only a lone zero digit, already consumed by the octal prefix. + <|> (if base == 8 then pure [0] else fail "Not a number") + pure . I $ s * digitsToNum base n + where + prefix = + ((pure (16, fromHexDigit <$> hexDigit) <* (string' "0x" <|> string' "0X")) + -- @notFollowedBy@ to prevent ambiguity with @vDouble@. + <|> (pure (8, fromOctDigit <$> octDigit) <* (string' "0" <* notFollowedBy (char '.'))) + <|> (pure (10, fromDecDigit <$> digit))) + vCast :: Parsec Text () Value vCast = do @@ -102,34 +119,41 @@ vString = T.pack <$> (single <|> double) lchar :: [Char] -> Parsec Text () Char lchar extra = charExcept $ "\r\n\\" <> extra - fromHexDigit :: Char -> Int - fromHexDigit n | inRange ('A', 'F') n = ord n - ord 'A' + 0xA - fromHexDigit n | inRange ('a', 'f') n = ord n - ord 'a' + 0xA - fromHexDigit n | inRange ('0', '9') n = ord n - ord '0' - fromHexDigit n = error $ "Expected a hexadecimal digit, '" ++ n : "' given" - - hexNum :: Int -> Parsec Text () Int - hexNum l = do - digits <- replicateM l (fromHexDigit <$> hexDigit) - return $ foldl (\acc d -> 16 * acc + d) 0 digits - qchar :: Parsec Text () (Maybe Char) qchar = do _ <- char '\\' ( -- Unicode escapes of the form `\uxxxx` and `\Uxxxxxxxx` are supported, in hexadecimal. - (char 'u' *> (Just <$> (chr <$> hexNum 4))) - <|> (char 'U' *> (Just <$> (chr <$> hexNum 8))) + (char 'u' *> (Just <$> (chr <$> hexNumFix 4))) + <|> (char 'U' *> (Just <$> (chr <$> hexNumFix 8))) <|> commonEscapes) inputs :: [Char] -> Parsec Text () String inputs extra = catMaybes <$> (many $ qchar <|> (Just <$> lchar extra)) +fromDecDigit :: Char -> Int +fromDecDigit n | inRange ('0', '9') n = ord n - ord '0' +fromDecDigit n = error $ "Expected a decimal digit, '" ++ n : "' given" + +fromHexDigit :: Char -> Int +fromHexDigit n | inRange ('A', 'F') n = ord n - ord 'A' + 0xA +fromHexDigit n | inRange ('a', 'f') n = ord n - ord 'a' + 0xA +fromHexDigit n | inRange ('0', '9') n = ord n - ord '0' +fromHexDigit n = error $ "Expected a hexadecimal digit, '" ++ n : "' given" fromOctDigit :: Char -> Int fromOctDigit n | inRange ('0', '7') n = ord n - ord '0' fromOctDigit n = error $ "Expected an octal digit, '" ++ n : "' given" +-- | Parses a hexadecimal number of precisely @l@ digits. +hexNumFix :: Int -> Parsec Text () Int +hexNumFix l = do + digits <- replicateM l (fromHexDigit <$> hexDigit) + return $ digitsToNum 16 digits + +digitsToNum :: Int -> [Int] -> Int +digitsToNum base = foldl (\acc d -> base * acc + d) 0 + -- | Parses an octal number between 1 and @maxlen@ digits. octNumMax :: Int -> Parsec Text () Int octNumMax maxLen = octNum' 0 maxLen diff --git a/test/DConf2NixTest.hs b/test/DConf2NixTest.hs index 750138c..3e30259 100644 --- a/test/DConf2NixTest.hs +++ b/test/DConf2NixTest.hs @@ -89,8 +89,8 @@ prop_dconf2nix_indexer = withTests (10 :: TestLimit) dconf2nixIndexer dconf2nixNegative :: Property dconf2nixNegative = - let input = "data/negative.settings" - output = "output/negative.nix" + let input = "data/numbers.settings" + output = "output/numbers.nix" root = Root T.empty in baseProperty input output root