module Data.Internal.Wkt.Common
  ( emptySet
  , emptySets
  , number
  ) where

import           Control.Applicative ((<|>))
import qualified Data.Scientific     as Scientific
import qualified Data.Sequence       as Sequence
import qualified Text.Trifecta       as Trifecta

emptySet :: Trifecta.Parser (Sequence.Seq a)
emptySet :: Parser (Seq a)
emptySet = do
  String
_ <- String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
Trifecta.string String
"empty"
  Seq a -> Parser (Seq a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Seq a
forall a. Seq a
Sequence.empty

emptySets :: Trifecta.Parser ([a], [[a]])
emptySets :: Parser ([a], [[a]])
emptySets = do
  String
_ <- String -> Parser String
forall (m :: * -> *). CharParsing m => String -> m String
Trifecta.string String
"empty"
  ([a], [[a]]) -> Parser ([a], [[a]])
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([], [])

number :: Trifecta.Parser Scientific.Scientific
number :: Parser Scientific
number = do
    Scientific -> Scientific
sign <- (Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> m Char
Trifecta.char Char
'+' Parser Char
-> Parser (Scientific -> Scientific)
-> Parser (Scientific -> Scientific)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (Scientific -> Scientific) -> Parser (Scientific -> Scientific)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Scientific -> Scientific
forall a. a -> a
id) Parser (Scientific -> Scientific)
-> Parser (Scientific -> Scientific)
-> Parser (Scientific -> Scientific)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> m Char
Trifecta.char Char
'-' Parser Char
-> Parser (Scientific -> Scientific)
-> Parser (Scientific -> Scientific)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (Scientific -> Scientific) -> Parser (Scientific -> Scientific)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Scientific -> Scientific
forall a. Num a => a -> a
negate) Parser (Scientific -> Scientific)
-> Parser (Scientific -> Scientific)
-> Parser (Scientific -> Scientific)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Scientific -> Scientific) -> Parser (Scientific -> Scientific)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Scientific -> Scientific
forall a. a -> a
id
    Scientific -> Scientific
sign  (Scientific -> Scientific)
-> (Either Integer Scientific -> Scientific)
-> Either Integer Scientific
-> Scientific
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Integer -> Scientific)
-> (Scientific -> Scientific)
-> Either Integer Scientific
-> Scientific
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Integer -> Scientific
forall a. Num a => Integer -> a
fromInteger Scientific -> Scientific
forall a. a -> a
id (Either Integer Scientific -> Scientific)
-> Parser (Either Integer Scientific) -> Parser Scientific
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (Either Integer Scientific)
forall (m :: * -> *).
TokenParsing m =>
m (Either Integer Scientific)
Trifecta.integerOrScientific