ConfigFileTH 0.1 → 0.2
raw patch · 2 files changed
+17/−9 lines, 2 filesdep ~ConfigFiledep ~basedep ~parsec
Dependency ranges changed: ConfigFile, base, parsec
Files
- ConfigFileTH.cabal +5/−2
- Data/ConfigFile/TH.hs +12/−7
ConfigFileTH.cabal view
@@ -1,5 +1,5 @@ Name: ConfigFileTH-Version: 0.1+Version: 0.2 Synopsis: Template haskell for reading ConfigFiles. Category: Parsing, Template Haskell Description:@@ -33,4 +33,7 @@ Library Exposed-Modules: Data.ConfigFile.TH- Build-Depends: base >= 4.2 && <4.3 ,ConfigFile == 1.0.6, template-haskell, parsec == 3.1.0+ Build-Depends: base >= 4.3 && < 5+ ,ConfigFile >= 1.0.6 && < 2+ ,template-haskell+ ,parsec >= 3.1.0 && <4
Data/ConfigFile/TH.hs view
@@ -58,16 +58,21 @@ -- |Quasiquoter for quickly writing config-file specifications-conf = QuasiQuoter sToExpQ undefined- where- sToExpQ = return . toList . map parse - . filter (not.all isSpace) - . lines - parse x = case runParser pCd () "Quasiquote" x of++conf = QuasiQuoter undefined undefined undefined (sToExpQ)++sToExpQ str = let+ hd':rst = filter (not.null) $ lines str+ hd = takeWhile (not . isSpace) . dropWhile isSpace $ hd'+ in genConf hd . map parseIt . filter (not.all isSpace) $ rst++parseIt :: [Char] -> (String, String, String, String)+parseIt x = case runParser pCd () "Quasiquote" x of Right x -> x- Left e -> error (show e) + Left e -> error (show e++show x) -- | TH macro for generating a data type and corresponding code to load it from a config file.+genConf :: Monad m => String -> [(String, String, String, String)] -> m [Dec] genConf name cs = do return $ decls