tomland 1.3.0.0 → 1.3.1.0
raw patch · 9 files changed
+121/−14 lines, 9 filesdep ~hspec-megaparsecdep ~megaparsec
Dependency ranges changed: hspec-megaparsec, megaparsec
Files
- CHANGELOG.md +11/−1
- examples/Main.hs +17/−0
- src/Toml/Codec/Combinator/Map.hs +4/−2
- src/Toml/Parser/Core.hs +1/−1
- src/Toml/Parser/Value.hs +25/−4
- test/Test/Toml/Codec/Combinator/Map.hs +6/−0
- test/Test/Toml/Parser/Common.hs +14/−1
- test/Test/Toml/Parser/Integer.hs +38/−0
- tomland.cabal +5/−5
CHANGELOG.md view
@@ -1,7 +1,17 @@ # Changelog -tomland uses [PVP Versioning][1].+`tomland` uses [PVP Versioning][1]. The changelog is available [on GitHub][2].++## 1.3.1.0 — Sep 21, 2020++* [#331](https://github.com/kowainik/tomland/issues/331):+ Support hexidecimal, octal and binary values with underscores.+* [#335](https://github.com/kowainik/tomland/issues/335):+ Consider table array keys in `tableMap`s as well.+* [#338](https://github.com/kowainik/tomland/issues/338):+ Allow `megaparsec-9.0` and `hspec-megaparsec-2.2`.+* Update GHC from `8.8.3` to `8.8.4`, from `8.10.1` to `8.10.2`. ## 1.3.0.0 — May 19, 2020
examples/Main.hs view
@@ -108,6 +108,21 @@ <*> Toml.int "green" .= rgbGreen <*> Toml.int "blue" .= rgbBlue +newtype Inner = Inner+ { val :: Text+ } deriving stock (Show)++innerCodec :: TomlCodec Inner+innerCodec = Inner <$> Toml.text "val" .= val++newtype MapWithList = MapWithList+ { mapList :: Map Text [Inner]+ } deriving stock (Show)++mapWithListCodec :: TomlCodec MapWithList+mapWithListCodec = MapWithList+ <$> Toml.tableMap Toml._KeyText (Toml.list innerCodec) "mapList" .= mapList+ data Test = Test { testB :: !Bool , testI :: !Int@@ -133,6 +148,7 @@ , intset :: !IntSet , payloads :: !(Map Text Int) , colours :: !(Map Text Colour)+ , tableList :: !MapWithList } @@ -162,6 +178,7 @@ <*> Toml.arrayIntSet "intset" .= intset <*> Toml.map (Toml.text "name") (Toml.int "payload") "payloads" .= payloads <*> Toml.tableMap Toml._KeyText colourCodec "colours" .= colours+ <*> mapWithListCodec .= tableList where pairC :: TomlCodec (Int, Text) pairC = Toml.pair (Toml.int "pNum") (Toml.text "pName")
src/Toml/Codec/Combinator/Map.hs view
@@ -374,7 +374,8 @@ -> Key -- ^ Table name for Map -> TomlCodec map-internalTableMap emptyMap toListMap fromListMap keyBiMap valCodec tableName = Codec input output+internalTableMap emptyMap toListMap fromListMap keyBiMap valCodec tableName =+ Codec input output where input :: TomlEnv map input = \t -> case Prefix.lookup tableName $ tomlTables t of@@ -382,7 +383,8 @@ Just toml -> let valKeys = HashMap.keys $ tomlPairs toml tableKeys = fmap (:|| []) $ HashMap.keys $ tomlTables toml- in fmap fromListMap $ for (valKeys <> tableKeys) $ \key ->+ tableArrayKey = HashMap.keys $ tomlTableArrays toml+ in fmap fromListMap $ for (valKeys <> tableKeys <> tableArrayKey) $ \key -> whenLeftBiMapError key (forward keyBiMap key) $ \k -> (k,) <$> codecRead (valCodec key) toml
src/Toml/Parser/Core.hs view
@@ -26,7 +26,7 @@ import Text.Megaparsec (Parsec, anySingle, eof, errorBundlePretty, match, parse, satisfy, try, (<?>))-import Text.Megaparsec.Char (alphaNumChar, char, digitChar, eol, hexDigitChar, space, space1,+import Text.Megaparsec.Char (alphaNumChar, char, digitChar, eol, hexDigitChar, octDigitChar, binDigitChar, space, space1, string, tab) import Text.Megaparsec.Char.Lexer (binary, float, hexadecimal, octal, signed, skipLineComment, symbol)
src/Toml/Parser/Value.hs view
@@ -22,9 +22,12 @@ import Data.Fixed (Pico) import Data.Time (Day, LocalTime (..), TimeOfDay, ZonedTime (..), fromGregorianValid, makeTimeOfDayValid, minutesToTimeZone)+import Data.String (fromString)+ import Text.Read (readMaybe)+import Text.Megaparsec (parseMaybe) -import Toml.Parser.Core (Parser, binary, char, digitChar, hexadecimal, lexeme, octal, sc, signed,+import Toml.Parser.Core (Parser, char, digitChar, hexDigitChar, octDigitChar, binDigitChar, hexadecimal, octal, binary, lexeme, sc, signed, string, text, try, (<?>)) import Toml.Parser.String (textP) import Toml.Type (AnyValue, UValue (..), typeCheck)@@ -41,15 +44,33 @@ check :: Maybe Integer -> Parser Integer check = maybe (fail "Not an integer") pure +-- | Parser for hexadecimal, octal and binary numbers : included parsing+numberP :: Parser Integer -> Parser Char -> String -> Parser Integer+numberP parseInteger parseDigit errorMessage = more+ where+ more :: Parser Integer+ more = check =<< intValueMaybe . concat <$> sepBy1 (some parseDigit) (char '_')++ intValueMaybe :: String -> Maybe Integer+ intValueMaybe = parseMaybe parseInteger . fromString++ check :: Maybe Integer -> Parser Integer+ check = maybe (fail errorMessage) pure+++ -- | Parser for 'Integer' value. integerP :: Parser Integer integerP = lexeme (bin <|> oct <|> hex <|> dec) <?> "integer" where bin, oct, hex, dec :: Parser Integer- bin = try (char '0' *> char 'b') *> binary <?> "bin"- oct = try (char '0' *> char 'o') *> octal <?> "oct"- hex = try (char '0' *> char 'x') *> hexadecimal <?> "hex"+ bin = try (char '0' *> char 'b') *> binaryP <?> "bin"+ oct = try (char '0' *> char 'o') *> octalP <?> "oct"+ hex = try (char '0' *> char 'x') *> hexadecimalP <?> "hex" dec = signed sc decimalP <?> "dec"+ binaryP = numberP binary binDigitChar "Invalid binary number"+ octalP = numberP octal octDigitChar "Invalid ocatl number"+ hexadecimalP = numberP hexadecimal hexDigitChar "Invalid hexadecimal number" -- | Parser for 'Double' value. doubleP :: Parser Double
test/Test/Toml/Codec/Combinator/Map.hs view
@@ -2,6 +2,7 @@ ( mapSpec ) where +import Data.Foldable (toList) import Test.Hspec (Spec, describe, parallel) import Test.Toml.Codec.Combinator.Common (codecRoundtrip)@@ -9,6 +10,7 @@ import qualified Test.Toml.Gen as Gen import qualified Toml.Codec.BiMap.Conversion as Toml+import qualified Toml.Codec.Combinator.List as Toml import qualified Toml.Codec.Combinator.Map as Toml import qualified Toml.Codec.Combinator.Primitive as Toml @@ -21,3 +23,7 @@ codecRoundtrip "Map Text Int (tableMap)" (Toml.tableMap Toml._KeyText Toml.int) (Gen.genMap (prettyKey <$> Gen.genKey) Gen.genInt)+ -- TODO: handle empty lists in values.+ codecRoundtrip "Map Text [Int] (tableMap)"+ (Toml.tableMap Toml._KeyText (Toml.list $ Toml.int "val"))+ (Gen.genMap (prettyKey <$> Gen.genKey) (toList <$> Gen.genNonEmpty Gen.genInt))
test/Test/Toml/Parser/Common.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ module Test.Toml.Parser.Common ( parseX , failOn@@ -40,6 +42,9 @@ import Test.Hspec (Expectation) import Test.Hspec.Megaparsec (shouldFailOn, shouldParse) import Text.Megaparsec (Parsec, ShowErrorComponent, Stream, parse)+#if MIN_VERSION_megaparsec(9,0,0)+import Text.Megaparsec.Stream (TraversableStream, VisualStream)+#endif import Toml.Parser.Item (tomlP) import Toml.Parser.Key (keyP)@@ -52,7 +57,15 @@ parseX- :: (ShowErrorComponent e, Stream s, Show a, Eq a)+ :: ( ShowErrorComponent e+ , Stream s+#if MIN_VERSION_megaparsec(9,0,0)+ , VisualStream s+ , TraversableStream s+#endif+ , Show a+ , Eq a+ ) => Parsec e s a -> s -> a -> Expectation parseX p given expected = parse p "" given `shouldParse` expected
test/Test/Toml/Parser/Integer.hs view
@@ -81,3 +81,41 @@ it "can parse numbers when hex digits are in both lowercase and uppercase" $ do parseInteger "0xAbCdEf" 0xAbCdEf parseInteger "0xaBcDeF" 0xaBcDeF+ context "when there is underscore in hexadecimal, octal and binary representation" $ do+ it "can parse numbers with underscore in hexadecimal representation" $ do+ parseInteger "0xAb_Cd_Ef" 0xabcdef+ parseInteger "0xA_bcd_ef" 0xabcdef+ parseInteger "0x123_abc" 0x123abc+ parseInteger "0xa_b_c_1_2_3" 0xabc123+ it "can't parse when underscore is between hexadecimal prefix and suffix" $ do+ integerFailOn "0x_Abab_ca"+ integerFailOn "0x_ababbac"+ it "can parse numbers with underscore in octal representation" $ do+ parseInteger "0o12_34_56" 0o123456+ parseInteger "0o1_2345_6" 0o123456+ parseInteger "0o76_54_21" 0o765421+ parseInteger "0o4_5_3_2_6" 0o45326+ it "can't parse when underscore is between octal prefix and suffix" $ do+ integerFailOn "0o_123_4567"+ integerFailOn "0o_1234567"+ it "can parse numbers with underscore in binary representation" $ do+ parseInteger "0b10_101_0" 42+ parseInteger "0b10_10_10" 42+ parseInteger "0b1_0_1" 5+ parseInteger "0b1_0" 2+ it "can't parse numbers when underscore is between binary prefix and suffix" $ do+ integerFailOn "0b_10101_0"+ integerFailOn "0b_101010"+ it "doesn't parse underscore not followed by any numbers" $ do + integerFailOn "0b_"+ integerFailOn "0o_"+ integerFailOn "0x_"+ it "doesn't parse when number is ending with underscore" $ do + integerFailOn "0b101_110_"+ integerFailOn "0b10101_"+ integerFailOn "0x1_23_daf_"+ integerFailOn "0x1214adf_"+ integerFailOn "0o1_15_41_"+ integerFailOn "0o1215147_"+ +
tomland.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: tomland-version: 1.3.0.0+version: 1.3.1.0 synopsis: Bidirectional TOML serialization description: Implementation of bidirectional TOML serialization. Simple codecs look like this:@@ -36,8 +36,8 @@ test/examples/*.toml tested-with: GHC == 8.4.4 GHC == 8.6.5- GHC == 8.8.3- GHC == 8.10.1+ GHC == 8.8.4+ GHC == 8.10.2 source-repository head type: git@@ -119,7 +119,7 @@ , containers >= 0.5.7 && < 0.7 , deepseq ^>= 1.4 , hashable >= 1.2 && < 1.4- , megaparsec >= 7.0.5 && < 8.1+ , megaparsec >= 7.0.5 && < 9.1 , mtl ^>= 2.2 , parser-combinators >= 1.1.0 && < 1.3 , text ^>= 1.2@@ -215,7 +215,7 @@ , hspec ^>= 2.7.1 , hspec-hedgehog ^>= 0.0.1 , hspec-golden ^>= 0.1.0- , hspec-megaparsec >= 2.0.0 && < 2.2.0+ , hspec-megaparsec >= 2.0.0 && < 2.3.0 , megaparsec , directory ^>= 1.3 , text