{-# LANGUAGE CPP #-}
module BishBosh.Text.Poly(
TextParser,
char,
string,
spaces,
unsignedDecimal,
) where
import qualified BishBosh.Data.Integral as Data.Integral
import qualified Data.Char
#if USE_POLYPARSE == 1
import qualified Text.ParserCombinators.Poly.Lazy as Poly
#else /* Plain */
import qualified Text.ParserCombinators.Poly.Plain as Poly
#endif
type TextParser = Poly.Parser Char
char :: Char -> TextParser ()
char :: Char -> TextParser ()
char Char
c = do
Char
_ <- (Char -> Bool) -> String -> Parser Char Char
forall t. Show t => (t -> Bool) -> String -> Parser t t
Poly.satisfyMsg (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
c) [Char
c]
() -> TextParser ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
string :: String -> TextParser ()
string :: String -> TextParser ()
string = (Char -> TextParser ()) -> String -> TextParser ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Char -> TextParser ()
char
spaces :: TextParser ()
spaces :: TextParser ()
spaces = do
String
_ <- Parser Char Char -> Parser Char String
forall (f :: * -> *) a. Alternative f => f a -> f [a]
Poly.many (Parser Char Char -> Parser Char String)
-> Parser Char Char -> Parser Char String
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Parser Char Char
forall t. (t -> Bool) -> Parser t t
Poly.satisfy Char -> Bool
Data.Char.isSpace
() -> TextParser ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
unsignedDecimal :: Num i => TextParser i
unsignedDecimal :: TextParser i
unsignedDecimal = TextParser ()
spaces TextParser () -> TextParser i -> TextParser i
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> i
forall i. Num i => String -> i
Data.Integral.stringToUnsignedDecimal (String -> i) -> Parser Char String -> TextParser i
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Parser Char Char -> Parser Char String
forall (p :: * -> *) a. PolyParse p => p a -> p [a]
Poly.many1 ((Char -> Bool) -> String -> Parser Char Char
forall t. Show t => (t -> Bool) -> String -> Parser t t
Poly.satisfyMsg Char -> Bool
Data.Char.isDigit String
"<digit>")