{-# LANGUAGE ScopedTypeVariables #-}
module Data.Icao.Switches
( parser
) where
import Data.Aeromess.Parser
parser
:: forall a b c.
(Bounded a, Enum a, Show a)
=> a -> Parser c -> (c -> b) -> Parser (Maybe b)
parser k p f = do
pk <- key' show k
if not (null pk)
then do
r <- p
_ <- eos show (bounds :: [a])
return (Just (f r))
else return Nothing
eos
:: forall a.
(Bounded a, Enum a, Show a)
=> (a -> String) -> [a] -> Parser String
eos f b = try (optional space >> lookAhead (keys' f b <|> string "-" <|> string ")"))
key' :: (a -> String) -> a -> Parser String
key' f k = try (string (f k ++ "/"))
keys' :: (a -> String) -> [a] -> Parser String
keys' f v = choice (map (key' f) v)
bounds
:: (Bounded a, Enum a)
=> [a]
bounds = [minBound .. maxBound]