{-# LANGUAGE CPP #-}
module Graphics.SVGFonts.ReadPath
( pathFromString,
pathFromByteString,
PathCommand(..),
)
where
import Control.Applicative
import qualified Data.Attoparsec.ByteString.Char8 as P
import Data.Attoparsec.ByteString.Char8 (Parser, skipMany, space, many1, try, char)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS
data PathCommand n =
M_abs !(n, n) |
M_rel !(n, n) |
Z |
L_abs !(n, n) |
L_rel !(n, n) |
H_abs !n |
H_rel !n |
V_abs !n |
V_rel !n |
C_abs !(n,n,n,n,n,n) |
C_rel !(n,n,n,n,n,n) |
S_abs !(n,n,n,n) |
S_rel !(n,n,n,n) |
Q_abs !(n,n,n,n) |
Q_rel !(n,n,n,n) |
T_abs !(n, n) |
T_rel !(n, n) |
A_abs |
A_rel
deriving Int -> PathCommand n -> ShowS
[PathCommand n] -> ShowS
PathCommand n -> String
(Int -> PathCommand n -> ShowS)
-> (PathCommand n -> String)
-> ([PathCommand n] -> ShowS)
-> Show (PathCommand n)
forall n. Show n => Int -> PathCommand n -> ShowS
forall n. Show n => [PathCommand n] -> ShowS
forall n. Show n => PathCommand n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PathCommand n] -> ShowS
$cshowList :: forall n. Show n => [PathCommand n] -> ShowS
show :: PathCommand n -> String
$cshow :: forall n. Show n => PathCommand n -> String
showsPrec :: Int -> PathCommand n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> PathCommand n -> ShowS
Show
pathFromString :: Fractional n => String -> Either String [PathCommand n]
pathFromString :: String -> Either String [PathCommand n]
pathFromString = ByteString -> Either String [PathCommand n]
forall n.
Fractional n =>
ByteString -> Either String [PathCommand n]
pathFromByteString (ByteString -> Either String [PathCommand n])
-> (String -> ByteString)
-> String
-> Either String [PathCommand n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS.pack
pathFromByteString :: Fractional n => ByteString -> Either String [PathCommand n]
pathFromByteString :: ByteString -> Either String [PathCommand n]
pathFromByteString ByteString
str = case Parser [PathCommand n]
-> ByteString -> Either String [PathCommand n]
forall a. Parser a -> ByteString -> Either String a
P.parseOnly Parser [PathCommand n]
forall n. Fractional n => Parser [PathCommand n]
path ByteString
str of
Left String
err -> String -> Either String [PathCommand n]
forall a b. a -> Either a b
Left (ShowS
forall a. Show a => a -> String
show String
err)
Right [PathCommand n]
p -> [PathCommand n] -> Either String [PathCommand n]
forall a b. b -> Either a b
Right [PathCommand n]
p
spaces :: Parser ()
spaces :: Parser ()
spaces = Parser ByteString Char -> Parser ()
forall (f :: * -> *) a. Alternative f => f a -> f ()
skipMany Parser ByteString Char
space
path :: Fractional n => Parser [PathCommand n]
path :: Parser [PathCommand n]
path = do{ [[PathCommand n]]
l <- Parser [PathCommand n] -> Parser ByteString [[PathCommand n]]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser [PathCommand n]
forall n. Fractional n => Parser [PathCommand n]
pathElement
; Parser ()
forall t. Chunk t => Parser t ()
P.endOfInput
; [PathCommand n] -> Parser [PathCommand n]
forall (m :: * -> *) a. Monad m => a -> m a
return ([[PathCommand n]] -> [PathCommand n]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[PathCommand n]]
l)
}
pathElement :: Fractional n => Parser [PathCommand n]
pathElement :: Parser [PathCommand n]
pathElement =
Parser ()
whiteSpace Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
( String -> Parser ()
symbol String
"M" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 ((n, n) -> PathCommand n
forall n. (n, n) -> PathCommand n
M_abs ((n, n) -> PathCommand n)
-> Parser ByteString (n, n) -> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (n, n)
forall n. Fractional n => Parser (n, n)
tupel2)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"m" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 ((n, n) -> PathCommand n
forall n. (n, n) -> PathCommand n
M_rel ((n, n) -> PathCommand n)
-> Parser ByteString (n, n) -> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (n, n)
forall n. Fractional n => Parser (n, n)
tupel2)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"z" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [PathCommand n
forall n. PathCommand n
Z]
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"Z" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [PathCommand n
forall n. PathCommand n
Z]
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"L" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 ((n, n) -> PathCommand n
forall n. (n, n) -> PathCommand n
L_abs ((n, n) -> PathCommand n)
-> Parser ByteString (n, n) -> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (n, n)
forall n. Fractional n => Parser (n, n)
tupel2)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"l" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 ((n, n) -> PathCommand n
forall n. (n, n) -> PathCommand n
L_rel ((n, n) -> PathCommand n)
-> Parser ByteString (n, n) -> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (n, n)
forall n. Fractional n => Parser (n, n)
tupel2)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"H" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 (n -> PathCommand n
forall n. n -> PathCommand n
H_abs (n -> PathCommand n)
-> Parser ByteString n -> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString n
forall n. Fractional n => Parser n
myfloat)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"h" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 (n -> PathCommand n
forall n. n -> PathCommand n
H_rel (n -> PathCommand n)
-> Parser ByteString n -> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString n
forall n. Fractional n => Parser n
myfloat)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"V" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 (n -> PathCommand n
forall n. n -> PathCommand n
V_abs (n -> PathCommand n)
-> Parser ByteString n -> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString n
forall n. Fractional n => Parser n
myfloat)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"v" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 (n -> PathCommand n
forall n. n -> PathCommand n
V_rel (n -> PathCommand n)
-> Parser ByteString n -> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString n
forall n. Fractional n => Parser n
myfloat)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"C" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 ((n, n, n, n, n, n) -> PathCommand n
forall n. (n, n, n, n, n, n) -> PathCommand n
C_abs ((n, n, n, n, n, n) -> PathCommand n)
-> Parser ByteString (n, n, n, n, n, n)
-> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (n, n, n, n, n, n)
forall n. Fractional n => Parser (n, n, n, n, n, n)
tupel6)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"c" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 ((n, n, n, n, n, n) -> PathCommand n
forall n. (n, n, n, n, n, n) -> PathCommand n
C_rel ((n, n, n, n, n, n) -> PathCommand n)
-> Parser ByteString (n, n, n, n, n, n)
-> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (n, n, n, n, n, n)
forall n. Fractional n => Parser (n, n, n, n, n, n)
tupel6)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"S" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 ((n, n, n, n) -> PathCommand n
forall n. (n, n, n, n) -> PathCommand n
S_abs ((n, n, n, n) -> PathCommand n)
-> Parser ByteString (n, n, n, n)
-> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (n, n, n, n)
forall n. Fractional n => Parser (n, n, n, n)
tupel4)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"s" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 ((n, n, n, n) -> PathCommand n
forall n. (n, n, n, n) -> PathCommand n
S_rel ((n, n, n, n) -> PathCommand n)
-> Parser ByteString (n, n, n, n)
-> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (n, n, n, n)
forall n. Fractional n => Parser (n, n, n, n)
tupel4)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"Q" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 ((n, n, n, n) -> PathCommand n
forall n. (n, n, n, n) -> PathCommand n
Q_abs ((n, n, n, n) -> PathCommand n)
-> Parser ByteString (n, n, n, n)
-> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (n, n, n, n)
forall n. Fractional n => Parser (n, n, n, n)
tupel4)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"q" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 ((n, n, n, n) -> PathCommand n
forall n. (n, n, n, n) -> PathCommand n
Q_rel ((n, n, n, n) -> PathCommand n)
-> Parser ByteString (n, n, n, n)
-> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (n, n, n, n)
forall n. Fractional n => Parser (n, n, n, n)
tupel4)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"T" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 ((n, n) -> PathCommand n
forall n. (n, n) -> PathCommand n
T_abs ((n, n) -> PathCommand n)
-> Parser ByteString (n, n) -> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (n, n)
forall n. Fractional n => Parser (n, n)
tupel2)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"t" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 ((n, n) -> PathCommand n
forall n. (n, n) -> PathCommand n
T_rel ((n, n) -> PathCommand n)
-> Parser ByteString (n, n) -> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (n, n)
forall n. Fractional n => Parser (n, n)
tupel2)
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"A" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 (PathCommand n
forall n. PathCommand n
A_abs PathCommand n
-> Parser ByteString (Double, Double)
-> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (Parser ByteString (Double, Double)
forall n. Fractional n => Parser (n, n)
tupel2::Parser (Double,Double)))
Parser [PathCommand n]
-> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Parser ()
symbol String
"a" Parser () -> Parser [PathCommand n] -> Parser [PathCommand n]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString (PathCommand n) -> Parser [PathCommand n]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many1 (PathCommand n
forall n. PathCommand n
A_rel PathCommand n
-> Parser ByteString (Double, Double)
-> Parser ByteString (PathCommand n)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (Parser ByteString (Double, Double)
forall n. Fractional n => Parser (n, n)
tupel2::Parser (Double,Double)))
)
comma :: Parser ()
comma :: Parser ()
comma = Parser ()
spaces Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Parser () -> Parser ()
forall i a. Parser i a -> Parser i a
try (() () -> Parser ByteString Char -> Parser ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser ByteString Char
char Char
',' ) Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ()
spaces)
tupel2 :: Fractional n => Parser (n,n)
tupel2 :: Parser (n, n)
tupel2 = do{ n
x <- Parser n
forall n. Fractional n => Parser n
myfloat; Parser ()
comma; n
y <- Parser n
forall n. Fractional n => Parser n
myfloat; Parser ()
spaces;
(n, n) -> Parser (n, n)
forall (m :: * -> *) a. Monad m => a -> m a
return (n
x, n
y)
}
tupel4 :: Fractional n => Parser (n,n,n,n)
tupel4 :: Parser (n, n, n, n)
tupel4 = do{ n
x1 <- Parser n
forall n. Fractional n => Parser n
myfloat; Parser ()
comma; n
y1 <- Parser n
forall n. Fractional n => Parser n
myfloat; Parser ()
spaces;
n
x <- Parser n
forall n. Fractional n => Parser n
myfloat; Parser ()
comma; n
y <- Parser n
forall n. Fractional n => Parser n
myfloat; Parser ()
spaces;
(n, n, n, n) -> Parser (n, n, n, n)
forall (m :: * -> *) a. Monad m => a -> m a
return (n
x1, n
y1, n
x, n
y)
}
tupel6 :: Fractional n => Parser (n,n,n,n,n,n)
tupel6 :: Parser (n, n, n, n, n, n)
tupel6 = do{ n
x1 <- Parser n
forall n. Fractional n => Parser n
myfloat; Parser ()
comma; n
y1 <- Parser n
forall n. Fractional n => Parser n
myfloat; Parser ()
spaces;
n
x2 <- Parser n
forall n. Fractional n => Parser n
myfloat; Parser ()
comma; n
y2 <- Parser n
forall n. Fractional n => Parser n
myfloat; Parser ()
spaces;
n
x <- Parser n
forall n. Fractional n => Parser n
myfloat; Parser ()
comma; n
y <- Parser n
forall n. Fractional n => Parser n
myfloat; Parser ()
spaces;
(n, n, n, n, n, n) -> Parser (n, n, n, n, n, n)
forall (m :: * -> *) a. Monad m => a -> m a
return (n
x1, n
y1, n
x2, n
y2, n
x, n
y)
}
myfloat :: Fractional n => Parser n
myfloat :: Parser n
myfloat = Parser n -> Parser n
forall i a. Parser i a -> Parser i a
try (do{ ()
_ <- String -> Parser ()
symbol String
"-"; n
n <- Parser n
forall n. Fractional n => Parser n
float; n -> Parser n
forall (m :: * -> *) a. Monad m => a -> m a
return (n -> n
forall a. Num a => a -> a
negate n
n) }) Parser n -> Parser n -> Parser n
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
Parser n -> Parser n
forall i a. Parser i a -> Parser i a
try Parser n
forall n. Fractional n => Parser n
float Parser n -> Parser n -> Parser n
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
do { Integer
i<-Parser Integer
integer; n -> Parser n
forall (m :: * -> *) a. Monad m => a -> m a
return(Integer -> n
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i) }
whiteSpace :: Parser ()
whiteSpace :: Parser ()
whiteSpace = Parser ()
P.skipSpace
symbol :: String -> Parser ()
symbol :: String -> Parser ()
symbol String
s = ByteString -> Parser ByteString
P.string (String -> ByteString
BS.pack String
s) Parser ByteString -> Parser () -> Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ()
whiteSpace
integer :: Parser Integer
integer :: Parser Integer
integer = Parser Integer
forall a. Integral a => Parser a
P.decimal
float :: Fractional n => Parser n
float :: Parser n
float = Double -> n
forall a b. (Real a, Fractional b) => a -> b
realToFrac (Double -> n) -> Parser ByteString Double -> Parser n
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Double
P.double