diff options
author | Adam Vogt <vogt.adam@gmail.com> | 2009-10-11 05:55:41 +0200 |
---|---|---|
committer | Adam Vogt <vogt.adam@gmail.com> | 2009-10-11 05:55:41 +0200 |
commit | afa953f5254ee68841e8396816261d3405f93cfb (patch) | |
tree | 56c67d63845020f94a88134d7f787b2527b28f7b | |
parent | cf428f0be385c523a979cd71c4e5e895f45413cc (diff) | |
download | xmobar-afa953f5254ee68841e8396816261d3405f93cfb.tar.gz xmobar-afa953f5254ee68841e8396816261d3405f93cfb.tar.bz2 |
Strip '--' comments in xmobarrc
Ignore-this: f58bb2b32a2257d48c039bb8866b5b65
darcs-hash:20091011035541-1499c-0a4163431ee0000c9cdbd70d15bce44b903ec314.gz
-rw-r--r-- | Parsers.hs | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -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 |