packages feed

htoml 0.1.0.2 → 0.1.0.3

raw patch · 4 files changed

+71/−15 lines, 4 filesdep ~aesondep ~basedep ~timePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: aeson, base, time

API changes (from Hackage documentation)

- Text.Toml.Types: instance Eq Node
- Text.Toml.Types: instance Eq TValue
- Text.Toml.Types: instance Show Node
- Text.Toml.Types: instance Show TValue
- Text.Toml.Types: instance ToBsJSON Node
- Text.Toml.Types: instance ToBsJSON TValue
- Text.Toml.Types: instance ToBsJSON a => ToBsJSON [a]
- Text.Toml.Types: instance ToBsJSON v => ToBsJSON (HashMap Text v)
- Text.Toml.Types: instance ToJSON Node
- Text.Toml.Types: instance ToJSON TValue
+ Text.Toml.Types: instance Data.Aeson.Types.Class.ToJSON Text.Toml.Types.Node
+ Text.Toml.Types: instance Data.Aeson.Types.Class.ToJSON Text.Toml.Types.TValue
+ Text.Toml.Types: instance GHC.Classes.Eq Text.Toml.Types.Node
+ Text.Toml.Types: instance GHC.Classes.Eq Text.Toml.Types.TValue
+ Text.Toml.Types: instance GHC.Show.Show Text.Toml.Types.Node
+ Text.Toml.Types: instance GHC.Show.Show Text.Toml.Types.TValue
+ Text.Toml.Types: instance Text.Toml.Types.ToBsJSON Text.Toml.Types.Node
+ Text.Toml.Types: instance Text.Toml.Types.ToBsJSON Text.Toml.Types.TValue
+ Text.Toml.Types: instance Text.Toml.Types.ToBsJSON a => Text.Toml.Types.ToBsJSON [a]
+ Text.Toml.Types: instance Text.Toml.Types.ToBsJSON v => Text.Toml.Types.ToBsJSON (Data.HashMap.Base.HashMap Data.Text.Internal.Text v)

Files

