summaryrefslogtreecommitdiffhomepage
path: root/Parsers.hs
diff options
context:
space:
mode:
authorAndrea Rossato <andrea.rossato@ing.unitn.it>2007-07-08 12:12:08 +0200
committerAndrea Rossato <andrea.rossato@ing.unitn.it>2007-07-08 12:12:08 +0200
commita1aed9cc40bd0a4752516b45fc65beded847c0f5 (patch)
tree9b858d331fd5e2aaa7527d74c760f318cdc33358 /Parsers.hs
parent39820c0004230f4df7e256bc83ec1c9578f94a8d (diff)
downloadxmobar-a1aed9cc40bd0a4752516b45fc65beded847c0f5.tar.gz
xmobar-a1aed9cc40bd0a4752516b45fc65beded847c0f5.tar.bz2
the output template is now parsed with the help of a finite map
This way we can quickly implement program name aliasing. darcs-hash:20070708101208-d6583-fa4f7f490020289e6f6b6fce0886223ec7924fa6.gz
Diffstat (limited to 'Parsers.hs')
-rw-r--r--Parsers.hs30
1 files changed, 22 insertions, 8 deletions
diff --git a/Parsers.hs b/Parsers.hs
index 6feea97..fa85193 100644
--- a/Parsers.hs
+++ b/Parsers.hs
@@ -26,7 +26,9 @@ module Parsers (
) where
import Config
+import Commands
import Text.ParserCombinators.Parsec
+import qualified Data.Map as Map
{- $parser
@@ -81,9 +83,9 @@ colorSpec =
templateStringParser :: Config -> Parser (String,String,String)
templateStringParser c =
do{ s <- many $ noneOf (sepChar c)
- ; (_,com,_) <- templateCommandParser c
+ ; (com,_,_) <- templateCommandParser c
; ss <- many $ noneOf (sepChar c)
- ; return (s, com, ss)
+ ; return (com, s, ss)
}
-- | Parses the command part of the template string
@@ -93,16 +95,28 @@ templateCommandParser c =
; char chr
; com <- many $ noneOf (sepChar c)
; char chr
- ; return $ ("",com,"")
- }
+ ; return $ (com,"","")
+ }
+
-- | Combines the template parsers
templateParser :: Config -> Parser [(String,String,String)]
templateParser c = many (templateStringParser c)
-- | Actually runs the template parsers
-parseTemplate :: Config -> String -> IO [(String,String,String)]
+parseTemplate :: Config -> String -> IO [(Command,String,String)]
parseTemplate config s =
- case (parse (templateParser config) "" s) of
- Left _ -> return [("","","")]
- Right x -> return x
+ do str <- case (parse (templateParser config) "" s) of
+ Left _ -> return [("","","")]
+ Right x -> return x
+ let comList = map (show . fst) $ commands config
+ m = Map.fromList . zip comList . map fst $ (commands config)
+ return $ combine m str
+-- | Given a finite "Map" and a parsed templatet produces the
+-- | resulting output string.
+combine :: Map.Map String Command -> [(String, String, String)] -> [(Command,String,String)]
+combine _ [] = []
+combine m ((ts,s,ss):xs) =
+ [(com, s, ss)] ++ combine m xs
+ where com = Map.findWithDefault dflt ts m
+ dflt = Exec ts [] [] --"<" ++ ts ++ " not found!>"