summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorDunric <dunric29a@gmail.com>2014-09-03 02:25:14 +0200
committerDunric <dunric29a@gmail.com>2014-09-03 02:25:14 +0200
commit849a02d4f6338bf956f62be6240b86a01f976e8c (patch)
tree95bed9c57f3a7ac4adf99860ce6dec5adb32e09b /src
parent557f5dbf2863f85c9e39c90d38a28d4870110afe (diff)
downloadxmobar-849a02d4f6338bf956f62be6240b86a01f976e8c.tar.gz
xmobar-849a02d4f6338bf956f62be6240b86a01f976e8c.tar.bz2
multiline strings support
Diffstat (limited to 'src')
-rw-r--r--src/Parsers.hs19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/Parsers.hs b/src/Parsers.hs
index 69c5f21..b4a2d59 100644
--- a/src/Parsers.hs
+++ b/src/Parsers.hs
@@ -180,9 +180,6 @@ 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 _ [] = []
@@ -249,8 +246,20 @@ parseConfig = runParser parseConf fields "Config" . stripComments
readCommands = manyTill anyChar (try commandsEnd) >>=
read' commandsErr . flip (++) "]"
- strField e n = field e n . between (strDel "start" n) (strDel "end" n) .
- many $ noneOf "\"\n\r"
+ strField e n = field e n strMulti
+
+ strMulti = do
+ scan '"'
+ where
+ scan lead = do
+ spaces
+ char lead
+ s <- manyTill anyChar (rowCont <|> unescQuote)
+ ( char '"' >> return s )
+ <|> ( scan '\\' >>= return . (s ++) )
+ rowCont = try $ (char '\\') >> (string "\n")
+ unescQuote = (lookAhead $ noneOf "\\") >> (lookAhead $ string "\"")
+
strDel t n = char '"' <?> strErr t n
strErr t n = "the " ++ t ++ " of the string field " ++ n ++
" - a double quote (\")."