module Network.MoHWS.Configuration.Parser (
T, lift, run, field, set, addToList,
stringLiteral, bool, int,
) where
import qualified Network.MoHWS.Configuration.Accessor as ConfigA
import qualified Network.MoHWS.Configuration as Config
import Network.MoHWS.ParserUtility (countBetween, )
import Control.Monad (liftM2, )
import Network.MoHWS.Utility (readM, )
import Text.ParserCombinators.Parsec
(GenParser, ParseError, parseFromFile,
(<|>), choice, many, option, try,
char, digit, eof, )
import Text.ParserCombinators.Parsec.Language
(LanguageDef, emptyDef, commentLine, nestedComments,
reservedOpNames, reservedNames, caseSensitive, )
import qualified Text.ParserCombinators.Parsec.Token as Token
import qualified Data.Set as Set
import qualified Data.Accessor.Basic as Accessor
type T st ext = GenParser Char st (Builder ext)
type Builder ext = Config.T ext -> Config.T ext
lift ::
Accessor.T fullExt partExt ->
T st partExt -> T st fullExt
lift :: T fullExt partExt -> T st partExt -> T st fullExt
lift T fullExt partExt
act =
((T partExt -> T partExt) -> T fullExt -> T fullExt)
-> T st partExt -> T st fullExt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\T partExt -> T partExt
build T fullExt
c ->
(partExt -> fullExt) -> T partExt -> T fullExt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((partExt -> fullExt -> fullExt) -> fullExt -> partExt -> fullExt
forall a b c. (a -> b -> c) -> b -> a -> c
flip (T fullExt partExt -> partExt -> fullExt -> fullExt
forall r a. T r a -> a -> r -> r
Accessor.set T fullExt partExt
act) (T fullExt -> fullExt
forall ext. T ext -> ext
Config.extension T fullExt
c)) (T partExt -> T fullExt) -> T partExt -> T fullExt
forall a b. (a -> b) -> a -> b
$
T partExt -> T partExt
build (T partExt -> T partExt) -> T partExt -> T partExt
forall a b. (a -> b) -> a -> b
$
(fullExt -> partExt) -> T fullExt -> T partExt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (T fullExt partExt -> fullExt -> partExt
forall r a. T r a -> r -> a
Accessor.get T fullExt partExt
act) T fullExt
c)
field :: String -> T st ext -> T st ext
field :: String -> T st ext -> T st ext
field String
keyword T st ext
parser =
GenTokenParser String st Identity
-> String -> ParsecT String st Identity ()
forall s u (m :: * -> *).
GenTokenParser s u m -> String -> ParsecT s u m ()
Token.reserved GenTokenParser String st Identity
forall st. TokenParser st
p String
keyword ParsecT String st Identity () -> T st ext -> T st ext
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> T st ext
parser
p :: Token.TokenParser st
p :: TokenParser st
p = GenLanguageDef String st Identity -> TokenParser st
forall s (m :: * -> *) u.
Stream s m Char =>
GenLanguageDef s u m -> GenTokenParser s u m
Token.makeTokenParser GenLanguageDef String st Identity
forall st. LanguageDef st
tokenDef
stringLiteral :: GenParser Char st String
stringLiteral :: GenParser Char st String
stringLiteral = GenTokenParser String st Identity -> GenParser Char st String
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
Token.stringLiteral GenTokenParser String st Identity
forall st. TokenParser st
p
bool :: GenParser Char st Bool
bool :: GenParser Char st Bool
bool = ( GenTokenParser String st Identity
-> String -> ParsecT String st Identity ()
forall s u (m :: * -> *).
GenTokenParser s u m -> String -> ParsecT s u m ()
Token.reserved GenTokenParser String st Identity
forall st. TokenParser st
p String
"On" ParsecT String st Identity ()
-> GenParser Char st Bool -> GenParser Char st Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> GenParser Char st Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True )
GenParser Char st Bool
-> GenParser Char st Bool -> GenParser Char st Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ( GenTokenParser String st Identity
-> String -> ParsecT String st Identity ()
forall s u (m :: * -> *).
GenTokenParser s u m -> String -> ParsecT s u m ()
Token.reserved GenTokenParser String st Identity
forall st. TokenParser st
p String
"Off" ParsecT String st Identity ()
-> GenParser Char st Bool -> GenParser Char st Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> GenParser Char st Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False )
int :: GenParser Char st Int
int :: GenParser Char st Int
int = (Integer -> Int)
-> ParsecT String st Identity Integer -> GenParser Char st Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Int
forall a. Num a => Integer -> a
fromInteger (ParsecT String st Identity Integer -> GenParser Char st Int)
-> ParsecT String st Identity Integer -> GenParser Char st Int
forall a b. (a -> b) -> a -> b
$ GenTokenParser String st Identity
-> ParsecT String st Identity Integer
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
Token.integer GenTokenParser String st Identity
forall st. TokenParser st
p
tokenDef :: LanguageDef st
tokenDef :: LanguageDef st
tokenDef =
LanguageDef st
forall st. LanguageDef st
emptyDef {
commentLine :: String
commentLine = String
"#",
nestedComments :: Bool
nestedComments = Bool
False,
reservedOpNames :: [String]
reservedOpNames = [],
reservedNames :: [String]
reservedNames = [],
caseSensitive :: Bool
caseSensitive = Bool
False
}
run :: T () ext -> String -> IO (Either ParseError (Builder ext))
run :: T () ext -> String -> IO (Either ParseError (Builder ext))
run T () ext
parseExt String
fname =
T () ext -> String -> IO (Either ParseError (Builder ext))
forall a. Parser a -> String -> IO (Either ParseError a)
parseFromFile (T () ext -> T () ext
forall st ext. T st ext -> T st ext
configParser T () ext
parseExt) String
fname
configParser :: T st ext -> T st ext
configParser :: T st ext -> T st ext
configParser T st ext
parseExt = do
GenTokenParser String st Identity -> ParsecT String st Identity ()
forall s u (m :: * -> *). GenTokenParser s u m -> ParsecT s u m ()
Token.whiteSpace GenTokenParser String st Identity
forall st. TokenParser st
p
[Builder ext]
cs <- T st ext -> ParsecT String st Identity [Builder ext]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (T st ext -> ParsecT String st Identity [Builder ext])
-> T st ext -> ParsecT String st Identity [Builder ext]
forall a b. (a -> b) -> a -> b
$ T st ext
parseExt T st ext -> T st ext -> T st ext
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> T st ext
forall st ext. T st ext
configLine
ParsecT String st Identity ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
Builder ext -> T st ext
forall (m :: * -> *) a. Monad m => a -> m a
return (Builder ext
forall ext. Builder ext
fixConfig Builder ext -> Builder ext -> Builder ext
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Builder ext -> Builder ext -> Builder ext)
-> Builder ext -> [Builder ext] -> Builder ext
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Builder ext -> Builder ext -> Builder ext
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) Builder ext
forall a. a -> a
id [Builder ext]
cs)
fixConfig :: Builder ext
fixConfig :: Builder ext
fixConfig T ext
conf =
let f :: [a] -> [a]
f [a]
xs = if [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1 then [a] -> [a]
forall a. [a] -> [a]
init [a]
xs else [a]
xs
in T (T ext) [(Maybe String, PortNumber)]
-> ([(Maybe String, PortNumber)] -> [(Maybe String, PortNumber)])
-> Builder ext
forall r a. T r a -> (a -> a) -> r -> r
Accessor.modify T (T ext) [(Maybe String, PortNumber)]
forall ext. T (T ext) [(Maybe String, PortNumber)]
ConfigA.listen [(Maybe String, PortNumber)] -> [(Maybe String, PortNumber)]
forall a. [a] -> [a]
f T ext
conf
configLine :: T st ext
configLine :: T st ext
configLine =
[T st ext] -> T st ext
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([T st ext] -> T st ext) -> [T st ext] -> T st ext
forall a b. (a -> b) -> a -> b
$
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"user" T st ext
forall st ext. T st ext
p_user) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"group" T st ext
forall st ext. T st ext
p_group) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"timeout" T st ext
forall st ext. T st ext
p_timeout) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"keepalivetimeout" T st ext
forall st ext. T st ext
p_keepAliveTimeout) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"maxclients" T st ext
forall st ext. T st ext
p_maxClients) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"listen" T st ext
forall st ext. T st ext
p_listen) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"serveradmin" T st ext
forall st ext. T st ext
p_serverAdmin) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"servername" T st ext
forall st ext. T st ext
p_serverName) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"serveralias" T st ext
forall st ext. T st ext
p_serverAlias) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"usecanonicalname" T st ext
forall st ext. T st ext
p_useCanonicalName) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"documentroot" T st ext
forall st ext. T st ext
p_documentRoot) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"accessfilename" T st ext
forall st ext. T st ext
p_accessFileName) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"followsymboliclinks" T st ext
forall st ext. T st ext
p_followSymbolicLinks) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"chunksize" T st ext
forall st ext. T st ext
p_chunkSize) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"typesconfig" T st ext
forall st ext. T st ext
p_typesConfig) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"defaulttype" T st ext
forall st ext. T st ext
p_defaultType) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"hostnamelookups" T st ext
forall st ext. T st ext
p_hostnameLookups) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"errorlog" T st ext
forall st ext. T st ext
p_errorLog) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"loglevel" T st ext
forall st ext. T st ext
p_logLevel) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"customlog" T st ext
forall st ext. T st ext
p_customLog) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"listen" T st ext
forall st ext. T st ext
p_listen) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"addlanguage" T st ext
forall st ext. T st ext
p_addLanguage) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
(String -> T st ext -> T st ext
forall st ext. String -> T st ext -> T st ext
field String
"languagepriority" T st ext
forall st ext. T st ext
p_languagePriority) T st ext -> [T st ext] -> [T st ext]
forall a. a -> [a] -> [a]
:
[]
set :: Accessor.T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set :: T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T r a
acc = (a -> r -> r) -> GenParser Char st a -> GenParser Char st (r -> r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (T r a -> a -> r -> r
forall r a. T r a -> a -> r -> r
Accessor.set T r a
acc)
addToList :: Accessor.T r [a] -> GenParser Char st a -> GenParser Char st (r -> r)
addToList :: T r [a] -> GenParser Char st a -> GenParser Char st (r -> r)
addToList T r [a]
acc = (a -> r -> r) -> GenParser Char st a -> GenParser Char st (r -> r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (T r [a] -> ([a] -> [a]) -> r -> r
forall r a. T r a -> (a -> a) -> r -> r
Accessor.modify T r [a]
acc (([a] -> [a]) -> r -> r) -> (a -> [a] -> [a]) -> a -> r -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:))
p_user :: T st ext
p_user :: T st ext
p_user = T (T ext) String -> GenParser Char st String -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) String
forall ext. T (T ext) String
ConfigA.user (GenParser Char st String -> T st ext)
-> GenParser Char st String -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st String
forall st. GenParser Char st String
stringLiteral
p_group :: T st ext
p_group :: T st ext
p_group = T (T ext) String -> GenParser Char st String -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) String
forall ext. T (T ext) String
ConfigA.group (GenParser Char st String -> T st ext)
-> GenParser Char st String -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st String
forall st. GenParser Char st String
stringLiteral
p_timeout :: T st ext
p_timeout :: T st ext
p_timeout = T (T ext) Int -> GenParser Char st Int -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) Int
forall ext. T (T ext) Int
ConfigA.requestTimeout (GenParser Char st Int -> T st ext)
-> GenParser Char st Int -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st Int
forall st. GenParser Char st Int
int
p_keepAliveTimeout :: T st ext
p_keepAliveTimeout :: T st ext
p_keepAliveTimeout = T (T ext) Int -> GenParser Char st Int -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) Int
forall ext. T (T ext) Int
ConfigA.keepAliveTimeout (GenParser Char st Int -> T st ext)
-> GenParser Char st Int -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st Int
forall st. GenParser Char st Int
int
p_maxClients :: T st ext
p_maxClients :: T st ext
p_maxClients = T (T ext) Int -> GenParser Char st Int -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) Int
forall ext. T (T ext) Int
ConfigA.maxClients (GenParser Char st Int -> T st ext)
-> GenParser Char st Int -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st Int
forall st. GenParser Char st Int
int
p_serverAdmin :: T st ext
p_serverAdmin :: T st ext
p_serverAdmin = T (T ext) String -> GenParser Char st String -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) String
forall ext. T (T ext) String
ConfigA.serverAdmin (GenParser Char st String -> T st ext)
-> GenParser Char st String -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st String
forall st. GenParser Char st String
stringLiteral
p_serverName :: T st ext
p_serverName :: T st ext
p_serverName = T (T ext) String -> GenParser Char st String -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) String
forall ext. T (T ext) String
ConfigA.serverName (GenParser Char st String -> T st ext)
-> GenParser Char st String -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st String
forall st. GenParser Char st String
stringLiteral
p_serverAlias :: T st ext
p_serverAlias :: T st ext
p_serverAlias = (String -> T ext -> T ext)
-> ParsecT String st Identity String -> T st ext
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (T (T ext) (Set String)
-> (Set String -> Set String) -> T ext -> T ext
forall r a. T r a -> (a -> a) -> r -> r
Accessor.modify T (T ext) (Set String)
forall ext. T (T ext) (Set String)
ConfigA.serverAlias ((Set String -> Set String) -> T ext -> T ext)
-> (String -> Set String -> Set String) -> String -> T ext -> T ext
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Set String -> Set String
forall a. Ord a => a -> Set a -> Set a
Set.insert) (ParsecT String st Identity String -> T st ext)
-> ParsecT String st Identity String -> T st ext
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity String
forall st. GenParser Char st String
stringLiteral
p_useCanonicalName :: T st ext
p_useCanonicalName :: T st ext
p_useCanonicalName = T (T ext) Bool -> GenParser Char st Bool -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) Bool
forall ext. T (T ext) Bool
ConfigA.useCanonicalName (GenParser Char st Bool -> T st ext)
-> GenParser Char st Bool -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st Bool
forall st. GenParser Char st Bool
bool
p_documentRoot :: T st ext
p_documentRoot :: T st ext
p_documentRoot = T (T ext) String -> GenParser Char st String -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) String
forall ext. T (T ext) String
ConfigA.documentRoot (GenParser Char st String -> T st ext)
-> GenParser Char st String -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st String
forall st. GenParser Char st String
stringLiteral
p_accessFileName :: T st ext
p_accessFileName :: T st ext
p_accessFileName = T (T ext) String -> GenParser Char st String -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) String
forall ext. T (T ext) String
ConfigA.accessFileName (GenParser Char st String -> T st ext)
-> GenParser Char st String -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st String
forall st. GenParser Char st String
stringLiteral
p_followSymbolicLinks :: T st ext
p_followSymbolicLinks :: T st ext
p_followSymbolicLinks = T (T ext) Bool -> GenParser Char st Bool -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) Bool
forall ext. T (T ext) Bool
ConfigA.followSymbolicLinks (GenParser Char st Bool -> T st ext)
-> GenParser Char st Bool -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st Bool
forall st. GenParser Char st Bool
bool
p_chunkSize :: T st ext
p_chunkSize :: T st ext
p_chunkSize = T (T ext) Int -> GenParser Char st Int -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) Int
forall ext. T (T ext) Int
ConfigA.chunkSize (GenParser Char st Int -> T st ext)
-> GenParser Char st Int -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st Int
forall st. GenParser Char st Int
int
p_typesConfig :: T st ext
p_typesConfig :: T st ext
p_typesConfig = T (T ext) String -> GenParser Char st String -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) String
forall ext. T (T ext) String
ConfigA.typesConfig (GenParser Char st String -> T st ext)
-> GenParser Char st String -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st String
forall st. GenParser Char st String
stringLiteral
p_defaultType :: T st ext
p_defaultType :: T st ext
p_defaultType = T (T ext) String -> GenParser Char st String -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) String
forall ext. T (T ext) String
ConfigA.defaultType (GenParser Char st String -> T st ext)
-> GenParser Char st String -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st String
forall st. GenParser Char st String
stringLiteral
p_hostnameLookups :: T st ext
p_hostnameLookups :: T st ext
p_hostnameLookups = T (T ext) Bool -> GenParser Char st Bool -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) Bool
forall ext. T (T ext) Bool
ConfigA.hostnameLookups (GenParser Char st Bool -> T st ext)
-> GenParser Char st Bool -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st Bool
forall st. GenParser Char st Bool
bool
p_errorLog :: T st ext
p_errorLog :: T st ext
p_errorLog = T (T ext) String -> GenParser Char st String -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) String
forall ext. T (T ext) String
ConfigA.errorLogFile (GenParser Char st String -> T st ext)
-> GenParser Char st String -> T st ext
forall a b. (a -> b) -> a -> b
$ GenParser Char st String
forall st. GenParser Char st String
stringLiteral
p_logLevel :: T st ext
p_logLevel :: T st ext
p_logLevel = T (T ext) T -> GenParser Char st T -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) T
forall ext. T (T ext) T
ConfigA.logLevel (GenParser Char st T -> T st ext)
-> GenParser Char st T -> T st ext
forall a b. (a -> b) -> a -> b
$ GenTokenParser String st Identity
-> ParsecT String st Identity String
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
Token.identifier GenTokenParser String st Identity
forall st. TokenParser st
p ParsecT String st Identity String
-> (String -> GenParser Char st T) -> GenParser Char st T
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> GenParser Char st T
forall a (m :: * -> *). (Read a, MonadFail m) => String -> m a
readM
p_customLog :: T st ext
p_customLog :: T st ext
p_customLog =
T (T ext) [(String, String)]
-> GenParser Char st (String, String) -> T st ext
forall r a st.
T r [a] -> GenParser Char st a -> GenParser Char st (r -> r)
addToList T (T ext) [(String, String)]
forall ext. T (T ext) [(String, String)]
ConfigA.customLogs (GenParser Char st (String, String) -> T st ext)
-> GenParser Char st (String, String) -> T st ext
forall a b. (a -> b) -> a -> b
$
(String -> String -> (String, String))
-> ParsecT String st Identity String
-> ParsecT String st Identity String
-> GenParser Char st (String, String)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,) ParsecT String st Identity String
forall st. GenParser Char st String
stringLiteral ParsecT String st Identity String
forall st. GenParser Char st String
stringLiteral
p_listen :: T st ext
p_listen :: T st ext
p_listen =
let p_addr :: ParsecT String u Identity (Maybe String)
p_addr =
Maybe String
-> ParsecT String u Identity (Maybe String)
-> ParsecT String u Identity (Maybe String)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Maybe String
forall a. Maybe a
Nothing (ParsecT String u Identity (Maybe String)
-> ParsecT String u Identity (Maybe String))
-> ParsecT String u Identity (Maybe String)
-> ParsecT String u Identity (Maybe String)
forall a b. (a -> b) -> a -> b
$ ParsecT String u Identity (Maybe String)
-> ParsecT String u Identity (Maybe String)
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT String u Identity (Maybe String)
-> ParsecT String u Identity (Maybe String))
-> ParsecT String u Identity (Maybe String)
-> ParsecT String u Identity (Maybe String)
forall a b. (a -> b) -> a -> b
$
do String
addr <- ParsecT String u Identity String
forall st. GenParser Char st String
p_ip_addr
Char
_ <- Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
':'
Maybe String -> ParsecT String u Identity (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe String -> ParsecT String u Identity (Maybe String))
-> Maybe String -> ParsecT String u Identity (Maybe String)
forall a b. (a -> b) -> a -> b
$ String -> Maybe String
forall a. a -> Maybe a
Just String
addr
p_ip_addr :: ParsecT String st Identity String
p_ip_addr =
([String] -> String)
-> ParsecT String st Identity [String]
-> ParsecT String st Identity String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (ParsecT String st Identity [String]
-> ParsecT String st Identity String)
-> ParsecT String st Identity [String]
-> ParsecT String st Identity String
forall a b. (a -> b) -> a -> b
$ [ParsecT String st Identity String]
-> ParsecT String st Identity [String]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([ParsecT String st Identity String]
-> ParsecT String st Identity [String])
-> [ParsecT String st Identity String]
-> ParsecT String st Identity [String]
forall a b. (a -> b) -> a -> b
$
ParsecT String st Identity String
forall st. GenParser Char st String
p_dec_byte ParsecT String st Identity String
-> [ParsecT String st Identity String]
-> [ParsecT String st Identity String]
forall a. a -> [a] -> [a]
: Int
-> ParsecT String st Identity String
-> [ParsecT String st Identity String]
forall a. Int -> a -> [a]
replicate Int
3 ParsecT String st Identity String
forall st. GenParser Char st String
p_dot_dec_byte
p_dec_byte :: GenParser Char st String
p_dec_byte = Int -> Int -> GenParser Char st Char -> GenParser Char st String
forall tok st a.
Int -> Int -> GenParser tok st a -> GenParser tok st [a]
countBetween Int
1 Int
3 GenParser Char st Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit
p_dot_dec_byte :: ParsecT String u Identity String
p_dot_dec_byte = (Char -> String -> String)
-> ParsecT String u Identity Char
-> ParsecT String u Identity String
-> ParsecT String u Identity String
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (:) (Char -> ParsecT String u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'.') ParsecT String u Identity String
forall st. GenParser Char st String
p_dec_byte
in T (T ext) [(Maybe String, PortNumber)]
-> GenParser Char st (Maybe String, PortNumber) -> T st ext
forall r a st.
T r [a] -> GenParser Char st a -> GenParser Char st (r -> r)
addToList T (T ext) [(Maybe String, PortNumber)]
forall ext. T (T ext) [(Maybe String, PortNumber)]
ConfigA.listen (GenParser Char st (Maybe String, PortNumber) -> T st ext)
-> GenParser Char st (Maybe String, PortNumber) -> T st ext
forall a b. (a -> b) -> a -> b
$
(Maybe String -> PortNumber -> (Maybe String, PortNumber))
-> ParsecT String st Identity (Maybe String)
-> ParsecT String st Identity PortNumber
-> GenParser Char st (Maybe String, PortNumber)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,) ParsecT String st Identity (Maybe String)
forall u. ParsecT String u Identity (Maybe String)
p_addr ((Integer -> PortNumber)
-> ParsecT String st Identity Integer
-> ParsecT String st Identity PortNumber
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> PortNumber
forall a. Num a => Integer -> a
fromInteger (ParsecT String st Identity Integer
-> ParsecT String st Identity PortNumber)
-> ParsecT String st Identity Integer
-> ParsecT String st Identity PortNumber
forall a b. (a -> b) -> a -> b
$ GenTokenParser String st Identity
-> ParsecT String st Identity Integer
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
Token.integer GenTokenParser String st Identity
forall st. TokenParser st
p)
p_addLanguage :: T st ext
p_addLanguage :: T st ext
p_addLanguage =
T (T ext) [(String, String)]
-> GenParser Char st (String, String) -> T st ext
forall r a st.
T r [a] -> GenParser Char st a -> GenParser Char st (r -> r)
addToList T (T ext) [(String, String)]
forall ext. T (T ext) [(String, String)]
ConfigA.addLanguage (GenParser Char st (String, String) -> T st ext)
-> GenParser Char st (String, String) -> T st ext
forall a b. (a -> b) -> a -> b
$
(String -> String -> (String, String))
-> ParsecT String st Identity String
-> ParsecT String st Identity String
-> GenParser Char st (String, String)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,) ParsecT String st Identity String
forall st. GenParser Char st String
stringLiteral ParsecT String st Identity String
forall st. GenParser Char st String
stringLiteral
p_languagePriority :: T st ext
p_languagePriority :: T st ext
p_languagePriority = T (T ext) [String] -> GenParser Char st [String] -> T st ext
forall r a st.
T r a -> GenParser Char st a -> GenParser Char st (r -> r)
set T (T ext) [String]
forall ext. T (T ext) [String]
ConfigA.languagePriority (GenParser Char st [String] -> T st ext)
-> GenParser Char st [String] -> T st ext
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity String -> GenParser Char st [String]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String st Identity String
forall st. GenParser Char st String
stringLiteral