module Toml.Parser.Value
( arrayP
, boolP
, dateTimeP
, doubleP
, integerP
, valueP
, anyValueP
) where
import Control.Applicative (Alternative (..))
import Control.Applicative.Combinators (between, count, option, optional, sepBy1, sepEndBy,
skipMany)
import Data.Fixed (Pico)
import Data.Time (Day, LocalTime (..), TimeOfDay, ZonedTime (..), fromGregorianValid,
makeTimeOfDayValid, minutesToTimeZone)
import Data.String (fromString)
import Text.Read (readMaybe)
import Text.Megaparsec (observing, parseMaybe)
import Toml.Parser.Core (Parser, char, digitChar, hexDigitChar, octDigitChar, binDigitChar, hexadecimal, octal, binary, lexeme, sc, signed,
string, text, try, (<?>))
import Toml.Parser.String (textP)
import Toml.Type (AnyValue, UValue (..), typeCheck)
decimalP :: Parser Integer
decimalP :: Parser Integer
decimalP = do
Either (ParseError Text Void) [Char]
value <- Parser [Char]
-> ParsecT
Void Text Identity (Either (ParseError Text Void) [Char])
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity (Either (ParseError Text Void) a)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> m (Either (ParseError s e) a)
observing (Parser [Char]
-> ParsecT
Void Text Identity (Either (ParseError Text Void) [Char]))
-> Parser [Char]
-> ParsecT
Void Text Identity (Either (ParseError Text Void) [Char])
forall a b. (a -> b) -> a -> b
$ Parser [Char] -> Parser [Char]
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try Parser [Char]
leadingZeroP
case Either (ParseError Text Void) [Char]
value of
Left ParseError Text Void
_ -> do
Parser Integer -> Parser Integer
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try Parser Integer
more
Right [Char]
_ ->
[Char] -> Parser Integer
forall a. [Char] -> ParsecT Void Text Identity a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"Leading zero."
where
leadingZeroP :: Parser String
leadingZeroP :: Parser [Char]
leadingZeroP = do
Int -> ParsecT Void Text Identity Char -> Parser [Char]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
count Int
1 (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'0') Parser [Char] -> ([Char] -> Parser [Char]) -> Parser [Char]
forall a b.
ParsecT Void Text Identity a
-> (a -> ParsecT Void Text Identity b)
-> ParsecT Void Text Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\[Char]
_ -> ParsecT Void Text Identity Char -> Parser [Char]
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some ParsecT Void Text Identity Char
ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
digitChar)
more :: Parser Integer
more :: Parser Integer
more = Maybe Integer -> Parser Integer
check (Maybe Integer -> Parser Integer)
-> ParsecT Void Text Identity (Maybe Integer) -> Parser Integer
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [Char] -> Maybe Integer
forall a. Read a => [Char] -> Maybe a
readMaybe ([Char] -> Maybe Integer)
-> ([[Char]] -> [Char]) -> [[Char]] -> Maybe Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Char]] -> [Char]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Char]] -> Maybe Integer)
-> ParsecT Void Text Identity [[Char]]
-> ParsecT Void Text Identity (Maybe Integer)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Char]
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity [[Char]]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
sepBy1 (ParsecT Void Text Identity Char -> Parser [Char]
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some ParsecT Void Text Identity Char
ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
digitChar) (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'_')
check :: Maybe Integer -> Parser Integer
check :: Maybe Integer -> Parser Integer
check = Parser Integer
-> (Integer -> Parser Integer) -> Maybe Integer -> Parser Integer
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Char] -> Parser Integer
forall a. [Char] -> ParsecT Void Text Identity a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"Not an integer") Integer -> Parser Integer
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
numberP :: Parser Integer -> Parser Char -> String -> Parser Integer
numberP :: Parser Integer
-> ParsecT Void Text Identity Char -> [Char] -> Parser Integer
numberP Parser Integer
parseInteger ParsecT Void Text Identity Char
parseDigit [Char]
errorMessage = Parser Integer
more
where
more :: Parser Integer
more :: Parser Integer
more = Maybe Integer -> Parser Integer
check (Maybe Integer -> Parser Integer)
-> ParsecT Void Text Identity (Maybe Integer) -> Parser Integer
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [Char] -> Maybe Integer
intValueMaybe ([Char] -> Maybe Integer)
-> ([[Char]] -> [Char]) -> [[Char]] -> Maybe Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Char]] -> [Char]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Char]] -> Maybe Integer)
-> ParsecT Void Text Identity [[Char]]
-> ParsecT Void Text Identity (Maybe Integer)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Char]
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity [[Char]]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
sepBy1 (ParsecT Void Text Identity Char -> Parser [Char]
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some ParsecT Void Text Identity Char
parseDigit) (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'_')
intValueMaybe :: String -> Maybe Integer
intValueMaybe :: [Char] -> Maybe Integer
intValueMaybe = Parser Integer -> Text -> Maybe Integer
forall e s a. (Ord e, Stream s) => Parsec e s a -> s -> Maybe a
parseMaybe Parser Integer
parseInteger (Text -> Maybe Integer)
-> ([Char] -> Text) -> [Char] -> Maybe Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
forall a. IsString a => [Char] -> a
fromString
check :: Maybe Integer -> Parser Integer
check :: Maybe Integer -> Parser Integer
check = Parser Integer
-> (Integer -> Parser Integer) -> Maybe Integer -> Parser Integer
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Char] -> Parser Integer
forall a. [Char] -> ParsecT Void Text Identity a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
errorMessage) Integer -> Parser Integer
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
integerP :: Parser Integer
integerP :: Parser Integer
integerP = Parser Integer -> Parser Integer
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
lexeme (Parser Integer
bin Parser Integer -> Parser Integer -> Parser Integer
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Integer
oct Parser Integer -> Parser Integer -> Parser Integer
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Integer
hex Parser Integer -> Parser Integer -> Parser Integer
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Integer
dec) Parser Integer -> [Char] -> Parser Integer
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> [Char] -> m a
<?> [Char]
"integer"
where
bin, oct, hex, dec :: Parser Integer
bin :: Parser Integer
bin = ParsecT Void Text Identity Char -> ParsecT Void Text Identity Char
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'0' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
forall a b.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity b -> ParsecT Void Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'b') ParsecT Void Text Identity Char -> Parser Integer -> Parser Integer
forall a b.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity b -> ParsecT Void Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Integer
binaryP Parser Integer -> [Char] -> Parser Integer
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> [Char] -> m a
<?> [Char]
"bin"
oct :: Parser Integer
oct = ParsecT Void Text Identity Char -> ParsecT Void Text Identity Char
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'0' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
forall a b.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity b -> ParsecT Void Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'o') ParsecT Void Text Identity Char -> Parser Integer -> Parser Integer
forall a b.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity b -> ParsecT Void Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Integer
octalP Parser Integer -> [Char] -> Parser Integer
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> [Char] -> m a
<?> [Char]
"oct"
hex :: Parser Integer
hex = ParsecT Void Text Identity Char -> ParsecT Void Text Identity Char
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'0' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
forall a b.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity b -> ParsecT Void Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'x') ParsecT Void Text Identity Char -> Parser Integer -> Parser Integer
forall a b.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity b -> ParsecT Void Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Integer
hexadecimalP Parser Integer -> [Char] -> Parser Integer
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> [Char] -> m a
<?> [Char]
"hex"
dec :: Parser Integer
dec = ParsecT Void Text Identity () -> Parser Integer -> Parser Integer
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m () -> m a -> m a
signed ParsecT Void Text Identity ()
sc Parser Integer
decimalP Parser Integer -> [Char] -> Parser Integer
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> [Char] -> m a
<?> [Char]
"dec"
binaryP :: Parser Integer
binaryP = Parser Integer
-> ParsecT Void Text Identity Char -> [Char] -> Parser Integer
numberP Parser Integer
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
binary ParsecT Void Text Identity Char
ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
binDigitChar [Char]
"Invalid binary number"
octalP :: Parser Integer
octalP = Parser Integer
-> ParsecT Void Text Identity Char -> [Char] -> Parser Integer
numberP Parser Integer
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
octal ParsecT Void Text Identity Char
ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
octDigitChar [Char]
"Invalid ocatl number"
hexadecimalP :: Parser Integer
hexadecimalP = Parser Integer
-> ParsecT Void Text Identity Char -> [Char] -> Parser Integer
numberP Parser Integer
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
hexadecimal ParsecT Void Text Identity Char
ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
hexDigitChar [Char]
"Invalid hexadecimal number"
doubleP :: Parser Double
doubleP :: Parser Double
doubleP = Parser Double -> Parser Double
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
lexeme (ParsecT Void Text Identity () -> Parser Double -> Parser Double
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m () -> m a -> m a
signed ParsecT Void Text Identity ()
sc (Parser Double
num Parser Double -> Parser Double -> Parser Double
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Double
inf Parser Double -> Parser Double -> Parser Double
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Double
nan)) Parser Double -> [Char] -> Parser Double
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> [Char] -> m a
<?> [Char]
"double"
where
num, inf, nan :: Parser Double
num :: Parser Double
num = Parser Double
floatP
inf :: Parser Double
inf = Double
1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
0 Double -> ParsecT Void Text Identity (Tokens Text) -> Parser Double
forall a b.
a -> ParsecT Void Text Identity b -> ParsecT Void Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT Void Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"inf"
nan :: Parser Double
nan = Double
0 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
0 Double -> ParsecT Void Text Identity (Tokens Text) -> Parser Double
forall a b.
a -> ParsecT Void Text Identity b -> ParsecT Void Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT Void Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"nan"
floatP :: Parser Double
floatP :: Parser Double
floatP = Maybe Double -> Parser Double
check (Maybe Double -> Parser Double)
-> ([Char] -> Maybe Double) -> [Char] -> Parser Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Maybe Double
forall a. Read a => [Char] -> Maybe a
readMaybe ([Char] -> Parser Double) -> Parser [Char] -> Parser Double
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [Parser [Char]] -> Parser [Char]
forall a. Monoid a => [a] -> a
mconcat [ Parser [Char]
digits, Parser [Char]
expo Parser [Char] -> Parser [Char] -> Parser [Char]
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser [Char]
dot ]
where
check :: Maybe Double -> Parser Double
check :: Maybe Double -> Parser Double
check = Parser Double
-> (Double -> Parser Double) -> Maybe Double -> Parser Double
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Char] -> Parser Double
forall a. [Char] -> ParsecT Void Text Identity a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"Not a float") Double -> Parser Double
forall a. a -> ParsecT Void Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return
digits, dot, expo :: Parser String
digits :: Parser [Char]
digits = [[Char]] -> [Char]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Char]] -> [Char])
-> ParsecT Void Text Identity [[Char]] -> Parser [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Char]
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity [[Char]]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
sepBy1 (ParsecT Void Text Identity Char -> Parser [Char]
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some ParsecT Void Text Identity Char
ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
digitChar) (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'_')
dot :: Parser [Char]
dot = [Parser [Char]] -> Parser [Char]
forall a. Monoid a => [a] -> a
mconcat [Char -> [Char]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Char -> [Char])
-> ParsecT Void Text Identity Char -> Parser [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'.', Parser [Char]
digits, [Char] -> Parser [Char] -> Parser [Char]
forall (m :: * -> *) a. Alternative m => a -> m a -> m a
option [Char]
"" Parser [Char]
expo]
expo :: Parser [Char]
expo = [Parser [Char]] -> Parser [Char]
forall a. Monoid a => [a] -> a
mconcat
[ Char -> [Char]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Char -> [Char])
-> ParsecT Void Text Identity Char -> Parser [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'e' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'E')
, Char -> [Char]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Char -> [Char])
-> ParsecT Void Text Identity Char -> Parser [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
forall (m :: * -> *) a. Alternative m => a -> m a -> m a
option Char
'+' (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'+' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'-')
, Parser [Char]
digits
]
boolP :: Parser Bool
boolP :: Parser Bool
boolP = Bool
False Bool -> ParsecT Void Text Identity Text -> Parser Bool
forall a b.
a -> ParsecT Void Text Identity b -> ParsecT Void Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> ParsecT Void Text Identity Text
text Text
"false"
Parser Bool -> Parser Bool -> Parser Bool
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Bool
True Bool -> ParsecT Void Text Identity Text -> Parser Bool
forall a b.
a -> ParsecT Void Text Identity b -> ParsecT Void Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> ParsecT Void Text Identity Text
text Text
"true"
Parser Bool -> [Char] -> Parser Bool
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> [Char] -> m a
<?> [Char]
"bool"
dateTimeP :: Parser UValue
dateTimeP :: Parser UValue
dateTimeP = Parser UValue -> Parser UValue
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
lexeme (Parser UValue -> Parser UValue
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (TimeOfDay -> UValue
UHours (TimeOfDay -> UValue)
-> ParsecT Void Text Identity TimeOfDay -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity TimeOfDay
hoursP) Parser UValue -> Parser UValue -> Parser UValue
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser UValue
dayLocalZoned) Parser UValue -> [Char] -> Parser UValue
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> [Char] -> m a
<?> [Char]
"datetime"
dayLocalZoned :: Parser UValue
dayLocalZoned :: Parser UValue
dayLocalZoned = do
Day
day <- ParsecT Void Text Identity Day -> ParsecT Void Text Identity Day
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT Void Text Identity Day
dayP
Maybe TimeOfDay
maybeHours <- ParsecT Void Text Identity TimeOfDay
-> ParsecT Void Text Identity (Maybe TimeOfDay)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ParsecT Void Text Identity TimeOfDay
-> ParsecT Void Text Identity TimeOfDay
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (ParsecT Void Text Identity TimeOfDay
-> ParsecT Void Text Identity TimeOfDay)
-> ParsecT Void Text Identity TimeOfDay
-> ParsecT Void Text Identity TimeOfDay
forall a b. (a -> b) -> a -> b
$ (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'T' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
' ') ParsecT Void Text Identity Char
-> ParsecT Void Text Identity TimeOfDay
-> ParsecT Void Text Identity TimeOfDay
forall a b.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity b -> ParsecT Void Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity TimeOfDay
hoursP)
case Maybe TimeOfDay
maybeHours of
Maybe TimeOfDay
Nothing -> UValue -> Parser UValue
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UValue -> Parser UValue) -> UValue -> Parser UValue
forall a b. (a -> b) -> a -> b
$ Day -> UValue
UDay Day
day
Just TimeOfDay
hours -> do
Maybe Int
maybeOffset <- ParsecT Void Text Identity Int
-> ParsecT Void Text Identity (Maybe Int)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ParsecT Void Text Identity Int -> ParsecT Void Text Identity Int
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT Void Text Identity Int
timeOffsetP)
let localTime :: LocalTime
localTime = Day -> TimeOfDay -> LocalTime
LocalTime Day
day TimeOfDay
hours
UValue -> Parser UValue
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UValue -> Parser UValue) -> UValue -> Parser UValue
forall a b. (a -> b) -> a -> b
$ case Maybe Int
maybeOffset of
Maybe Int
Nothing -> LocalTime -> UValue
ULocal LocalTime
localTime
Just Int
offset -> ZonedTime -> UValue
UZoned (ZonedTime -> UValue) -> ZonedTime -> UValue
forall a b. (a -> b) -> a -> b
$ LocalTime -> TimeZone -> ZonedTime
ZonedTime LocalTime
localTime (Int -> TimeZone
minutesToTimeZone Int
offset)
timeOffsetP :: Parser Int
timeOffsetP :: ParsecT Void Text Identity Int
timeOffsetP = ParsecT Void Text Identity Int
z ParsecT Void Text Identity Int
-> ParsecT Void Text Identity Int -> ParsecT Void Text Identity Int
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT Void Text Identity Int
numOffset
where
z :: Parser Int
z :: ParsecT Void Text Identity Int
z = Int
0 Int
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Int
forall a b.
a -> ParsecT Void Text Identity b -> ParsecT Void Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'Z'
numOffset :: Parser Int
numOffset :: ParsecT Void Text Identity Int
numOffset = do
Char
sign <- Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'+' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
-> ParsecT Void Text Identity Char
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'-'
Int
hours <- ParsecT Void Text Identity Int
int2DigitsP
Char
_ <- Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
':'
Int
minutes <- ParsecT Void Text Identity Int
int2DigitsP
let totalMinutes :: Int
totalMinutes = Int
hours Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
60 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
minutes
Int -> ParsecT Void Text Identity Int
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int -> ParsecT Void Text Identity Int)
-> Int -> ParsecT Void Text Identity Int
forall a b. (a -> b) -> a -> b
$ if Char
sign Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'+'
then Int
totalMinutes
else Int -> Int
forall a. Num a => a -> a
negate Int
totalMinutes
hoursP :: Parser TimeOfDay
hoursP :: ParsecT Void Text Identity TimeOfDay
hoursP = do
Int
hours <- ParsecT Void Text Identity Int
int2DigitsP
Char
_ <- Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
':'
Int
minutes <- ParsecT Void Text Identity Int
int2DigitsP
Char
_ <- Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
':'
Pico
seconds <- Parser Pico
picoTruncated
case Int -> Int -> Pico -> Maybe TimeOfDay
makeTimeOfDayValid Int
hours Int
minutes Pico
seconds of
Just TimeOfDay
time -> TimeOfDay -> ParsecT Void Text Identity TimeOfDay
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TimeOfDay
time
Maybe TimeOfDay
Nothing -> [Char] -> ParsecT Void Text Identity TimeOfDay
forall a. [Char] -> ParsecT Void Text Identity a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char] -> ParsecT Void Text Identity TimeOfDay)
-> [Char] -> ParsecT Void Text Identity TimeOfDay
forall a b. (a -> b) -> a -> b
$
[Char]
"Invalid time of day: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Int -> [Char]
forall a. Show a => a -> [Char]
show Int
hours [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
":" [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Int -> [Char]
forall a. Show a => a -> [Char]
show Int
minutes [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
":" [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Pico -> [Char]
forall a. Show a => a -> [Char]
show Pico
seconds
dayP :: Parser Day
dayP :: ParsecT Void Text Identity Day
dayP = do
Integer
year <- Parser Integer
yearP
Char
_ <- Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'-'
Int
month <- ParsecT Void Text Identity Int
int2DigitsP
Char
_ <- Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'-'
Int
day <- ParsecT Void Text Identity Int
int2DigitsP
case Integer -> Int -> Int -> Maybe Day
fromGregorianValid Integer
year Int
month Int
day of
Just Day
date -> Day -> ParsecT Void Text Identity Day
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Day
date
Maybe Day
Nothing -> [Char] -> ParsecT Void Text Identity Day
forall a. [Char] -> ParsecT Void Text Identity a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char] -> ParsecT Void Text Identity Day)
-> [Char] -> ParsecT Void Text Identity Day
forall a b. (a -> b) -> a -> b
$
[Char]
"Invalid date: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Integer -> [Char]
forall a. Show a => a -> [Char]
show Integer
year [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
"-" [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Int -> [Char]
forall a. Show a => a -> [Char]
show Int
month [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
"-" [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Int -> [Char]
forall a. Show a => a -> [Char]
show Int
day
yearP :: Parser Integer
yearP :: Parser Integer
yearP = [Char] -> Integer
forall a. Read a => [Char] -> a
read ([Char] -> Integer) -> Parser [Char] -> Parser Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ParsecT Void Text Identity Char -> Parser [Char]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
count Int
4 ParsecT Void Text Identity Char
ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
digitChar
int2DigitsP :: Parser Int
int2DigitsP :: ParsecT Void Text Identity Int
int2DigitsP = [Char] -> Int
forall a. Read a => [Char] -> a
read ([Char] -> Int) -> Parser [Char] -> ParsecT Void Text Identity Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ParsecT Void Text Identity Char -> Parser [Char]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
count Int
2 ParsecT Void Text Identity Char
ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
digitChar
picoTruncated :: Parser Pico
picoTruncated :: Parser Pico
picoTruncated = do
[Char]
int <- Int -> ParsecT Void Text Identity Char -> Parser [Char]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
count Int
2 ParsecT Void Text Identity Char
ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
digitChar
Maybe [Char]
frc <- Parser [Char] -> ParsecT Void Text Identity (Maybe [Char])
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser [Char] -> ParsecT Void Text Identity (Maybe [Char]))
-> Parser [Char] -> ParsecT Void Text Identity (Maybe [Char])
forall a b. (a -> b) -> a -> b
$ Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'.' ParsecT Void Text Identity Char -> Parser [Char] -> Parser [Char]
forall a b.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity b -> ParsecT Void Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take Int
12 ([Char] -> [Char]) -> Parser [Char] -> Parser [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity Char -> Parser [Char]
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some ParsecT Void Text Identity Char
ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
digitChar)
Pico -> Parser Pico
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Pico -> Parser Pico) -> Pico -> Parser Pico
forall a b. (a -> b) -> a -> b
$ [Char] -> Pico
forall a. Read a => [Char] -> a
read ([Char] -> Pico) -> [Char] -> Pico
forall a b. (a -> b) -> a -> b
$ case Maybe [Char]
frc of
Maybe [Char]
Nothing -> [Char]
int
Just [Char]
frc' -> [Char]
int [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"." [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
frc'
arrayP :: Parser [UValue]
arrayP :: Parser [UValue]
arrayP = Parser [UValue] -> Parser [UValue]
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
lexeme (ParsecT Void Text Identity ()
-> ParsecT Void Text Identity Char
-> Parser [UValue]
-> Parser [UValue]
forall (m :: * -> *) open close a.
Applicative m =>
m open -> m close -> m a -> m a
between (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'[' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity () -> ParsecT Void Text Identity ()
forall a b.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity b -> ParsecT Void Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity ()
sc) (Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
']') Parser [UValue]
elements) Parser [UValue] -> [Char] -> Parser [UValue]
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> [Char] -> m a
<?> [Char]
"array"
where
elements :: Parser [UValue]
elements :: Parser [UValue]
elements = [UValue] -> Parser [UValue] -> Parser [UValue]
forall (m :: * -> *) a. Alternative m => a -> m a -> m a
option [] (Parser [UValue] -> Parser [UValue])
-> Parser [UValue] -> Parser [UValue]
forall a b. (a -> b) -> a -> b
$ do
UValue
v <- Parser UValue
valueP
Maybe ()
sep <- ParsecT Void Text Identity ()
-> ParsecT Void Text Identity (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ParsecT Void Text Identity ()
spComma
[UValue]
vs <- case Maybe ()
sep of
Maybe ()
Nothing -> [UValue] -> Parser [UValue]
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
Just ()
_ -> (UValue -> Parser UValue
element UValue
v Parser UValue -> ParsecT Void Text Identity () -> Parser [UValue]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
`sepEndBy` ParsecT Void Text Identity ()
spComma) Parser [UValue] -> ParsecT Void Text Identity () -> Parser [UValue]
forall a b.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity b -> ParsecT Void Text Identity a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Void Text Identity () -> ParsecT Void Text Identity ()
forall (m :: * -> *) a. Alternative m => m a -> m ()
skipMany ParsecT Void Text Identity ()
spComma
[UValue] -> Parser [UValue]
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UValue
vUValue -> [UValue] -> [UValue]
forall a. a -> [a] -> [a]
:[UValue]
vs)
element :: UValue -> Parser UValue
element :: UValue -> Parser UValue
element = \case
UBool Bool
_ -> Bool -> UValue
UBool (Bool -> UValue) -> Parser Bool -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
boolP
UZoned ZonedTime
_ -> Parser UValue
dayLocalZoned
ULocal LocalTime
_ -> Parser UValue
dayLocalZoned
UDay Day
_ -> Day -> UValue
UDay (Day -> UValue) -> ParsecT Void Text Identity Day -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity Day
dayP
UHours TimeOfDay
_ -> TimeOfDay -> UValue
UHours (TimeOfDay -> UValue)
-> ParsecT Void Text Identity TimeOfDay -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity TimeOfDay
hoursP
UDouble Double
_ -> Double -> UValue
UDouble (Double -> UValue) -> Parser Double -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Double -> Parser Double
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try Parser Double
doubleP
UInteger Integer
_ -> Integer -> UValue
UInteger (Integer -> UValue) -> Parser Integer -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Integer
integerP
UText Text
_ -> Text -> UValue
UText (Text -> UValue)
-> ParsecT Void Text Identity Text -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity Text
textP
UArray [UValue]
_ -> [UValue] -> UValue
UArray ([UValue] -> UValue) -> Parser [UValue] -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [UValue]
arrayP
spComma :: Parser ()
spComma :: ParsecT Void Text Identity ()
spComma = Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
',' ParsecT Void Text Identity Char
-> ParsecT Void Text Identity () -> ParsecT Void Text Identity ()
forall a b.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity b -> ParsecT Void Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text Identity ()
sc
valueP :: Parser UValue
valueP :: Parser UValue
valueP = Text -> UValue
UText (Text -> UValue)
-> ParsecT Void Text Identity Text -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text Identity Text
textP
Parser UValue -> Parser UValue -> Parser UValue
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Bool -> UValue
UBool (Bool -> UValue) -> Parser Bool -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
boolP
Parser UValue -> Parser UValue -> Parser UValue
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [UValue] -> UValue
UArray ([UValue] -> UValue) -> Parser [UValue] -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [UValue]
arrayP
Parser UValue -> Parser UValue -> Parser UValue
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser UValue
dateTimeP
Parser UValue -> Parser UValue -> Parser UValue
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Double -> UValue
UDouble (Double -> UValue) -> Parser Double -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Double -> Parser Double
forall a.
ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try Parser Double
doubleP
Parser UValue -> Parser UValue -> Parser UValue
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Integer -> UValue
UInteger (Integer -> UValue) -> Parser Integer -> Parser UValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Integer
integerP
anyValueP :: Parser AnyValue
anyValueP :: Parser AnyValue
anyValueP = UValue -> Either TypeMismatchError AnyValue
typeCheck (UValue -> Either TypeMismatchError AnyValue)
-> Parser UValue
-> ParsecT Void Text Identity (Either TypeMismatchError AnyValue)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser UValue
valueP ParsecT Void Text Identity (Either TypeMismatchError AnyValue)
-> (Either TypeMismatchError AnyValue -> Parser AnyValue)
-> Parser AnyValue
forall a b.
ParsecT Void Text Identity a
-> (a -> ParsecT Void Text Identity b)
-> ParsecT Void Text Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left TypeMismatchError
err -> [Char] -> Parser AnyValue
forall a. [Char] -> ParsecT Void Text Identity a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char] -> Parser AnyValue) -> [Char] -> Parser AnyValue
forall a b. (a -> b) -> a -> b
$ TypeMismatchError -> [Char]
forall a. Show a => a -> [Char]
show TypeMismatchError
err
Right AnyValue
v -> AnyValue -> Parser AnyValue
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AnyValue
v