{-# LANGUAGE FlexibleContexts, CPP #-}
module Xmobar.Config.Parse(readConfig
, parseConfig
, indexedFont
, indexedOffset
, colorComponents) where
import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Number (int)
import Text.ParserCombinators.Parsec.Perm ((<|?>), (<$?>), permute)
import Control.Monad.IO.Class (liftIO)
import Data.Functor ((<&>))
import Xmobar.Config.Types
import qualified System.IO as S (readFile)
colorComponents :: Config -> String -> (String, String)
colorComponents :: Config -> String -> (String, String)
colorComponents Config
conf String
c =
case (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
',') String
c of
(String
f,Char
',':String
b) -> (String
f, String
b)
(String
f, String
_) -> (String
f, Config -> String
bgColor Config
conf)
stripComments :: String -> String
=
[String] -> String
unlines ([String] -> String) -> (String -> [String]) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (FontIndex -> String -> String
forall a. FontIndex -> [a] -> [a]
drop FontIndex
5 (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> String -> String
strip Bool
False (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FontIndex -> Char -> String
forall a. FontIndex -> a -> [a]
replicate FontIndex
5 Char
' 'String -> String -> String
forall a. [a] -> [a] -> [a]
++)) ([String] -> [String])
-> (String -> [String]) -> String -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
lines
where strip :: Bool -> String -> String
strip Bool
m (Char
'-':Char
'-':String
xs) = if Bool
m then String
"--" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Bool -> String -> String
strip Bool
m String
xs else String
""
strip Bool
m (Char
'"':String
xs) = Char
'"'Char -> String -> String
forall a. a -> [a] -> [a]
: Bool -> String -> String
strip (Bool -> Bool
not Bool
m) String
xs
strip Bool
m (Char
x:String
xs) = Char
x Char -> String -> String
forall a. a -> [a] -> [a]
: Bool -> String -> String
strip Bool
m String
xs
strip Bool
_ [] = []
parseConfig :: Config -> String -> Either ParseError (Config,[String])
parseConfig :: Config -> String -> Either ParseError (Config, [String])
parseConfig Config
defaultConfig =
GenParser Char [String] (Config, [String])
-> [String]
-> String
-> String
-> Either ParseError (Config, [String])
forall tok st a.
GenParser tok st a -> st -> String -> [tok] -> Either ParseError a
runParser GenParser Char [String] (Config, [String])
parseConf [String]
fields String
"Config" (String -> Either ParseError (Config, [String]))
-> (String -> String)
-> String
-> Either ParseError (Config, [String])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
stripComments
where
parseConf :: GenParser Char [String] (Config, [String])
parseConf = do
ParsecT String [String] Identity Char
-> ParsecT String [String] Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String [String] Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
space
[String] -> ParsecT String [String] Identity ()
forall {u}. [String] -> ParsecT String u Identity ()
sepEndSpc [String
"Config",String
"{"]
x <- Parsec String [String] Config
perms
eof
s <- getState
return (x, s)
perms :: Parsec String [String] Config
perms = StreamPermParser String [String] Config
-> Parsec String [String] Config
forall s tok st a.
Stream s Identity tok =>
StreamPermParser s st a -> Parsec s st a
permute (StreamPermParser String [String] Config
-> Parsec String [String] Config)
-> StreamPermParser String [String] Config
-> Parsec String [String] Config
forall a b. (a -> b) -> a -> b
$ String
-> [String]
-> String
-> String
-> String
-> String
-> XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config
Config
(String
-> [String]
-> String
-> String
-> String
-> String
-> XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (String, ParsecT String [String] Identity String)
-> StreamPermParser
String
[String]
([String]
-> String
-> String
-> String
-> String
-> XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok a b st.
Stream s Identity tok =>
(a -> b) -> (a, Parsec s st a) -> StreamPermParser s st b
<$?> (String, ParsecT String [String] Identity String)
pFont StreamPermParser
String
[String]
([String]
-> String
-> String
-> String
-> String
-> XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> ([String], ParsecT String [String] Identity [String])
-> StreamPermParser
String
[String]
(String
-> String
-> String
-> String
-> XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> ([String], ParsecT String [String] Identity [String])
pFontList StreamPermParser
String
[String]
(String
-> String
-> String
-> String
-> XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (String, ParsecT String [String] Identity String)
-> StreamPermParser
String
[String]
(String
-> String
-> String
-> XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (String, ParsecT String [String] Identity String)
pWmClass StreamPermParser
String
[String]
(String
-> String
-> String
-> XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (String, ParsecT String [String] Identity String)
-> StreamPermParser
String
[String]
(String
-> String
-> XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (String, ParsecT String [String] Identity String)
pWmName
StreamPermParser
String
[String]
(String
-> String
-> XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (String, ParsecT String [String] Identity String)
-> StreamPermParser
String
[String]
(String
-> XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (String, ParsecT String [String] Identity String)
pBgColor StreamPermParser
String
[String]
(String
-> XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (String, ParsecT String [String] Identity String)
-> StreamPermParser
String
[String]
(XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (String, ParsecT String [String] Identity String)
pFgColor StreamPermParser
String
[String]
(XPosition
-> Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (XPosition, Parsec String [String] XPosition)
-> StreamPermParser
String
[String]
(Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (XPosition, Parsec String [String] XPosition)
pPosition
StreamPermParser
String
[String]
(Bool
-> TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (Bool, Parsec String [String] Bool)
-> StreamPermParser
String
[String]
(TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (Bool, Parsec String [String] Bool)
pTextOutput StreamPermParser
String
[String]
(TextOutputFormat
-> FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (TextOutputFormat, Parsec String [String] TextOutputFormat)
-> StreamPermParser
String
[String]
(FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (TextOutputFormat, Parsec String [String] TextOutputFormat)
pTextOutputFormat
StreamPermParser
String
[String]
(FontIndex
-> [FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (FontIndex, Parsec String [String] FontIndex)
-> StreamPermParser
String
[String]
([FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (FontIndex, Parsec String [String] FontIndex)
pTextOffset StreamPermParser
String
[String]
([FontIndex]
-> FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> ([FontIndex], Parsec String [String] [FontIndex])
-> StreamPermParser
String
[String]
(FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> ([FontIndex], Parsec String [String] [FontIndex])
pTextOffsets
StreamPermParser
String
[String]
(FontIndex
-> Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (FontIndex, Parsec String [String] FontIndex)
-> StreamPermParser
String
[String]
(Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (FontIndex, Parsec String [String] FontIndex)
pIconOffset StreamPermParser
String
[String]
(Border
-> String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (Border, Parsec String [String] Border)
-> StreamPermParser
String
[String]
(String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (Border, Parsec String [String] Border)
pBorder
StreamPermParser
String
[String]
(String
-> FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (String, ParsecT String [String] Identity String)
-> StreamPermParser
String
[String]
(FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (String, ParsecT String [String] Identity String)
pBdColor StreamPermParser
String
[String]
(FontIndex
-> FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (FontIndex, Parsec String [String] FontIndex)
-> StreamPermParser
String
[String]
(FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (FontIndex, Parsec String [String] FontIndex)
pBdWidth StreamPermParser
String
[String]
(FontIndex
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (FontIndex, Parsec String [String] FontIndex)
-> StreamPermParser
String
[String]
(Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (FontIndex, Parsec String [String] FontIndex)
pAlpha StreamPermParser
String
[String]
(Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (Bool, Parsec String [String] Bool)
-> StreamPermParser
String
[String]
(Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (Bool, Parsec String [String] Bool)
pHideOnStart
StreamPermParser
String
[String]
(Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (Bool, Parsec String [String] Bool)
-> StreamPermParser
String
[String]
(Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (Bool, Parsec String [String] Bool)
pAllDesktops StreamPermParser
String
[String]
(Bool
-> Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (Bool, Parsec String [String] Bool)
-> StreamPermParser
String
[String]
(Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (Bool, Parsec String [String] Bool)
pOverrideRedirect StreamPermParser
String
[String]
(Bool
-> Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (Bool, Parsec String [String] Bool)
-> StreamPermParser
String
[String]
(Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (Bool, Parsec String [String] Bool)
pPickBroadest
StreamPermParser
String
[String]
(Bool
-> Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (Bool, Parsec String [String] Bool)
-> StreamPermParser
String
[String]
(Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (Bool, Parsec String [String] Bool)
pLowerOnStart StreamPermParser
String
[String]
(Bool
-> String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (Bool, Parsec String [String] Bool)
-> StreamPermParser
String
[String]
(String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (Bool, Parsec String [String] Bool)
pPersistent StreamPermParser
String
[String]
(String
-> [Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> (String, ParsecT String [String] Identity String)
-> StreamPermParser
String
[String]
([Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (String, ParsecT String [String] Identity String)
pIconRoot
StreamPermParser
String
[String]
([Runnable]
-> String
-> String
-> String
-> Bool
-> SignalChan
-> Double
-> Config)
-> ([Runnable], Parsec String [String] [Runnable])
-> StreamPermParser
String
[String]
(String
-> String -> String -> Bool -> SignalChan -> Double -> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> ([Runnable], Parsec String [String] [Runnable])
pCommands StreamPermParser
String
[String]
(String
-> String -> String -> Bool -> SignalChan -> Double -> Config)
-> (String, ParsecT String [String] Identity String)
-> StreamPermParser
String
[String]
(String -> String -> Bool -> SignalChan -> Double -> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (String, ParsecT String [String] Identity String)
pSepChar StreamPermParser
String
[String]
(String -> String -> Bool -> SignalChan -> Double -> Config)
-> (String, ParsecT String [String] Identity String)
-> StreamPermParser
String [String] (String -> Bool -> SignalChan -> Double -> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (String, ParsecT String [String] Identity String)
pAlignSep StreamPermParser
String [String] (String -> Bool -> SignalChan -> Double -> Config)
-> (String, ParsecT String [String] Identity String)
-> StreamPermParser
String [String] (Bool -> SignalChan -> Double -> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (String, ParsecT String [String] Identity String)
pTemplate
StreamPermParser
String [String] (Bool -> SignalChan -> Double -> Config)
-> (Bool, Parsec String [String] Bool)
-> StreamPermParser
String [String] (SignalChan -> Double -> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (Bool, Parsec String [String] Bool)
pVerbose StreamPermParser String [String] (SignalChan -> Double -> Config)
-> (SignalChan, Parsec String [String] SignalChan)
-> StreamPermParser String [String] (Double -> Config)
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (SignalChan, Parsec String [String] SignalChan)
forall {b}. (SignalChan, ParsecT String [String] Identity b)
pSignal StreamPermParser String [String] (Double -> Config)
-> (Double, Parsec String [String] Double)
-> StreamPermParser String [String] Config
forall s tok st a b.
Stream s Identity tok =>
StreamPermParser s st (a -> b)
-> (a, Parsec s st a) -> StreamPermParser s st b
<|?> (Double, Parsec String [String] Double)
pDpi
fields :: [String]
fields = [ String
"font", String
"additionalFonts", String
"bgColor", String
"fgColor"
, String
"wmClass", String
"wmName", String
"sepChar"
, String
"alignSep" , String
"border", String
"borderColor" ,String
"template"
, String
"position" , String
"textOffset", String
"textOffsets", String
"iconOffset"
, String
"allDesktops", String
"overrideRedirect", String
"pickBroadest"
, String
"hideOnStart", String
"lowerOnStart", String
"persistent", String
"iconRoot"
, String
"alpha", String
"commands", String
"verbose", String
"signal", String
"textOutput"
, String
"textOutputFormat", String
"dpi"
]
pTextOutput :: (Bool, Parsec String [String] Bool)
pTextOutput = (Config -> Bool) -> String -> (Bool, Parsec String [String] Bool)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> Bool
textOutput String
"textOutput"
pTextOutputFormat :: (TextOutputFormat, Parsec String [String] TextOutputFormat)
pTextOutputFormat = (Config -> TextOutputFormat)
-> String
-> (TextOutputFormat, Parsec String [String] TextOutputFormat)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> TextOutputFormat
textOutputFormat String
"textOutputFormat"
pFont :: (String, ParsecT String [String] Identity String)
pFont = (Config -> String)
-> String -> (String, ParsecT String [String] Identity String)
forall {a}.
(Config -> a)
-> String -> (a, ParsecT String [String] Identity String)
strField Config -> String
font String
"font"
pFontList :: ([String], ParsecT String [String] Identity [String])
pFontList = (Config -> [String])
-> String -> ([String], ParsecT String [String] Identity [String])
forall {a}.
(Config -> a)
-> String -> (a, ParsecT String [String] Identity [String])
strListField Config -> [String]
additionalFonts String
"additionalFonts"
pWmClass :: (String, ParsecT String [String] Identity String)
pWmClass = (Config -> String)
-> String -> (String, ParsecT String [String] Identity String)
forall {a}.
(Config -> a)
-> String -> (a, ParsecT String [String] Identity String)
strField Config -> String
wmClass String
"wmClass"
pWmName :: (String, ParsecT String [String] Identity String)
pWmName = (Config -> String)
-> String -> (String, ParsecT String [String] Identity String)
forall {a}.
(Config -> a)
-> String -> (a, ParsecT String [String] Identity String)
strField Config -> String
wmName String
"wmName"
pBgColor :: (String, ParsecT String [String] Identity String)
pBgColor = (Config -> String)
-> String -> (String, ParsecT String [String] Identity String)
forall {a}.
(Config -> a)
-> String -> (a, ParsecT String [String] Identity String)
strField Config -> String
bgColor String
"bgColor"
pFgColor :: (String, ParsecT String [String] Identity String)
pFgColor = (Config -> String)
-> String -> (String, ParsecT String [String] Identity String)
forall {a}.
(Config -> a)
-> String -> (a, ParsecT String [String] Identity String)
strField Config -> String
fgColor String
"fgColor"
pBdColor :: (String, ParsecT String [String] Identity String)
pBdColor = (Config -> String)
-> String -> (String, ParsecT String [String] Identity String)
forall {a}.
(Config -> a)
-> String -> (a, ParsecT String [String] Identity String)
strField Config -> String
borderColor String
"borderColor"
pSepChar :: (String, ParsecT String [String] Identity String)
pSepChar = (Config -> String)
-> String -> (String, ParsecT String [String] Identity String)
forall {a}.
(Config -> a)
-> String -> (a, ParsecT String [String] Identity String)
strField Config -> String
sepChar String
"sepChar"
pAlignSep :: (String, ParsecT String [String] Identity String)
pAlignSep = (Config -> String)
-> String -> (String, ParsecT String [String] Identity String)
forall {a}.
(Config -> a)
-> String -> (a, ParsecT String [String] Identity String)
strField Config -> String
alignSep String
"alignSep"
pTemplate :: (String, ParsecT String [String] Identity String)
pTemplate = (Config -> String)
-> String -> (String, ParsecT String [String] Identity String)
forall {a}.
(Config -> a)
-> String -> (a, ParsecT String [String] Identity String)
strField Config -> String
template String
"template"
pTextOffset :: (FontIndex, Parsec String [String] FontIndex)
pTextOffset = (Config -> FontIndex)
-> String -> (FontIndex, Parsec String [String] FontIndex)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> FontIndex
textOffset String
"textOffset"
pTextOffsets :: ([FontIndex], Parsec String [String] [FontIndex])
pTextOffsets = (Config -> [FontIndex])
-> String -> ([FontIndex], Parsec String [String] [FontIndex])
forall {a}.
(Config -> a) -> String -> (a, Parsec String [String] [FontIndex])
readIntList Config -> [FontIndex]
textOffsets String
"textOffsets"
pIconOffset :: (FontIndex, Parsec String [String] FontIndex)
pIconOffset = (Config -> FontIndex)
-> String -> (FontIndex, Parsec String [String] FontIndex)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> FontIndex
iconOffset String
"iconOffset"
pPosition :: (XPosition, Parsec String [String] XPosition)
pPosition = (Config -> XPosition)
-> String -> (XPosition, Parsec String [String] XPosition)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> XPosition
position String
"position"
pHideOnStart :: (Bool, Parsec String [String] Bool)
pHideOnStart = (Config -> Bool) -> String -> (Bool, Parsec String [String] Bool)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> Bool
hideOnStart String
"hideOnStart"
pLowerOnStart :: (Bool, Parsec String [String] Bool)
pLowerOnStart = (Config -> Bool) -> String -> (Bool, Parsec String [String] Bool)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> Bool
lowerOnStart String
"lowerOnStart"
pPersistent :: (Bool, Parsec String [String] Bool)
pPersistent = (Config -> Bool) -> String -> (Bool, Parsec String [String] Bool)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> Bool
persistent String
"persistent"
pBorder :: (Border, Parsec String [String] Border)
pBorder = (Config -> Border)
-> String -> (Border, Parsec String [String] Border)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> Border
border String
"border"
pBdWidth :: (FontIndex, Parsec String [String] FontIndex)
pBdWidth = (Config -> FontIndex)
-> String -> (FontIndex, Parsec String [String] FontIndex)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> FontIndex
borderWidth String
"borderWidth"
pAllDesktops :: (Bool, Parsec String [String] Bool)
pAllDesktops = (Config -> Bool) -> String -> (Bool, Parsec String [String] Bool)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> Bool
allDesktops String
"allDesktops"
pOverrideRedirect :: (Bool, Parsec String [String] Bool)
pOverrideRedirect = (Config -> Bool) -> String -> (Bool, Parsec String [String] Bool)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> Bool
overrideRedirect String
"overrideRedirect"
pPickBroadest :: (Bool, Parsec String [String] Bool)
pPickBroadest = (Config -> Bool) -> String -> (Bool, Parsec String [String] Bool)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> Bool
pickBroadest String
"pickBroadest"
pIconRoot :: (String, ParsecT String [String] Identity String)
pIconRoot = (Config -> String)
-> String -> (String, ParsecT String [String] Identity String)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> String
iconRoot String
"iconRoot"
pAlpha :: (FontIndex, Parsec String [String] FontIndex)
pAlpha = (Config -> FontIndex)
-> String -> (FontIndex, Parsec String [String] FontIndex)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> FontIndex
alpha String
"alpha"
pVerbose :: (Bool, Parsec String [String] Bool)
pVerbose = (Config -> Bool) -> String -> (Bool, Parsec String [String] Bool)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> Bool
verbose String
"verbose"
pDpi :: (Double, Parsec String [String] Double)
pDpi = (Config -> Double)
-> String -> (Double, Parsec String [String] Double)
forall {b} {a}.
Read b =>
(Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> Double
dpi String
"dpi"
pSignal :: (SignalChan, ParsecT String [String] Identity b)
pSignal = (Config -> SignalChan)
-> String
-> ParsecT String [String] Identity b
-> (SignalChan, ParsecT String [String] Identity b)
forall {a} {b}.
(Config -> a)
-> String
-> ParsecT String [String] Identity b
-> (a, ParsecT String [String] Identity b)
field Config -> SignalChan
signal String
"signal" (ParsecT String [String] Identity b
-> (SignalChan, ParsecT String [String] Identity b))
-> ParsecT String [String] Identity b
-> (SignalChan, ParsecT String [String] Identity b)
forall a b. (a -> b) -> a -> b
$
String -> ParsecT String [String] Identity b
forall a. String -> ParsecT String [String] Identity a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"signal is meant for use with Xmobar as a library.\n It is not meant for use in the configuration file."
pCommands :: ([Runnable], Parsec String [String] [Runnable])
pCommands = (Config -> [Runnable])
-> String
-> Parsec String [String] [Runnable]
-> ([Runnable], Parsec String [String] [Runnable])
forall {a} {b}.
(Config -> a)
-> String
-> ParsecT String [String] Identity b
-> (a, ParsecT String [String] Identity b)
field Config -> [Runnable]
commands String
"commands" Parsec String [String] [Runnable]
forall {u}. ParsecT String u Identity [Runnable]
readCommands
staticPos :: ParsecT String u Identity String
staticPos = do String -> ParsecT String u Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"Static"
ParsecT String u Identity String
-> ParsecT String u Identity String
forall {s} {m :: * -> *} {u} {b}.
Stream s m Char =>
ParsecT s u m b -> ParsecT s u m b
wrapSkip (String -> ParsecT String u Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"{")
p <- ParsecT String u Identity Char -> ParsecT String u Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (String -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
"}")
wrapSkip (string "}")
string ","
return ("Static {" ++ p ++ "}")
tillFieldEnd :: ParsecT String u Identity String
tillFieldEnd = ParsecT String u Identity String
forall {u}. ParsecT String u Identity String
staticPos ParsecT String u Identity String
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity Char -> ParsecT String u Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (String -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
",}\n\r")
commandsEnd :: ParsecT String u Identity String
commandsEnd = ParsecT String u Identity String
-> ParsecT String u Identity String
forall {s} {m :: * -> *} {u} {b}.
Stream s m Char =>
ParsecT s u m b -> ParsecT s u m b
wrapSkip (String -> ParsecT String u Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"]") ParsecT String u Identity String
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall a b.
ParsecT String u Identity a
-> ParsecT String u Identity b -> ParsecT String u Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (String -> ParsecT String u Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"}" ParsecT String u Identity String
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity String
forall {u}. ParsecT String u Identity String
notNextRun)
notNextRun :: ParsecT String u Identity String
notNextRun = do {String -> ParsecT String u Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
","
; ParsecT String u Identity String -> ParsecT String u Identity ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (ParsecT String u Identity String -> ParsecT String u Identity ())
-> ParsecT String u Identity String -> ParsecT String u Identity ()
forall a b. (a -> b) -> a -> b
$ ParsecT String u Identity String
-> ParsecT String u Identity String
forall {s} {m :: * -> *} {u} {b}.
Stream s m Char =>
ParsecT s u m b -> ParsecT s u m b
wrapSkip (ParsecT String u Identity String
-> ParsecT String u Identity String)
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String u Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"Run"
; String -> ParsecT String u Identity String
forall a. a -> ParsecT String u Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return String
","
}
readCommands :: ParsecT String u Identity [Runnable]
readCommands = ParsecT String u Identity Char
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT String u Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParsecT String u Identity String
-> ParsecT String u Identity String
forall tok st a. GenParser tok st a -> GenParser tok st a
try ParsecT String u Identity String
forall {u}. ParsecT String u Identity String
commandsEnd) ParsecT String u Identity String
-> (String -> ParsecT String u Identity [Runnable])
-> ParsecT String u Identity [Runnable]
forall a b.
ParsecT String u Identity a
-> (a -> ParsecT String u Identity b)
-> ParsecT String u Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
String -> String -> ParsecT String u Identity [Runnable]
forall {a} {m :: * -> *}.
(Read a, MonadFail m) =>
String -> String -> m a
read' String
commandsErr (String -> ParsecT String u Identity [Runnable])
-> (String -> String)
-> String
-> ParsecT String u Identity [Runnable]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> String -> String) -> String -> String -> String
forall a b c. (a -> b -> c) -> b -> a -> c
flip String -> String -> String
forall a. [a] -> [a] -> [a]
(++) String
"]"
strField :: (Config -> a)
-> String -> (a, ParsecT String [String] Identity String)
strField Config -> a
e String
n = (Config -> a)
-> String
-> ParsecT String [String] Identity String
-> (a, ParsecT String [String] Identity String)
forall {a} {b}.
(Config -> a)
-> String
-> ParsecT String [String] Identity b
-> (a, ParsecT String [String] Identity b)
field Config -> a
e String
n ParsecT String [String] Identity String
forall {u}. ParsecT String u Identity String
strMulti
strMulti :: ParsecT String u Identity String
strMulti = Char -> ParsecT String u Identity String
forall {u}. Char -> ParsecT String u Identity String
scan Char
'"'
where
scan :: Char -> ParsecT String u Identity String
scan Char
lead = do
ParsecT String u Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
lead
s <- ParsecT String u Identity Char
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT String u Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParsecT String u Identity String
forall {u}. ParsecT String u Identity String
rowCont ParsecT String u Identity String
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String u Identity String
forall {u}. ParsecT String u Identity String
unescQuote)
(char '"' >> return s) <|> fmap (s ++) (scan '\\')
rowCont :: GenParser Char st String
rowCont = GenParser Char st String -> GenParser Char st String
forall tok st a. GenParser tok st a -> GenParser tok st a
try (GenParser Char st String -> GenParser Char st String)
-> GenParser Char st String -> GenParser Char st String
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\\' ParsecT String st Identity Char
-> GenParser Char st String -> GenParser Char st String
forall a b.
ParsecT String st Identity a
-> ParsecT String st Identity b -> ParsecT String st Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> GenParser Char st String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"\n"
unescQuote :: ParsecT String u Identity String
unescQuote = ParsecT String u Identity Char -> ParsecT String u Identity Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (String -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
"\\") ParsecT String u Identity Char
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall a b.
ParsecT String u Identity a
-> ParsecT String u Identity b -> ParsecT String u Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String u Identity String
-> ParsecT String u Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (String -> ParsecT String u Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"\"")
strListField :: (Config -> a)
-> String -> (a, ParsecT String [String] Identity [String])
strListField Config -> a
e String
n = (Config -> a)
-> String
-> ParsecT String [String] Identity [String]
-> (a, ParsecT String [String] Identity [String])
forall {a} {b}.
(Config -> a)
-> String
-> ParsecT String [String] Identity b
-> (a, ParsecT String [String] Identity b)
field Config -> a
e String
n ParsecT String [String] Identity [String]
forall {u}. ParsecT String u Identity [String]
strList
strList :: ParsecT String u Identity [String]
strList = do
ParsecT String u Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'['
list <- ParsecT String u Identity String
-> ParsecT String u Identity Char
-> ParsecT String u Identity [String]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
sepBy (ParsecT String u Identity String
forall {u}. ParsecT String u Identity String
strMulti ParsecT String u Identity String
-> (String -> ParsecT String u Identity String)
-> ParsecT String u Identity String
forall a b.
ParsecT String u Identity a
-> (a -> ParsecT String u Identity b)
-> ParsecT String u Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \String
x -> ParsecT String u Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces ParsecT String u Identity ()
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall a b.
ParsecT String u Identity a
-> ParsecT String u Identity b -> ParsecT String u Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> ParsecT String u Identity String
forall a. a -> ParsecT String u Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return String
x) (Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
',')
spaces
char ']'
return list
wrapSkip :: ParsecT s u m b -> ParsecT s u m b
wrapSkip ParsecT s u m b
x = ParsecT s u m Char -> ParsecT s u m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT s u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
space ParsecT s u m String -> ParsecT s u m b -> ParsecT s u m b
forall a b. ParsecT s u m a -> ParsecT s u m b -> ParsecT s u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT s u m b
x ParsecT s u m b -> (b -> ParsecT s u m b) -> ParsecT s u m b
forall a b.
ParsecT s u m a -> (a -> ParsecT s u m b) -> ParsecT s u m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \b
r -> ParsecT s u m Char -> ParsecT s u m String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT s u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
space ParsecT s u m String -> ParsecT s u m b -> ParsecT s u m b
forall a b. ParsecT s u m a -> ParsecT s u m b -> ParsecT s u m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> b -> ParsecT s u m b
forall a. a -> ParsecT s u m a
forall (m :: * -> *) a. Monad m => a -> m a
return b
r
sepEndSpc :: [String] -> ParsecT String u Identity ()
sepEndSpc = (String -> ParsecT String u Identity String)
-> [String] -> ParsecT String u Identity ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (ParsecT String u Identity String
-> ParsecT String u Identity String
forall {s} {m :: * -> *} {u} {b}.
Stream s m Char =>
ParsecT s u m b -> ParsecT s u m b
wrapSkip (ParsecT String u Identity String
-> ParsecT String u Identity String)
-> (String -> ParsecT String u Identity String)
-> String
-> ParsecT String u Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsecT String u Identity String
-> ParsecT String u Identity String
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT String u Identity String
-> ParsecT String u Identity String)
-> (String -> ParsecT String u Identity String)
-> String
-> ParsecT String u Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ParsecT String u Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string)
fieldEnd :: ParsecT String u Identity String
fieldEnd = ParsecT String u Identity Char -> ParsecT String u Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT String u Identity Char
-> ParsecT String u Identity String)
-> ParsecT String u Identity Char
-> ParsecT String u Identity String
forall a b. (a -> b) -> a -> b
$ ParsecT String u Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
space ParsecT String u Identity Char
-> ParsecT String u Identity Char -> ParsecT String u Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> String -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
",}"
field :: (Config -> a)
-> String
-> ParsecT String [String] Identity b
-> (a, ParsecT String [String] Identity b)
field Config -> a
e String
n ParsecT String [String] Identity b
c = (,) (Config -> a
e Config
defaultConfig) (ParsecT String [String] Identity b
-> (a, ParsecT String [String] Identity b))
-> ParsecT String [String] Identity b
-> (a, ParsecT String [String] Identity b)
forall a b. (a -> b) -> a -> b
$
([String] -> [String]) -> ParsecT String [String] Identity ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((String -> Bool) -> [String] -> [String]
forall a. (a -> Bool) -> [a] -> [a]
filter (String -> String -> Bool
forall a. Eq a => a -> a -> Bool
/= String
n)) ParsecT String [String] Identity ()
-> ParsecT String [String] Identity ()
-> ParsecT String [String] Identity ()
forall a b.
ParsecT String [String] Identity a
-> ParsecT String [String] Identity b
-> ParsecT String [String] Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [String] -> ParsecT String [String] Identity ()
forall {u}. [String] -> ParsecT String u Identity ()
sepEndSpc [String
n,String
"="] ParsecT String [String] Identity ()
-> ParsecT String [String] Identity b
-> ParsecT String [String] Identity b
forall a b.
ParsecT String [String] Identity a
-> ParsecT String [String] Identity b
-> ParsecT String [String] Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
ParsecT String [String] Identity b
-> ParsecT String [String] Identity b
forall {s} {m :: * -> *} {u} {b}.
Stream s m Char =>
ParsecT s u m b -> ParsecT s u m b
wrapSkip ParsecT String [String] Identity b
c ParsecT String [String] Identity b
-> (b -> ParsecT String [String] Identity b)
-> ParsecT String [String] Identity b
forall a b.
ParsecT String [String] Identity a
-> (a -> ParsecT String [String] Identity b)
-> ParsecT String [String] Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \b
r -> ParsecT String [String] Identity String
forall {u}. ParsecT String u Identity String
fieldEnd ParsecT String [String] Identity String
-> ParsecT String [String] Identity b
-> ParsecT String [String] Identity b
forall a b.
ParsecT String [String] Identity a
-> ParsecT String [String] Identity b
-> ParsecT String [String] Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> b -> ParsecT String [String] Identity b
forall a. a -> ParsecT String [String] Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return b
r
readField :: (Config -> a) -> String -> (a, ParsecT String [String] Identity b)
readField Config -> a
a String
n = (Config -> a)
-> String
-> ParsecT String [String] Identity b
-> (a, ParsecT String [String] Identity b)
forall {a} {b}.
(Config -> a)
-> String
-> ParsecT String [String] Identity b
-> (a, ParsecT String [String] Identity b)
field Config -> a
a String
n (ParsecT String [String] Identity b
-> (a, ParsecT String [String] Identity b))
-> ParsecT String [String] Identity b
-> (a, ParsecT String [String] Identity b)
forall a b. (a -> b) -> a -> b
$ ParsecT String [String] Identity String
forall {u}. ParsecT String u Identity String
tillFieldEnd ParsecT String [String] Identity String
-> (String -> ParsecT String [String] Identity b)
-> ParsecT String [String] Identity b
forall a b.
ParsecT String [String] Identity a
-> (a -> ParsecT String [String] Identity b)
-> ParsecT String [String] Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> String -> ParsecT String [String] Identity b
forall {a} {m :: * -> *}.
(Read a, MonadFail m) =>
String -> String -> m a
read' String
n
readIntList :: (Config -> a) -> String -> (a, Parsec String [String] [FontIndex])
readIntList Config -> a
d String
n = (Config -> a)
-> String
-> Parsec String [String] [FontIndex]
-> (a, Parsec String [String] [FontIndex])
forall {a} {b}.
(Config -> a)
-> String
-> ParsecT String [String] Identity b
-> (a, ParsecT String [String] Identity b)
field Config -> a
d String
n Parsec String [String] [FontIndex]
forall {u}. ParsecT String u Identity [FontIndex]
intList
intList :: ParsecT String u Identity [FontIndex]
intList = do
ParsecT String u Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'['
list <- ParsecT String u Identity FontIndex
-> ParsecT String u Identity Char
-> ParsecT String u Identity [FontIndex]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
sepBy (ParsecT String u Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces ParsecT String u Identity ()
-> ParsecT String u Identity FontIndex
-> ParsecT String u Identity FontIndex
forall a b.
ParsecT String u Identity a
-> ParsecT String u Identity b -> ParsecT String u Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String u Identity FontIndex
forall i st. Integral i => CharParser st i
int ParsecT String u Identity FontIndex
-> (FontIndex -> ParsecT String u Identity FontIndex)
-> ParsecT String u Identity FontIndex
forall a b.
ParsecT String u Identity a
-> (a -> ParsecT String u Identity b)
-> ParsecT String u Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \FontIndex
x-> ParsecT String u Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces ParsecT String u Identity ()
-> ParsecT String u Identity FontIndex
-> ParsecT String u Identity FontIndex
forall a b.
ParsecT String u Identity a
-> ParsecT String u Identity b -> ParsecT String u Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FontIndex -> ParsecT String u Identity FontIndex
forall a. a -> ParsecT String u Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return FontIndex
x) (Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
',')
spaces
char ']'
return list
read' :: String -> String -> m a
read' String
d String
s = case ReadS a
forall a. Read a => ReadS a
reads String
s of
[(a
x, String
_)] -> a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x
[(a, String)]
_ -> String -> m a
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m a) -> String -> m a
forall a b. (a -> b) -> a -> b
$ String
"error reading the " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
d String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" field: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s
commandsErr :: String
commandsErr :: String
commandsErr = String
"commands: this usually means that a command could not" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"\nbe parsed." String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"\nThe error could be located at the begining of the command" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"\nwhich follows the offending one."
readConfig :: Config -> FilePath -> IO (Either ParseError (Config,[String]))
readConfig :: Config -> String -> IO (Either ParseError (Config, [String]))
readConfig Config
defaultConfig String
f =
IO String -> IO String
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String -> IO String
S.readFile String
f) IO String
-> (String -> Either ParseError (Config, [String]))
-> IO (Either ParseError (Config, [String]))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> Config -> String -> Either ParseError (Config, [String])
parseConfig Config
defaultConfig
indexedFont :: Config -> FontIndex -> String
indexedFont :: Config -> FontIndex -> String
indexedFont Config
config FontIndex
idx =
if FontIndex
idx FontIndex -> FontIndex -> Bool
forall a. Ord a => a -> a -> Bool
< FontIndex
1 Bool -> Bool -> Bool
|| FontIndex
idx FontIndex -> FontIndex -> Bool
forall a. Ord a => a -> a -> Bool
> [String] -> FontIndex
forall a. [a] -> FontIndex
forall (t :: * -> *) a. Foldable t => t a -> FontIndex
length (Config -> [String]
additionalFonts Config
config)
then Config -> String
font Config
config else Config -> [String]
additionalFonts Config
config [String] -> FontIndex -> String
forall a. HasCallStack => [a] -> FontIndex -> a
!! (FontIndex
idx FontIndex -> FontIndex -> FontIndex
forall a. Num a => a -> a -> a
- FontIndex
1)
indexedOffset :: Config -> FontIndex -> Int
indexedOffset :: Config -> FontIndex -> FontIndex
indexedOffset Config
config FontIndex
idx =
if FontIndex
idx FontIndex -> FontIndex -> Bool
forall a. Ord a => a -> a -> Bool
< FontIndex
1 Bool -> Bool -> Bool
|| FontIndex
idx FontIndex -> FontIndex -> Bool
forall a. Ord a => a -> a -> Bool
> [FontIndex] -> FontIndex
forall a. [a] -> FontIndex
forall (t :: * -> *) a. Foldable t => t a -> FontIndex
length (Config -> [FontIndex]
textOffsets Config
config)
then Config -> FontIndex
textOffset Config
config else Config -> [FontIndex]
textOffsets Config
config [FontIndex] -> FontIndex -> FontIndex
forall a. HasCallStack => [a] -> FontIndex -> a
!! (FontIndex
idx FontIndex -> FontIndex -> FontIndex
forall a. Num a => a -> a -> a
- FontIndex
1)