{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE TypeOperators #-}
module Language.SexpGrammar.Class
( SexpGrammar
, SexpIso(..)
) where
import Prelude hiding ((.), id)
import Control.Arrow
import Control.Category
import Data.InvertibleGrammar
import qualified Data.List.NonEmpty as NE
import Data.Map (Map)
import Data.Scientific
import Data.Set (Set)
import Data.Text (Text)
import qualified Data.Map as Map
import qualified Data.Set as Set
#if !MIN_VERSION_base(4,11,0)
import Data.Semigroup
#endif
import Language.Sexp.Located
import Language.SexpGrammar.Base
import Language.SexpGrammar.Generic
type SexpGrammar a = forall t. Grammar Position (Sexp :- t) (a :- t)
class SexpIso a where
sexpIso :: SexpGrammar a
instance SexpIso () where
sexpIso :: SexpGrammar ()
sexpIso = forall a b s t (c :: Meta) (d :: Meta) (f :: * -> *) p.
(Generic a, MkPrismList (Rep a), MkStackPrism f,
Rep a ~ M1 D d (M1 C c f), StackPrismLhs f t ~ b, Constructor c) =>
(Grammar p b (a :- t) -> Grammar p s (a :- t))
-> Grammar p s (a :- t)
with forall a b. (a -> b) -> a -> b
$ \Grammar Position t (() :- t)
unit ->
forall t. Text -> Grammar Position (Sexp :- t) t
sym Text
"nil" forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Grammar Position t (() :- t)
unit
instance SexpIso Bool where
sexpIso :: SexpGrammar Bool
sexpIso = forall a (bs :: [*]) t p s.
(Generic a, MkPrismList (Rep a), Match (Rep a) bs t,
bs ~ Coll (Rep a) t) =>
Coproduct p s bs a t -> Grammar p s (a :- t)
match
forall a b. (a -> b) -> a -> b
$ forall p b a t s (bs1 :: [*]).
(Grammar p b (a :- t) -> Grammar p s (a :- t))
-> Coproduct p s bs1 a t -> Coproduct p s (b : bs1) a t
With (\Grammar Position t (Bool :- t)
false_ -> forall t. Text -> Grammar Position (Sexp :- t) t
sym Text
"false" forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Grammar Position t (Bool :- t)
false_)
forall a b. (a -> b) -> a -> b
$ forall p b a t s (bs1 :: [*]).
(Grammar p b (a :- t) -> Grammar p s (a :- t))
-> Coproduct p s bs1 a t -> Coproduct p s (b : bs1) a t
With (\Grammar Position t (Bool :- t)
true_ -> forall t. Text -> Grammar Position (Sexp :- t) t
sym Text
"true" forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Grammar Position t (Bool :- t)
true_)
forall a b. (a -> b) -> a -> b
$ forall p s a t. Coproduct p s '[] a t
End
instance SexpIso Int where
sexpIso :: SexpGrammar Int
sexpIso = SexpGrammar Int
int
instance SexpIso Integer where
sexpIso :: SexpGrammar Integer
sexpIso = SexpGrammar Integer
integer
instance SexpIso Double where
sexpIso :: SexpGrammar Double
sexpIso = SexpGrammar Double
double
instance SexpIso Scientific where
sexpIso :: SexpGrammar Scientific
sexpIso = SexpGrammar Scientific
real
instance SexpIso Text where
sexpIso :: SexpGrammar Text
sexpIso = SexpGrammar Text
string
instance (SexpIso a, SexpIso b) => SexpIso (a, b) where
sexpIso :: SexpGrammar (a, b)
sexpIso =
forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
list (
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall p b a t. Grammar p (b :- (a :- t)) ((a, b) :- t)
pair
instance (SexpIso a, SexpIso b, SexpIso c) => SexpIso (a, b, c) where
sexpIso :: SexpGrammar (a, b, c)
sexpIso = forall a b s t (c :: Meta) (d :: Meta) (f :: * -> *) p.
(Generic a, MkPrismList (Rep a), MkStackPrism f,
Rep a ~ M1 D d (M1 C c f), StackPrismLhs f t ~ b, Constructor c) =>
(Grammar p b (a :- t) -> Grammar p s (a :- t))
-> Grammar p s (a :- t)
with forall a b. (a -> b) -> a -> b
$ \Grammar Position (c :- (b :- (a :- t))) ((a, b, c) :- t)
tuple3 ->
forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
list (
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Grammar Position (c :- (b :- (a :- t))) ((a, b, c) :- t)
tuple3
instance (SexpIso a, SexpIso b, SexpIso c, SexpIso d) => SexpIso (a, b, c, d) where
sexpIso :: SexpGrammar (a, b, c, d)
sexpIso = forall a b s t (c :: Meta) (d :: Meta) (f :: * -> *) p.
(Generic a, MkPrismList (Rep a), MkStackPrism f,
Rep a ~ M1 D d (M1 C c f), StackPrismLhs f t ~ b, Constructor c) =>
(Grammar p b (a :- t) -> Grammar p s (a :- t))
-> Grammar p s (a :- t)
with forall a b. (a -> b) -> a -> b
$ \Grammar Position (d :- (c :- (b :- (a :- t)))) ((a, b, c, d) :- t)
tuple4 ->
forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
list (
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Grammar Position (d :- (c :- (b :- (a :- t)))) ((a, b, c, d) :- t)
tuple4
instance (SexpIso a, SexpIso b, SexpIso c, SexpIso d, SexpIso e) => SexpIso (a, b, c, d, e) where
sexpIso :: SexpGrammar (a, b, c, d, e)
sexpIso = forall a b s t (c :: Meta) (d :: Meta) (f :: * -> *) p.
(Generic a, MkPrismList (Rep a), MkStackPrism f,
Rep a ~ M1 D d (M1 C c f), StackPrismLhs f t ~ b, Constructor c) =>
(Grammar p b (a :- t) -> Grammar p s (a :- t))
-> Grammar p s (a :- t)
with forall a b. (a -> b) -> a -> b
$ \Grammar
Position
(e :- (d :- (c :- (b :- (a :- t)))))
((a, b, c, d, e) :- t)
tuple5 ->
forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
list (
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Grammar
Position
(e :- (d :- (c :- (b :- (a :- t)))))
((a, b, c, d, e) :- t)
tuple5
instance (SexpIso a, SexpIso b, SexpIso c, SexpIso d, SexpIso e, SexpIso f) => SexpIso (a, b, c, d, e, f) where
sexpIso :: SexpGrammar (a, b, c, d, e, f)
sexpIso = forall a b s t (c :: Meta) (d :: Meta) (f :: * -> *) p.
(Generic a, MkPrismList (Rep a), MkStackPrism f,
Rep a ~ M1 D d (M1 C c f), StackPrismLhs f t ~ b, Constructor c) =>
(Grammar p b (a :- t) -> Grammar p s (a :- t))
-> Grammar p s (a :- t)
with forall a b. (a -> b) -> a -> b
$ \Grammar
Position
(f :- (e :- (d :- (c :- (b :- (a :- t))))))
((a, b, c, d, e, f) :- t)
tuple6 ->
forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
list (
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Grammar
Position
(f :- (e :- (d :- (c :- (b :- (a :- t))))))
((a, b, c, d, e, f) :- t)
tuple6
instance (SexpIso a, SexpIso b, SexpIso c, SexpIso d, SexpIso e, SexpIso f, SexpIso g) =>
SexpIso (a, b, c, d, e, f, g) where
sexpIso :: SexpGrammar (a, b, c, d, e, f, g)
sexpIso = forall a b s t (c :: Meta) (d :: Meta) (f :: * -> *) p.
(Generic a, MkPrismList (Rep a), MkStackPrism f,
Rep a ~ M1 D d (M1 C c f), StackPrismLhs f t ~ b, Constructor c) =>
(Grammar p b (a :- t) -> Grammar p s (a :- t))
-> Grammar p s (a :- t)
with forall a b. (a -> b) -> a -> b
$ \Grammar
Position
(g :- (f :- (e :- (d :- (c :- (b :- (a :- t)))))))
((a, b, c, d, e, f, g) :- t)
tuple7 ->
forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
list (
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Grammar
Position
(g :- (f :- (e :- (d :- (c :- (b :- (a :- t)))))))
((a, b, c, d, e, f, g) :- t)
tuple7
instance (Ord k, SexpIso k, SexpIso v) => SexpIso (Map k v) where
sexpIso :: SexpGrammar (Map k v)
sexpIso = forall a b p t. (a -> b) -> (b -> a) -> Grammar p (a :- t) (b :- t)
iso forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall k a. Map k a -> [(k, a)]
Map.toList forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
braceList (forall a t.
(forall t1. Grammar Position (Sexp :- t1) (a :- t1))
-> Grammar Position (List :- t) (List :- ([a] :- t))
rest forall a. SexpIso a => SexpGrammar a
sexpIso)
instance (Ord a, SexpIso a) => SexpIso (Set a) where
sexpIso :: SexpGrammar (Set a)
sexpIso = forall a b p t. (a -> b) -> (b -> a) -> Grammar p (a :- t) (b :- t)
iso forall a. Ord a => [a] -> Set a
Set.fromList forall a. Set a -> [a]
Set.toList forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
braceList (forall a t.
(forall t1. Grammar Position (Sexp :- t1) (a :- t1))
-> Grammar Position (List :- t) (List :- ([a] :- t))
rest forall a. SexpIso a => SexpGrammar a
sexpIso)
instance (SexpIso a) => SexpIso (Maybe a) where
sexpIso :: SexpGrammar (Maybe a)
sexpIso = forall a (bs :: [*]) t p s.
(Generic a, MkPrismList (Rep a), Match (Rep a) bs t,
bs ~ Coll (Rep a) t) =>
Coproduct p s bs a t -> Grammar p s (a :- t)
match
forall a b. (a -> b) -> a -> b
$ forall p b a t s (bs1 :: [*]).
(Grammar p b (a :- t) -> Grammar p s (a :- t))
-> Coproduct p s bs1 a t -> Coproduct p s (b : bs1) a t
With (\Grammar Position t (Maybe a :- t)
nothing -> forall t. Text -> Grammar Position (Sexp :- t) t
sym Text
"nil" forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Grammar Position t (Maybe a :- t)
nothing)
forall a b. (a -> b) -> a -> b
$ forall p b a t s (bs1 :: [*]).
(Grammar p b (a :- t) -> Grammar p s (a :- t))
-> Coproduct p s bs1 a t -> Coproduct p s (b : bs1) a t
With (\Grammar Position (a :- t) (Maybe a :- t)
just -> forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
list (forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el (forall t. Text -> Grammar Position (Sexp :- t) t
sym Text
"just") forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Grammar Position (a :- t) (Maybe a :- t)
just)
forall a b. (a -> b) -> a -> b
$ forall p s a t. Coproduct p s '[] a t
End
instance (SexpIso a, SexpIso b) => SexpIso (Either a b) where
sexpIso :: SexpGrammar (Either a b)
sexpIso = forall a (bs :: [*]) t p s.
(Generic a, MkPrismList (Rep a), Match (Rep a) bs t,
bs ~ Coll (Rep a) t) =>
Coproduct p s bs a t -> Grammar p s (a :- t)
match
forall a b. (a -> b) -> a -> b
$ forall p b a t s (bs1 :: [*]).
(Grammar p b (a :- t) -> Grammar p s (a :- t))
-> Coproduct p s bs1 a t -> Coproduct p s (b : bs1) a t
With (\Grammar Position (a :- t) (Either a b :- t)
left -> forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
list (forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el (forall t. Text -> Grammar Position (Sexp :- t) t
sym Text
"left") forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Grammar Position (a :- t) (Either a b :- t)
left)
forall a b. (a -> b) -> a -> b
$ forall p b a t s (bs1 :: [*]).
(Grammar p b (a :- t) -> Grammar p s (a :- t))
-> Coproduct p s bs1 a t -> Coproduct p s (b : bs1) a t
With (\Grammar Position (b :- t) (Either a b :- t)
right -> forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
list (forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el (forall t. Text -> Grammar Position (Sexp :- t) t
sym Text
"right") forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Grammar Position (b :- t) (Either a b :- t)
right)
forall a b. (a -> b) -> a -> b
$ forall p s a t. Coproduct p s '[] a t
End
instance (SexpIso a) => SexpIso [a] where
sexpIso :: SexpGrammar [a]
sexpIso = forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
list forall a b. (a -> b) -> a -> b
$ forall a t.
(forall t1. Grammar Position (Sexp :- t1) (a :- t1))
-> Grammar Position (List :- t) (List :- ([a] :- t))
rest forall a. SexpIso a => SexpGrammar a
sexpIso
instance (SexpIso a) => SexpIso (NE.NonEmpty a) where
sexpIso :: SexpGrammar (NonEmpty a)
sexpIso =
forall t t'.
Grammar Position (List :- t) (List :- t')
-> Grammar Position (Sexp :- t) t'
list (forall t t'.
Grammar Position (Sexp :- t) t'
-> Grammar Position (List :- t) (List :- t')
el forall a. SexpIso a => SexpGrammar a
sexpIso forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall a t.
(forall t1. Grammar Position (Sexp :- t1) (a :- t1))
-> Grammar Position (List :- t) (List :- ([a] :- t))
rest forall a. SexpIso a => SexpGrammar a
sexpIso) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall p b a t. Grammar p (b :- (a :- t)) ((a, b) :- t)
pair forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
forall a b p t. (a -> b) -> (b -> a) -> Grammar p (a :- t) (b :- t)
iso (\(a
x,[a]
xs) -> a
x forall a. a -> [a] -> NonEmpty a
NE.:| [a]
xs )
(\(a
x NE.:| [a]
xs) -> (a
x, [a]
xs))