CHANGES.md view
@@ -4,14 +4,20 @@ #### dev * ... +#### 0.1.0.3+* GHC 7.10 compatibility fix (thanks @erebe)+* Allow time >= 1.5.0, by using some CPP trickery+* Improve README based on+  [feedback on Reddit](http://www.reddit.com/r/haskell/comments/2s376c/show_rhaskell_htoml_a_parser_for_toml_files)+ #### 0.1.0.2-* Updated the REAMDE-* Added/relaxed dependency version contraints where applicable-* Fixed all warnings-* Added `CHANGES.md`+* Update the REAMDE+* Add/relax dependency version contraints where applicable+* Fix all warnings+* Add `CHANGES.md`  #### 0.1.0.1-* Fixes `cabal configure` error in cabal file+* Fix `cabal configure` error in cabal file  #### 0.1.0.0 * Initial upload to Hackage
README.md view
@@ -36,7 +36,9 @@      git clone https://github.com/cies/htoml.git     cd htoml-    cabal repl  ;# this starts GHCi+    cabal sandbox init  ;# initialize a cabal sandbox+    cabal install       ;# install the dependencies and build all+    cabal repl          ;# starts a sandbox-aware GHCi  We can immediately start exploring from the `GHCi` prompt. @@ -50,7 +52,7 @@     Object (fromList [("database",Object (fromList [("enabled",Bool True) [...]      > let Left error = parseTomlDoc "" "== invalid toml =="-    > error+    > e     (line 1, column 1):     unexpected '='     expecting "#", "[" or end of input@@ -58,6 +60,41 @@ Notice that some outputs are truncated, indicated by `[...]`.  +### How to pull data from a TOML file after parsing it++Once you have sucessfully parsed a TOML file you most likely want to pull+some piecces of data out of the resulting data structure.++To do so you have two main options. The first is to use pattern matching.+For example let's consider the following `parseResult`:++```haskell+Right (fromList [("server",NTable (fromList [("enabled",NTValue (VBoolean True))] ) )] )+```++Which could be pattern matched with:++```haskell+case parseResult of+  Left  _ -> "Could not parse file"+  Right m -> case m ! "server" of+    NTable mm -> case mm ! "enabled" of+      VBoolean b -> "Server is " ++ (if b then "enabled" else "disabled")+      _ -> "Could not parse server status (Boolean)"+    _ -> "TOML file does not contain the 'server' key"+```++The second main option is to use the `toJSON` function to transform the data+to an [Aeson](https://hackage.haskell.org/package/aeson) data structure,+after which you can use your Aeson toolbelt to tackle the problem. Since+TOML is intended to be a close cousin of JSON this is a very practical+approach.++Other ways to pull data from a parsed TOML document will most likely+exist; maybe the `lens` library can give great results in some cases.+But I have no experience with them.++ ### Version contraints of `htoml`'s dependencies  If you encounter any problems because `htoml`'s dependecies are@@ -94,14 +131,14 @@  ### Features -* Follows the latest version of the TOML spec, proven by an extensive test suite+* Compatibility to the TOML spec is proven by an extensive test suite * Incorporates [BurntSushi's language agnostic test suite](https://github.com/BurntSushi/toml-test) * Has an internal representation that easily maps to JSON-* Provides a JSON interface (suggested by Greg Weber)+* Provides an [Aeson](https://hackage.haskell.org/package/aeson)-style JSON interface (suggested by Greg Weber) * Useful error messages (thanks to using Parsec over Attoparsec) * Understands arrays as described in [this issue](https://github.com/toml-lang/toml/issues/254) * Fails on mix-type arrays (as per spec)-* Provides a benchmark suite+* Comes with a benchmark suite to make performance gains/regressions measurable * Tries to be well documented (please raise an issue if you find documentation lacking)  @@ -109,8 +146,7 @@  * Release a stable 1.0 release and submit it to [Stackage](http://stackage.org) * More documentation-* Moke all tests pass (currently some more obscure corner cases don't pass)-* Add more tests (maybe find a more mature TOML parser and steal their tests)+* Make all tests pass (currently some more obscure corner cases don't pass) * Add property tests with QuickCheck (the internet says it's possible for parsers) * Extensively test error cases * Try using Vector instead of List (measure performance increase with the benchmarks)
htoml.cabal view
@@ -1,5 +1,5 @@ name:                     htoml-version:                  0.1.0.2+version:                  0.1.0.3 synopsis:                 Parser for TOML files description:              TOML is an obvious and minimal format for config files.                           .@@ -86,6 +86,7 @@                         , file-embed                         , unordered-containers                         , vector+                        , aeson                         , text                         , time                         , Cabal
src/Text/Toml/Parser.hs view
@@ -1,4 +1,6 @@+{-# LANGUAGE FlexibleContexts  #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE CPP               #-}  module Text.Toml.Parser   ( module Text.Toml.Parser@@ -13,9 +15,16 @@ import qualified Data.List           as L import qualified Data.Set            as S import           Data.Text           (Text, pack, unpack)++#if MIN_VERSION_time(1,5,0)+import           Data.Time.Format    (defaultTimeLocale, iso8601DateFormat,+                                      parseTimeM)+#else import           Data.Time.Format    (parseTime)-import           Numeric             (readHex) import           System.Locale       (defaultTimeLocale, iso8601DateFormat)+#endif++import           Numeric             (readHex) import           Text.Parsec import           Text.Parsec.Text @@ -78,7 +87,7 @@  -- | Parses a table array header. tableArrayHeader :: Parser [Text]-tableArrayHeader = between (twoChar  '[') (twoChar ']') headerValue+tableArrayHeader = between (twoChar '[') (twoChar ']') headerValue   where     twoChar c = count 2 (char c) @@ -174,7 +183,11 @@ datetime :: Parser TValue datetime = do     d <- manyTill anyChar (try $ char 'Z')+#if MIN_VERSION_time(1,5,0)+    let  mt = parseTimeM True defaultTimeLocale (iso8601DateFormat $ Just "%X") d+#else     let  mt = parseTime defaultTimeLocale (iso8601DateFormat $ Just "%X") d+#endif     case mt of Just t  -> return $ VDatetime t                Nothing -> fail "parsing datetime failed"