{-# OPTIONS -fallow-overlapping-instances -fallow-undecidable-instances -fglasgow-exts #-}
{-# language DefaultSignatures, IncoherentInstances #-}
module Autolib.Reader.Class
( Reader (..), readerPrec, readerParenPrec, parse_complete
, atomic_readerPrec_with
, module Export_Trickery
, guard
, fcp
, listify
)
where
import Text.ParserCombinators.Parsec
hiding ( label, State )
import Text.ParserCombinators.Parsec as Export_Trickery
hiding ( label, State )
import Control.Monad ( guard, void )
import Autolib.Reader.Basic ( my_parens, my_brackets, my_braces, my_reserved, my_equals, my_comma, my_symbol )
import Text.ParserCombinators.Parsec.Token ( whiteSpace, commaSep )
import Autolib.Reader.Basic ( haskell)
import Data.List (isSuffixOf)
import GHC.Generics
import Data.Either
import Autolib.Multilingual.Doc (Doc, text)
import Autolib.ToDoc (fcp)
class Reader a where
atomic_reader :: Parser a
atomic_reader = Int -> Parser a
forall a. Reader a => Int -> Parser a
atomic_readerPrec Int
0
atomic_readerPrec :: Int -> Parser a
default atomic_readerPrec :: (Generic a, GReader (Rep a))
=> Int -> Parser a
atomic_readerPrec Int
p = Rep a (ZonkAny 1) -> a
forall a x. Generic a => Rep a x -> a
forall x. Rep a x -> a
to (Rep a (ZonkAny 1) -> a)
-> ParsecT String () Identity (Rep a (ZonkAny 1)) -> Parser a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Rep a (ZonkAny 1))
-> Type -> Int -> ParsecT String () Identity (Rep a (ZonkAny 1))
forall p. Maybe (Rep a p) -> Type -> Int -> Parser (Rep a p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrec Maybe (Rep a (ZonkAny 1))
forall a. Maybe a
Nothing Type
Pref Int
p
reader :: Parser a
reader = Int -> Parser a
forall a. Reader a => Int -> Parser a
readerPrec Int
0
readerPrec :: Int -> Parser a
readerPrec Int
d = Int -> (Int -> Parser a) -> Parser a
forall a. Int -> (Int -> Parser a) -> Parser a
readerParenPrec Int
d Int -> Parser a
forall a. Reader a => Int -> Parser a
atomic_readerPrec
readerList :: Parser [a]
readerList = Parser a -> Parser [a]
forall a. Parser a -> Parser [a]
listify Parser a
forall a. Reader a => Parser a
reader
atomic_readerPrec_with
:: (Generic a, GReader (Rep a))
=> a -> Int -> Parser a
atomic_readerPrec_with :: forall a. (Generic a, GReader (Rep a)) => a -> Int -> Parser a
atomic_readerPrec_with a
def Int
p =
Rep a (ZonkAny 0) -> a
forall a x. Generic a => Rep a x -> a
forall x. Rep a x -> a
to (Rep a (ZonkAny 0) -> a)
-> ParsecT String () Identity (Rep a (ZonkAny 0))
-> ParsecT String () Identity a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Rep a (ZonkAny 0))
-> Type -> Int -> ParsecT String () Identity (Rep a (ZonkAny 0))
forall p. Maybe (Rep a p) -> Type -> Int -> Parser (Rep a p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrec (Rep a (ZonkAny 0) -> Maybe (Rep a (ZonkAny 0))
forall a. a -> Maybe a
Just (Rep a (ZonkAny 0) -> Maybe (Rep a (ZonkAny 0)))
-> Rep a (ZonkAny 0) -> Maybe (Rep a (ZonkAny 0))
forall a b. (a -> b) -> a -> b
$ a -> Rep a (ZonkAny 0)
forall x. a -> Rep a x
forall a x. Generic a => a -> Rep a x
from a
def) Type
Pref Int
p
listify :: Parser a -> Parser [a]
listify :: forall a. Parser a -> Parser [a]
listify Parser a
p = Parser [a] -> Parser [a]
forall a. Parser a -> Parser a
my_brackets ( GenTokenParser String () Identity
-> forall a. Parser a -> Parser [a]
forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m [a]
commaSep GenTokenParser String () Identity
forall {u}. GenTokenParser String u Identity
haskell Parser a
p )
data Type = Rec | Tup | Pref
data Status = Doing | Done
class GReader f where
gReaderPrec :: Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrecSel
:: Maybe (f p) -> Type -> Int -> Parser (f p)
instance GReader U1 where
gReaderPrec :: forall p. Maybe (U1 p) -> Type -> Int -> Parser (U1 p)
gReaderPrec Maybe (U1 p)
_ Type
_ Int
p = U1 p -> ParsecT String () Identity (U1 p)
forall a. a -> ParsecT String () Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return U1 p
forall k (p :: k). U1 p
U1
instance Reader c => GReader (K1 i c) where
gReaderPrec :: forall p. Maybe (K1 i c p) -> Type -> Int -> Parser (K1 i c p)
gReaderPrec Maybe (K1 i c p)
d Type
_ Int
p =
case Maybe (K1 i c p)
d of
Maybe (K1 i c p)
Nothing -> c -> K1 i c p
forall k i c (p :: k). c -> K1 i c p
K1 (c -> K1 i c p)
-> ParsecT String () Identity c -> Parser (K1 i c p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ParsecT String () Identity c
forall a. Reader a => Int -> Parser a
readerPrec Int
p
Just K1 i c p
d -> (c -> K1 i c p
forall k i c (p :: k). c -> K1 i c p
K1 (c -> K1 i c p)
-> ParsecT String () Identity c -> Parser (K1 i c p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ParsecT String () Identity c
forall a. Reader a => Int -> Parser a
readerPrec Int
p) Parser (K1 i c p) -> Parser (K1 i c p) -> Parser (K1 i c p)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> K1 i c p -> Parser (K1 i c p)
forall a. a -> ParsecT String () Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return K1 i c p
d
instance (GReader f, GReader g) => GReader (f :+: g) where
gReaderPrec :: forall p.
Maybe ((:+:) f g p) -> Type -> Int -> Parser ((:+:) f g p)
gReaderPrec Maybe ((:+:) f g p)
d Type
t Int
p =
let (Maybe (f p)
dl,Maybe (g p)
dr) = case Maybe ((:+:) f g p)
d of
Maybe ((:+:) f g p)
Nothing -> (Maybe (f p)
forall a. Maybe a
Nothing,Maybe (g p)
forall a. Maybe a
Nothing)
Just (L1 f p
d) -> (f p -> Maybe (f p)
forall a. a -> Maybe a
Just f p
d, Maybe (g p)
forall a. Maybe a
Nothing)
Just (R1 g p
d) -> (Maybe (f p)
forall a. Maybe a
Nothing, g p -> Maybe (g p)
forall a. a -> Maybe a
Just g p
d)
in f p -> (:+:) f g p
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 (f p -> (:+:) f g p)
-> ParsecT String () Identity (f p)
-> ParsecT String () Identity ((:+:) f g p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (f p) -> Type -> Int -> ParsecT String () Identity (f p)
forall p. Maybe (f p) -> Type -> Int -> Parser (f p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrec Maybe (f p)
dl Type
t Int
p ParsecT String () Identity ((:+:) f g p)
-> ParsecT String () Identity ((:+:) f g p)
-> ParsecT String () Identity ((:+:) f g p)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> g p -> (:+:) f g p
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (g p -> (:+:) f g p)
-> ParsecT String () Identity (g p)
-> ParsecT String () Identity ((:+:) f g p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (g p) -> Type -> Int -> ParsecT String () Identity (g p)
forall p. Maybe (g p) -> Type -> Int -> Parser (g p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrec Maybe (g p)
dr Type
t Int
p
instance (GReader f, GReader g) => GReader (f :*: g) where
gReaderPrecSel :: forall p.
Maybe ((:*:) f g p) -> Type -> Int -> Parser ((:*:) f g p)
gReaderPrecSel Maybe ((:*:) f g p)
d Type
m Int
p = do
let (Maybe (f p)
dl,Maybe (g p)
dr) = case Maybe ((:*:) f g p)
d of
Maybe ((:*:) f g p)
Nothing -> (Maybe (f p)
forall a. Maybe a
Nothing,Maybe (g p)
forall a. Maybe a
Nothing)
Just (f p
l :*: g p
r) -> (f p -> Maybe (f p)
forall a. a -> Maybe a
Just f p
l, g p -> Maybe (g p)
forall a. a -> Maybe a
Just g p
r)
f p -> g p -> (:*:) f g p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:) (f p -> g p -> (:*:) f g p)
-> ParsecT String () Identity (f p)
-> ParsecT String () Identity (g p -> (:*:) f g p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (f p) -> Type -> Int -> ParsecT String () Identity (f p)
forall p. Maybe (f p) -> Type -> Int -> Parser (f p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrecSel Maybe (f p)
dl Type
m Int
p ParsecT String () Identity (g p -> (:*:) f g p)
-> ParsecT String () Identity (g p)
-> ParsecT String () Identity ((:*:) f g p)
forall a b.
ParsecT String () Identity (a -> b)
-> ParsecT String () Identity a -> ParsecT String () Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe (g p) -> Type -> Int -> ParsecT String () Identity (g p)
forall p. Maybe (g p) -> Type -> Int -> Parser (g p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrecSel Maybe (g p)
dr Type
m Int
p
gReaderPrec :: forall p.
Maybe ((:*:) f g p) -> Type -> Int -> Parser ((:*:) f g p)
gReaderPrec Maybe ((:*:) f g p)
d Type
m Int
p = do
let (Maybe (f p)
dl,Maybe (g p)
dr) = case Maybe ((:*:) f g p)
d of
Maybe ((:*:) f g p)
Nothing -> (Maybe (f p)
forall a. Maybe a
Nothing,Maybe (g p)
forall a. Maybe a
Nothing)
Just (f p
l :*: g p
r) -> (f p -> Maybe (f p)
forall a. a -> Maybe a
Just f p
l, g p -> Maybe (g p)
forall a. a -> Maybe a
Just g p
r)
f p -> g p -> (:*:) f g p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:) (f p -> g p -> (:*:) f g p)
-> ParsecT String () Identity (f p)
-> ParsecT String () Identity (g p -> (:*:) f g p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (f p) -> Type -> Int -> ParsecT String () Identity (f p)
forall p. Maybe (f p) -> Type -> Int -> Parser (f p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrec Maybe (f p)
dl Type
m Int
p ParsecT String () Identity (g p -> (:*:) f g p)
-> ParsecT String () Identity (g p)
-> ParsecT String () Identity ((:*:) f g p)
forall a b.
ParsecT String () Identity (a -> b)
-> ParsecT String () Identity a -> ParsecT String () Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe (g p) -> Type -> Int -> ParsecT String () Identity (g p)
forall p. Maybe (g p) -> Type -> Int -> Parser (g p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrec Maybe (g p)
dr Type
m Int
p
instance (Constructor c) => GReader (C1 c U1) where
gReaderPrec :: forall p. Maybe (C1 c U1 p) -> Type -> Int -> Parser (C1 c U1 p)
gReaderPrec Maybe (C1 c U1 p)
_ Type
_ Int
p =
let c :: C1 c f p
c = C1 c f p
forall a. HasCallStack => a
forall {f :: * -> *} {p}. C1 c f p
undefined :: C1 c f p
in ( String -> Parser ()
my_reserved (M1 C c (ZonkAny 8) (ZonkAny 7) -> String
forall {k} (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
(f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> String
forall k1 (t :: Meta -> (k1 -> *) -> k1 -> *) (f :: k1 -> *)
(a :: k1).
t c f a -> String
conName M1 C c (ZonkAny 8) (ZonkAny 7)
forall {f :: * -> *} {p}. C1 c f p
c) Parser ()
-> ParsecT String () Identity (C1 c U1 p)
-> ParsecT String () Identity (C1 c U1 p)
forall a b.
ParsecT String () Identity a
-> ParsecT String () Identity b -> ParsecT String () Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ( U1 p -> C1 c U1 p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (U1 p -> C1 c U1 p)
-> ParsecT String () Identity (U1 p)
-> ParsecT String () Identity (C1 c U1 p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> U1 p -> ParsecT String () Identity (U1 p)
forall a. a -> ParsecT String () Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return U1 p
forall k (p :: k). U1 p
U1 ) )
instance (Constructor c, GReader f) => GReader (C1 c f) where
gReaderPrec :: forall p. Maybe (C1 c f p) -> Type -> Int -> Parser (C1 c f p)
gReaderPrec Maybe (C1 c f p)
d Type
_ Int
p =
let c :: C1 c f p
c = C1 c f p
forall {p}. C1 c f p
forall a. HasCallStack => a
undefined :: C1 c f p
dd :: Maybe (f p)
dd = case Maybe (C1 c f p)
d of Maybe (C1 c f p)
Nothing -> Maybe (f p)
forall a. Maybe a
Nothing ; Just (M1 f p
d) -> f p -> Maybe (f p)
forall a. a -> Maybe a
Just f p
d
in if M1 C c f (ZonkAny 4) -> Bool
forall {k} (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
(f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> Bool
forall k1 (t :: Meta -> (k1 -> *) -> k1 -> *) (f :: k1 -> *)
(a :: k1).
t c f a -> Bool
conIsRecord M1 C c f (ZonkAny 4)
forall {p}. C1 c f p
c
then String -> Parser ()
my_reserved (M1 C c f (ZonkAny 5) -> String
forall {k} (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
(f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> String
forall k1 (t :: Meta -> (k1 -> *) -> k1 -> *) (f :: k1 -> *)
(a :: k1).
t c f a -> String
conName M1 C c f (ZonkAny 5)
forall {p}. C1 c f p
c) Parser ()
-> ParsecT String () Identity (C1 c f p)
-> ParsecT String () Identity (C1 c f p)
forall a b.
ParsecT String () Identity a
-> ParsecT String () Identity b -> ParsecT String () Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
ParsecT String () Identity (C1 c f p)
-> ParsecT String () Identity (C1 c f p)
forall a. Parser a -> Parser a
my_braces ( f p -> C1 c f p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (f p -> C1 c f p)
-> ParsecT String () Identity (f p)
-> ParsecT String () Identity (C1 c f p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (f p) -> Type -> Int -> ParsecT String () Identity (f p)
forall p. Maybe (f p) -> Type -> Int -> Parser (f p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrecSel Maybe (f p)
dd Type
Rec Int
0 )
else ( if Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
fcp then ParsecT String () Identity (C1 c f p)
-> ParsecT String () Identity (C1 c f p)
forall a. a -> a
id else ParsecT String () Identity (C1 c f p)
-> ParsecT String () Identity (C1 c f p)
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT String () Identity (C1 c f p)
-> ParsecT String () Identity (C1 c f p))
-> (ParsecT String () Identity (C1 c f p)
-> ParsecT String () Identity (C1 c f p))
-> ParsecT String () Identity (C1 c f p)
-> ParsecT String () Identity (C1 c f p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsecT String () Identity (C1 c f p)
-> ParsecT String () Identity (C1 c f p)
forall a. Parser a -> Parser a
my_parens )
( String -> Parser ()
my_reserved (M1 C c f (ZonkAny 6) -> String
forall {k} (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
(f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> String
forall k1 (t :: Meta -> (k1 -> *) -> k1 -> *) (f :: k1 -> *)
(a :: k1).
t c f a -> String
conName M1 C c f (ZonkAny 6)
forall {p}. C1 c f p
c) Parser ()
-> ParsecT String () Identity (C1 c f p)
-> ParsecT String () Identity (C1 c f p)
forall a b.
ParsecT String () Identity a
-> ParsecT String () Identity b -> ParsecT String () Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ( f p -> C1 c f p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (f p -> C1 c f p)
-> ParsecT String () Identity (f p)
-> ParsecT String () Identity (C1 c f p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (f p) -> Type -> Int -> ParsecT String () Identity (f p)
forall p. Maybe (f p) -> Type -> Int -> Parser (f p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrec Maybe (f p)
dd Type
Pref Int
fcp ) )
instance (Selector s, GReader f) => GReader (S1 s f) where
gReaderPrecSel :: forall p. Maybe (S1 s f p) -> Type -> Int -> Parser (S1 s f p)
gReaderPrecSel Maybe (S1 s f p)
d Type
Rec Int
p = do
let s :: S1 s f p
s = S1 s f p
forall {p}. S1 s f p
forall a. HasCallStack => a
undefined :: S1 s f p
dd :: Maybe (f p)
dd = case Maybe (S1 s f p)
d of Maybe (S1 s f p)
Nothing -> Maybe (f p)
forall a. Maybe a
Nothing ; Just (M1 f p
d) -> f p -> Maybe (f p)
forall a. a -> Maybe a
Just f p
d
if String
"_info" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isSuffixOf` M1 S s f (ZonkAny 2) -> String
forall {k} (s :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
(f :: k1 -> *) (a :: k1).
Selector s =>
t s f a -> String
forall k1 (t :: Meta -> (k1 -> *) -> k1 -> *) (f :: k1 -> *)
(a :: k1).
t s f a -> String
selName M1 S s f (ZonkAny 2)
forall {p}. S1 s f p
s
then
case Maybe (f p)
dd of
Maybe (f p)
Nothing ->
case Parser (S1 s f p)
-> () -> String -> String -> Either ParseError (S1 s f p)
forall tok st a.
GenParser tok st a -> st -> String -> [tok] -> Either ParseError a
runParser (Maybe (S1 s f p) -> Type -> Int -> Parser (S1 s f p)
forall p. Maybe (S1 s f p) -> Type -> Int -> Parser (S1 s f p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrec Maybe (S1 s f p)
forall a. Maybe a
Nothing Type
Pref Int
0) () String
"<>" String
"_info" of
Left ParseError
e -> String -> Parser (S1 s f p)
forall a. HasCallStack => String -> a
error String
"cannot parse canned default value for _info component"
Right S1 s f p
x -> S1 s f p -> Parser (S1 s f p)
forall a. a -> ParsecT String () Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return S1 s f p
x
Just f p
d -> S1 s f p -> Parser (S1 s f p)
forall a. a -> ParsecT String () Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (S1 s f p -> Parser (S1 s f p)) -> S1 s f p -> Parser (S1 s f p)
forall a b. (a -> b) -> a -> b
$ f p -> S1 s f p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 f p
d
else
(String -> Parser ()
my_reserved (M1 S s f (ZonkAny 3) -> String
forall {k} (s :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
(f :: k1 -> *) (a :: k1).
Selector s =>
t s f a -> String
forall k1 (t :: Meta -> (k1 -> *) -> k1 -> *) (f :: k1 -> *)
(a :: k1).
t s f a -> String
selName M1 S s f (ZonkAny 3)
forall {p}. S1 s f p
s) Parser () -> Parser () -> Parser ()
forall a b.
ParsecT String () Identity a
-> ParsecT String () Identity b -> ParsecT String () Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ()
my_equals Parser () -> Parser (S1 s f p) -> Parser (S1 s f p)
forall a b.
ParsecT String () Identity a
-> ParsecT String () Identity b -> ParsecT String () Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ( f p -> S1 s f p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (f p -> S1 s f p)
-> ParsecT String () Identity (f p) -> Parser (S1 s f p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (f p) -> Type -> Int -> ParsecT String () Identity (f p)
forall p. Maybe (f p) -> Type -> Int -> Parser (f p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrec Maybe (f p)
dd Type
Pref Int
0 ) Parser (S1 s f p)
-> ParsecT String () Identity String -> Parser (S1 s f p)
forall a b.
ParsecT String () Identity a
-> ParsecT String () Identity b -> ParsecT String () Identity a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (ParsecT String () Identity String
my_comma ParsecT String () Identity String
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (String -> ParsecT String () Identity String
my_symbol String
"}")))
Parser (S1 s f p) -> Parser (S1 s f p) -> Parser (S1 s f p)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> case Maybe (f p)
dd of
Maybe (f p)
Nothing -> String -> Parser (S1 s f p)
forall s (m :: * -> *) t u a.
Stream s m t =>
String -> ParsecT s u m a
unexpected String
"missing"
Just f p
d -> S1 s f p -> Parser (S1 s f p)
forall a. a -> ParsecT String () Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (S1 s f p -> Parser (S1 s f p)) -> S1 s f p -> Parser (S1 s f p)
forall a b. (a -> b) -> a -> b
$ f p -> S1 s f p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 f p
d
gReaderPrec :: forall p. Maybe (S1 s f p) -> Type -> Int -> Parser (S1 s f p)
gReaderPrec Maybe (S1 s f p)
d Type
t Int
p =
let dd :: Maybe (f p)
dd = case Maybe (S1 s f p)
d of Maybe (S1 s f p)
Nothing -> Maybe (f p)
forall a. Maybe a
Nothing; Just (M1 f p
d) -> f p -> Maybe (f p)
forall a. a -> Maybe a
Just f p
d
in f p -> S1 s f p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (f p -> S1 s f p)
-> ParsecT String () Identity (f p)
-> ParsecT String () Identity (S1 s f p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (f p) -> Type -> Int -> ParsecT String () Identity (f p)
forall p. Maybe (f p) -> Type -> Int -> Parser (f p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrec Maybe (f p)
dd Type
t Int
p
instance GReader f => GReader (M1 D c f) where
gReaderPrec :: forall p. Maybe (M1 D c f p) -> Type -> Int -> Parser (M1 D c f p)
gReaderPrec Maybe (M1 D c f p)
d Type
_ Int
p =
let dd :: Maybe (f p)
dd = case Maybe (M1 D c f p)
d of Maybe (M1 D c f p)
Nothing -> Maybe (f p)
forall a. Maybe a
Nothing; Just (M1 f p
d) -> f p -> Maybe (f p)
forall a. a -> Maybe a
Just f p
d
in f p -> M1 D c f p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (f p -> M1 D c f p)
-> ParsecT String () Identity (f p)
-> ParsecT String () Identity (M1 D c f p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (f p) -> Type -> Int -> ParsecT String () Identity (f p)
forall p. Maybe (f p) -> Type -> Int -> Parser (f p)
forall (f :: * -> *) p.
GReader f =>
Maybe (f p) -> Type -> Int -> Parser (f p)
gReaderPrec Maybe (f p)
dd Type
Pref Int
p
ends_with_comma_or_close :: ParsecT String () Identity a
-> ParsecT String () Identity (a, Status)
ends_with_comma_or_close ParsecT String () Identity a
p = do
x <- ParsecT String () Identity a
p
my_comma *> return (x, Doing)
<|> my_symbol "}" *> return (x, Done)
class Is_Empty t where is_empty :: t -> Bool
instance Is_Empty (U1 p) where is_empty :: U1 p -> Bool
is_empty U1 p
_ = Bool
True
instance Is_Empty t where is_empty :: t -> Bool
is_empty t
_ = Bool
False
data B = F | T deriving (Int -> B -> ShowS
[B] -> ShowS
B -> String
(Int -> B -> ShowS) -> (B -> String) -> ([B] -> ShowS) -> Show B
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> B -> ShowS
showsPrec :: Int -> B -> ShowS
$cshow :: B -> String
show :: B -> String
$cshowList :: [B] -> ShowS
showList :: [B] -> ShowS
Show, (forall x. B -> Rep B x) -> (forall x. Rep B x -> B) -> Generic B
forall x. Rep B x -> B
forall x. B -> Rep B x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. B -> Rep B x
from :: forall x. B -> Rep B x
$cto :: forall x. Rep B x -> B
to :: forall x. Rep B x -> B
Generic)
instance Reader B
data Foo = Foo | Bar { Foo -> B
baz :: B } deriving (Int -> Foo -> ShowS
[Foo] -> ShowS
Foo -> String
(Int -> Foo -> ShowS)
-> (Foo -> String) -> ([Foo] -> ShowS) -> Show Foo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Foo -> ShowS
showsPrec :: Int -> Foo -> ShowS
$cshow :: Foo -> String
show :: Foo -> String
$cshowList :: [Foo] -> ShowS
showList :: [Foo] -> ShowS
Show, (forall x. Foo -> Rep Foo x)
-> (forall x. Rep Foo x -> Foo) -> Generic Foo
forall x. Rep Foo x -> Foo
forall x. Foo -> Rep Foo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Foo -> Rep Foo x
from :: forall x. Foo -> Rep Foo x
$cto :: forall x. Rep Foo x -> Foo
to :: forall x. Rep Foo x -> Foo
Generic)
instance Reader Foo
data Bar = Cons B Bar | Nil deriving ( Int -> Bar -> ShowS
[Bar] -> ShowS
Bar -> String
(Int -> Bar -> ShowS)
-> (Bar -> String) -> ([Bar] -> ShowS) -> Show Bar
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Bar -> ShowS
showsPrec :: Int -> Bar -> ShowS
$cshow :: Bar -> String
show :: Bar -> String
$cshowList :: [Bar] -> ShowS
showList :: [Bar] -> ShowS
Show, (forall x. Bar -> Rep Bar x)
-> (forall x. Rep Bar x -> Bar) -> Generic Bar
forall x. Rep Bar x -> Bar
forall x. Bar -> Rep Bar x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Bar -> Rep Bar x
from :: forall x. Bar -> Rep Bar x
$cto :: forall x. Rep Bar x -> Bar
to :: forall x. Rep Bar x -> Bar
Generic )
instance Reader Bar
data Fob = C Bar Foo deriving (Int -> Fob -> ShowS
[Fob] -> ShowS
Fob -> String
(Int -> Fob -> ShowS)
-> (Fob -> String) -> ([Fob] -> ShowS) -> Show Fob
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Fob -> ShowS
showsPrec :: Int -> Fob -> ShowS
$cshow :: Fob -> String
show :: Fob -> String
$cshowList :: [Fob] -> ShowS
showList :: [Fob] -> ShowS
Show, (forall x. Fob -> Rep Fob x)
-> (forall x. Rep Fob x -> Fob) -> Generic Fob
forall x. Rep Fob x -> Fob
forall x. Fob -> Rep Fob x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Fob -> Rep Fob x
from :: forall x. Fob -> Rep Fob x
$cto :: forall x. Rep Fob x -> Fob
to :: forall x. Rep Fob x -> Fob
Generic)
instance Reader Fob
readerParenPrec :: Int -> ( Int -> Parser a ) -> Parser a
readerParenPrec :: forall a. Int -> (Int -> Parser a) -> Parser a
readerParenPrec Int
d Int -> Parser a
pp
= Int -> Parser a
pp Int
d
Parser a -> Parser a -> Parser a
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser a -> Parser a
forall a. Parser a -> Parser a
my_parens ( Int -> (Int -> Parser a) -> Parser a
forall a. Int -> (Int -> Parser a) -> Parser a
readerParenPrec Int
0 Int -> Parser a
pp )
parse_complete :: Parser p -> Parser p
parse_complete :: forall a. Parser a -> Parser a
parse_complete Parser p
p = do
ParsecT String () Identity Char
-> ParsecT String () Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
space
x <- Parser p
p
eof
return x
instance Reader Doc where atomic_readerPrec :: Int -> Parser Doc
atomic_readerPrec Int
_ = Doc -> Parser Doc
forall a. a -> ParsecT String () Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Doc -> Parser Doc) -> Doc -> Parser Doc
forall a b. (a -> b) -> a -> b
$ String -> Doc
text String
"_info"