[Pkg-haskell-commits] [SCM] Configuration file support branch, upstream, updated. debian/1.0.5-1-7-g16ca5db
Clint Adams
clint at debian.org
Thu Nov 8 03:57:06 UTC 2012
The following commit has been merged in the upstream branch:
commit 16ca5db902b1ad5e6f309d1515923d64071e1a08
Author: Clint Adams <clint at debian.org>
Date: Wed Nov 7 22:14:44 2012 -0500
Imported Upstream version 1.1.1
diff --git a/ConfigFile.cabal b/ConfigFile.cabal
index 0831177..090586c 100644
--- a/ConfigFile.cabal
+++ b/ConfigFile.cabal
@@ -1,5 +1,5 @@
Name: ConfigFile
-Version: 1.0.6
+Version: 1.1.1
License: LGPL
Maintainer: John Goerzen <jgoerzen at complete.org>
Author: John Goerzen
@@ -37,13 +37,14 @@ Library
Hs-Source-Dirs: src
Exposed-Modules: Data.ConfigFile,
Data.ConfigFile.Types,
- Data.ConfigFile.Parser
+ Data.ConfigFile.Parser,
+ Data.ConfigFile.Monadic
Other-Modules: Data.ConfigFile.Lexer
Extensions: ExistentialQuantification, OverlappingInstances,
UndecidableInstances, TypeSynonymInstances, FlexibleContexts,
FlexibleInstances
Build-Depends: parsec, base < 5,
- haskell98, mtl, MissingH>=1.0.0, containers
+ mtl, MissingH>=1.0.0, containers
GHC-Options: -O2 -Wall
Executable runtests
diff --git a/src/Data/ConfigFile.hs b/src/Data/ConfigFile.hs
index cbb5cdf..1007807 100644
--- a/src/Data/ConfigFile.hs
+++ b/src/Data/ConfigFile.hs
@@ -427,7 +427,7 @@ instance Get_C String where
instance Get_C Bool where
get = getbool
-instance (Num t, Read t) => Get_C t where
+instance Read t => Get_C t where
get = genericget
genericget :: (Read b, MonadError CPError m) => ConfigParser -> SectionSpec -> OptionSpec -> m b
diff --git a/src/Data/ConfigFile/Lexer.hs b/src/Data/ConfigFile/Lexer.hs
index d3bfea6..968d4cd 100644
--- a/src/Data/ConfigFile/Lexer.hs
+++ b/src/Data/ConfigFile/Lexer.hs
@@ -96,8 +96,7 @@ optionkey = many1 oname_chars
optionvalue = many value_chars
optionpair :: GenParser Char st (String, String)
optionpair = do key <- optionkey
- optionsep
- value <- optionvalue
+ value <- option "" $ do { optionsep; optionvalue }
eolstuff
return (key, value)
<?> "key/value option"
diff --git a/src/Data/ConfigFile/Monadic.hs b/src/Data/ConfigFile/Monadic.hs
new file mode 100644
index 0000000..382557f
--- /dev/null
+++ b/src/Data/ConfigFile/Monadic.hs
@@ -0,0 +1,94 @@
+module Data.ConfigFile.Monadic (
+ -- * Overview
+ -- $overview
+
+ module Reexporting,
+ simpleAccess,
+ interpolatingAccess,
+ readfile, readhandle, readstring,
+ has_section, options, has_option, items,
+ set, setshow, remove_option, add_section, remove_section
+) where
+
+import Control.Monad.Error
+import System.IO(Handle)
+import Data.ConfigFile as Reexporting (SectionSpec, OptionSpec, ConfigParser(..),
+ CPErrorData, CPError, emptyCP, Get_C(..), sections, merge, to_string)
+import qualified Data.ConfigFile as C
+
+{- $overview
+This module reexports a slightly different version of the standard API which makes it more convenient for chaining monadically. Everywhere a 'ConfigParser' was the first argument in a function in the standard API, it is now the last. This lets you rewrite
+
+> do let cp = emptyCP
+> cp <- add_section cp "sect1"
+> cp <- set cp "sect1" "opt1" "foo"
+> cp <- set cp "sect1" "opt2" "bar"
+> options cp "sect1"
+
+as
+
+> return emptyCP >>=
+> add_section "sect1" >>=
+> set "sect1" "opt1" "foo" >>=
+> set "sect1" "opt2" "bar" >>=
+> options "sect1"
+
+which may be more elegant in some cases. A future development might be to chain the 'ConfigParser' implicitly with a state monad, which would be yet more elegant.
+
+-}
+
+simpleAccess :: MonadError CPError m =>
+ SectionSpec -> OptionSpec -> ConfigParser -> m String
+simpleAccess s o cp = C.simpleAccess cp s o
+
+interpolatingAccess :: MonadError CPError m =>
+ Int ->
+ SectionSpec -> OptionSpec -> ConfigParser
+ -> m String
+interpolatingAccess maxdepth s o cp = C.interpolatingAccess maxdepth cp s o
+
+readfile :: MonadError CPError m => FilePath -> ConfigParser -> IO (m ConfigParser)
+readfile fp cp = C.readfile cp fp
+
+readhandle :: MonadError CPError m => Handle -> ConfigParser -> IO (m ConfigParser)
+readhandle h cp = C.readhandle cp h
+
+readstring :: MonadError CPError m =>
+ String -> ConfigParser -> m ConfigParser
+readstring cp s = C.readstring s cp
+
+has_section :: SectionSpec -> ConfigParser -> Bool
+has_section x cp = C.has_section cp x
+
+add_section :: MonadError CPError m =>
+ SectionSpec -> ConfigParser -> m ConfigParser
+add_section s cp = C.add_section cp s
+
+options :: MonadError CPError m =>
+ SectionSpec -> ConfigParser -> m [OptionSpec]
+options x cp = C.options cp x
+
+has_option :: SectionSpec -> OptionSpec -> ConfigParser -> Bool
+has_option s o cp = C.has_option cp s o
+
+items :: MonadError CPError m =>
+ SectionSpec -> ConfigParser -> m [(OptionSpec, String)]
+items s cp = C.items cp s
+
+set :: MonadError CPError m =>
+ SectionSpec -> OptionSpec -> String -> ConfigParser -> m ConfigParser
+set s passedo val cp = C.set cp s passedo val
+
+setshow :: (Show a, MonadError CPError m) =>
+ SectionSpec -> OptionSpec -> a -> ConfigParser -> m ConfigParser
+setshow s o val cp = C.setshow cp s o val
+
+remove_option :: MonadError CPError m =>
+ SectionSpec -> OptionSpec -> ConfigParser -> m ConfigParser
+remove_option s passedo cp = C.remove_option cp s passedo
+
+
+remove_section :: MonadError CPError m =>
+ SectionSpec -> ConfigParser -> m ConfigParser
+remove_section s cp = C.remove_section cp s
+
diff --git a/src/Data/ConfigFile/Parser.hs b/src/Data/ConfigFile/Parser.hs
index 02629f7..58df78d 100644
--- a/src/Data/ConfigFile/Parser.hs
+++ b/src/Data/ConfigFile/Parser.hs
@@ -112,7 +112,7 @@ sectionhead =
do {s <- tokeng wf; return $ strip s}
optionlist :: GeneralizedTokenParser CPTok () [(String, String)]
-optionlist = many1 coption
+optionlist = many coption
coption :: GeneralizedTokenParser CPTok () (String, String)
coption =
--
Configuration file support
More information about the Pkg-haskell-commits
mailing list