summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam Vogt <vogt.adam@gmail.com>2009-10-11 05:55:41 +0200
committerAdam Vogt <vogt.adam@gmail.com>2009-10-11 05:55:41 +0200
commitafa953f5254ee68841e8396816261d3405f93cfb (patch)
tree56c67d63845020f94a88134d7f787b2527b28f7b
parentcf428f0be385c523a979cd71c4e5e895f45413cc (diff)
downloadxmobar-afa953f5254ee68841e8396816261d3405f93cfb.tar.gz
xmobar-afa953f5254ee68841e8396816261d3405f93cfb.tar.bz2
Strip '--' comments in xmobarrc
Ignore-this: f58bb2b32a2257d48c039bb8866b5b65 darcs-hash:20091011035541-1499c-0a4163431ee0000c9cdbd70d15bce44b903ec314.gz
-rw-r--r--Parsers.hs23
1 files changed, 17 insertions, 6 deletions
diff --git a/Parsers.hs b/Parsers.hs
index 5fae1d8..0b77940 100644
--- a/Parsers.hs
+++ b/Parsers.hs
@@ -147,16 +147,27 @@ liftM9 :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> b)
liftM9 fun a b c d e f g h i
= fun `liftM` a `ap` b `ap` c `ap` d `ap` e `ap` f `ap` g `ap` h `ap` i
+stripComments :: String -> String
+stripComments = unlines . map (drop 5 . strip False . (replicate 5 ' '++)) . lines
+ where strip m ('-':'-':xs) = if m then "--" ++ strip m xs else ""
+ strip m ('\\':xss) = case xss of
+ '\\':xs -> '\\' : strip m xs
+ _ -> strip m $ drop 1 xss
+ strip m ('"':xs) = '"': strip (not m) xs
+ strip m (x:xs) = x : strip m xs
+ strip _ [] = []
+
-- | Parse the config, logging a list of fields that were missing and replaced
-- by the default definition.
parseConfig :: MonadWriter [String] m => String -> Either ParseError (m Config)
-parseConfig = flip parse "Config" $ do
- sepEndSpaces ["Config","{"]
- x <- unWrapParser perms
- wrapSkip (string "}")
- eof
- return x
+parseConfig = parseConf "Config" . stripComments
where
+ parseConf = parse $ do
+ sepEndSpaces ["Config","{"]
+ x <- unWrapParser perms
+ wrapSkip (string "}")
+ eof
+ return x
perms = runPermsSep (WrappedParser $ wrapSkip $ string ",") $ liftM9 Config
<$> withDef font "font" strField
<*> withDef bgColor "bgColor" strField