{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
module Symantic.Parser.Grammar.Combinators where
import Data.Bool (Bool(..), not, (||))
import Data.Char (Char)
import Data.Either (Either(..))
import Data.Eq (Eq(..))
import Data.Function ((.), flip, const)
import Data.Int (Int)
import Data.Maybe (Maybe(..))
import Data.Ord (Ord)
import Data.String (String)
import Text.Show (Show(..))
import qualified Data.Functor as Functor
import qualified Data.List as List
import qualified Language.Haskell.TH as TH
import qualified Language.Haskell.TH.Syntax as TH
import qualified Symantic.Univariant.Trans as Sym
import qualified Symantic.Parser.Haskell as H
type TermGrammar = H.Term H.ValueCode
class Applicable repr where
(<$>) :: TermGrammar (a -> b) -> repr a -> repr b
(<$>) TermGrammar (a -> b)
f = (TermGrammar (a -> b) -> repr (a -> b)
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar (a -> b)
f repr (a -> b) -> repr a -> repr b
forall (repr :: * -> *) a b.
Applicable repr =>
repr (a -> b) -> repr a -> repr b
<*>)
(<&>) :: repr a -> TermGrammar (a -> b) -> repr b
(<&>) = (TermGrammar (a -> b) -> repr a -> repr b)
-> repr a -> TermGrammar (a -> b) -> repr b
forall a b c. (a -> b -> c) -> b -> a -> c
flip TermGrammar (a -> b) -> repr a -> repr b
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
(<$>)
(<$) :: TermGrammar a -> repr b -> repr a
(<$) TermGrammar a
x = (TermGrammar a -> repr a
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar a
x repr a -> repr b -> repr a
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> repr b -> repr a
<*)
($>) :: repr a -> TermGrammar b -> repr b
($>) = (TermGrammar b -> repr a -> repr b)
-> repr a -> TermGrammar b -> repr b
forall a b c. (a -> b -> c) -> b -> a -> c
flip TermGrammar b -> repr a -> repr b
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar a -> repr b -> repr a
(<$)
pure :: TermGrammar a -> repr a
default pure ::
Sym.Liftable repr => Applicable (Sym.Output repr) =>
TermGrammar a -> repr a
pure = Output repr a -> repr a
forall (repr :: * -> *) a. Liftable repr => Output repr a -> repr a
Sym.lift (Output repr a -> repr a)
-> (TermGrammar a -> Output repr a) -> TermGrammar a -> repr a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TermGrammar a -> Output repr a
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure
(<*>) :: repr (a -> b) -> repr a -> repr b
default (<*>) ::
Sym.Liftable2 repr => Applicable (Sym.Output repr) =>
repr (a -> b) -> repr a -> repr b
(<*>) = (Output repr (a -> b) -> Output repr a -> Output repr b)
-> repr (a -> b) -> repr a -> repr b
forall (repr :: * -> *) a b c.
Liftable2 repr =>
(Output repr a -> Output repr b -> Output repr c)
-> repr a -> repr b -> repr c
Sym.lift2 Output repr (a -> b) -> Output repr a -> Output repr b
forall (repr :: * -> *) a b.
Applicable repr =>
repr (a -> b) -> repr a -> repr b
(<*>)
liftA2 :: TermGrammar (a -> b -> c) -> repr a -> repr b -> repr c
liftA2 TermGrammar (a -> b -> c)
f repr a
x = repr (b -> c) -> repr b -> repr c
forall (repr :: * -> *) a b.
Applicable repr =>
repr (a -> b) -> repr a -> repr b
(<*>) (TermGrammar (a -> b -> c)
f TermGrammar (a -> b -> c) -> repr a -> repr (b -> c)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> repr a
x)
(<*) :: repr a -> repr b -> repr a
(<*) = TermGrammar (a -> b -> a) -> repr a -> repr b -> repr a
forall (repr :: * -> *) a b c.
Applicable repr =>
TermGrammar (a -> b -> c) -> repr a -> repr b -> repr c
liftA2 TermGrammar (a -> b -> a)
forall (repr :: * -> *) a b. Termable repr => repr (a -> b -> a)
H.const
(*>) :: repr a -> repr b -> repr b
repr a
x *> repr b
y = (Term ValueCode (b -> b)
forall (repr :: * -> *) a. Termable repr => repr (a -> a)
H.id Term ValueCode (b -> b) -> repr a -> repr (b -> b)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar a -> repr b -> repr a
<$ repr a
x) repr (b -> b) -> repr b -> repr b
forall (repr :: * -> *) a b.
Applicable repr =>
repr (a -> b) -> repr a -> repr b
<*> repr b
y
(<**>) :: repr a -> repr (a -> b) -> repr b
(<**>) = TermGrammar (a -> (a -> b) -> b)
-> repr a -> repr (a -> b) -> repr b
forall (repr :: * -> *) a b c.
Applicable repr =>
TermGrammar (a -> b -> c) -> repr a -> repr b -> repr c
liftA2 (Term ValueCode (((a -> b) -> a -> b) -> a -> (a -> b) -> b)
forall (repr :: * -> *) a b c.
Termable repr =>
repr ((a -> b -> c) -> b -> a -> c)
H.flip Term ValueCode (((a -> b) -> a -> b) -> a -> (a -> b) -> b)
-> Term ValueCode ((a -> b) -> a -> b)
-> TermGrammar (a -> (a -> b) -> b)
forall (repr :: * -> *) a b.
Termable repr =>
repr (a -> b) -> repr a -> repr b
H..@ Term ValueCode ((a -> b) -> a -> b)
forall (repr :: * -> *) a b.
Termable repr =>
repr ((a -> b) -> a -> b)
(H.$))
infixl 4 <$>, <&>, <$, $>, <*>, <*, *>, <**>
class Alternable repr where
(<|>) :: repr a -> repr a -> repr a
empty :: repr a
try :: repr a -> repr a
default (<|>) ::
Sym.Liftable2 repr => Alternable (Sym.Output repr) =>
repr a -> repr a -> repr a
default empty ::
Sym.Liftable repr => Alternable (Sym.Output repr) =>
repr a
default try ::
Sym.Liftable1 repr => Alternable (Sym.Output repr) =>
repr a -> repr a
(<|>) = (Output repr a -> Output repr a -> Output repr a)
-> repr a -> repr a -> repr a
forall (repr :: * -> *) a b c.
Liftable2 repr =>
(Output repr a -> Output repr b -> Output repr c)
-> repr a -> repr b -> repr c
Sym.lift2 Output repr a -> Output repr a -> Output repr a
forall (repr :: * -> *) a.
Alternable repr =>
repr a -> repr a -> repr a
(<|>)
empty = Output repr a -> repr a
forall (repr :: * -> *) a. Liftable repr => Output repr a -> repr a
Sym.lift Output repr a
forall (repr :: * -> *) a. Alternable repr => repr a
empty
try = (Output repr a -> Output repr a) -> repr a -> repr a
forall (repr :: * -> *) a b.
Liftable1 repr =>
(Output repr a -> Output repr b) -> repr a -> repr b
Sym.lift1 Output repr a -> Output repr a
forall (repr :: * -> *) a. Alternable repr => repr a -> repr a
try
(<+>) :: Applicable repr => Alternable repr => repr a -> repr b -> repr (Either a b)
repr a
p <+> repr b
q = Term ValueCode (a -> Either a b)
forall (repr :: * -> *) l r.
Termable repr =>
repr (l -> Either l r)
H.left Term ValueCode (a -> Either a b) -> repr a -> repr (Either a b)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> repr a
p repr (Either a b) -> repr (Either a b) -> repr (Either a b)
forall (repr :: * -> *) a.
Alternable repr =>
repr a -> repr a -> repr a
<|> Term ValueCode (b -> Either a b)
forall (repr :: * -> *) r l.
Termable repr =>
repr (r -> Either l r)
H.right Term ValueCode (b -> Either a b) -> repr b -> repr (Either a b)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> repr b
q
infixl 3 <|>, <+>
optionally :: Applicable repr => Alternable repr => repr a -> TermGrammar b -> repr b
optionally :: forall (repr :: * -> *) a b.
(Applicable repr, Alternable repr) =>
repr a -> TermGrammar b -> repr b
optionally repr a
p TermGrammar b
x = repr a
p repr a -> TermGrammar b -> repr b
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> TermGrammar b -> repr b
$> TermGrammar b
x repr b -> repr b -> repr b
forall (repr :: * -> *) a.
Alternable repr =>
repr a -> repr a -> repr a
<|> TermGrammar b -> repr b
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar b
x
optional :: Applicable repr => Alternable repr => repr a -> repr ()
optional :: forall (repr :: * -> *) a.
(Applicable repr, Alternable repr) =>
repr a -> repr ()
optional = (repr a -> TermGrammar () -> repr ())
-> TermGrammar () -> repr a -> repr ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip repr a -> TermGrammar () -> repr ()
forall (repr :: * -> *) a b.
(Applicable repr, Alternable repr) =>
repr a -> TermGrammar b -> repr b
optionally TermGrammar ()
forall (repr :: * -> *). Termable repr => repr ()
H.unit
option :: Applicable repr => Alternable repr => TermGrammar a -> repr a -> repr a
option :: forall (repr :: * -> *) a.
(Applicable repr, Alternable repr) =>
TermGrammar a -> repr a -> repr a
option TermGrammar a
x repr a
p = repr a
p repr a -> repr a -> repr a
forall (repr :: * -> *) a.
Alternable repr =>
repr a -> repr a -> repr a
<|> TermGrammar a -> repr a
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar a
x
choice :: Alternable repr => [repr a] -> repr a
choice :: forall (repr :: * -> *) a. Alternable repr => [repr a] -> repr a
choice = (repr a -> repr a -> repr a) -> repr a -> [repr a] -> repr a
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
List.foldr repr a -> repr a -> repr a
forall (repr :: * -> *) a.
Alternable repr =>
repr a -> repr a -> repr a
(<|>) repr a
forall (repr :: * -> *) a. Alternable repr => repr a
empty
maybeP :: Applicable repr => Alternable repr => repr a -> repr (Maybe a)
maybeP :: forall (repr :: * -> *) a.
(Applicable repr, Alternable repr) =>
repr a -> repr (Maybe a)
maybeP repr a
p = TermGrammar (Maybe a) -> repr (Maybe a) -> repr (Maybe a)
forall (repr :: * -> *) a.
(Applicable repr, Alternable repr) =>
TermGrammar a -> repr a -> repr a
option TermGrammar (Maybe a)
forall (repr :: * -> *) a. Termable repr => repr (Maybe a)
H.nothing (Term ValueCode (a -> Maybe a)
forall (repr :: * -> *) a. Termable repr => repr (a -> Maybe a)
H.just Term ValueCode (a -> Maybe a) -> repr a -> repr (Maybe a)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> repr a
p)
manyTill :: Applicable repr => Alternable repr => repr a -> repr b -> repr [a]
manyTill :: forall (repr :: * -> *) a b.
(Applicable repr, Alternable repr) =>
repr a -> repr b -> repr [a]
manyTill repr a
p repr b
end = let go :: repr [a]
go = repr b
end repr b -> TermGrammar [a] -> repr [a]
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> TermGrammar b -> repr b
$> TermGrammar [a]
forall (repr :: * -> *) a. Termable repr => repr [a]
H.nil repr [a] -> repr [a] -> repr [a]
forall (repr :: * -> *) a.
Alternable repr =>
repr a -> repr a -> repr a
<|> repr a
p repr a -> repr [a] -> repr [a]
forall (repr :: * -> *) a.
Applicable repr =>
repr a -> repr [a] -> repr [a]
<:> repr [a]
go in repr [a]
go
class Selectable repr where
branch :: repr (Either a b) -> repr (a -> c) -> repr (b -> c) -> repr c
default branch ::
Sym.Liftable3 repr => Selectable (Sym.Output repr) =>
repr (Either a b) -> repr (a -> c) -> repr (b -> c) -> repr c
branch = (Output repr (Either a b)
-> Output repr (a -> c) -> Output repr (b -> c) -> Output repr c)
-> repr (Either a b) -> repr (a -> c) -> repr (b -> c) -> repr c
forall (repr :: * -> *) a b c d.
Liftable3 repr =>
(Output repr a -> Output repr b -> Output repr c -> Output repr d)
-> repr a -> repr b -> repr c -> repr d
Sym.lift3 Output repr (Either a b)
-> Output repr (a -> c) -> Output repr (b -> c) -> Output repr c
forall (repr :: * -> *) a b c.
Selectable repr =>
repr (Either a b) -> repr (a -> c) -> repr (b -> c) -> repr c
branch
class Matchable repr where
conditional ::
Eq a => repr a -> [TermGrammar (a -> Bool)] -> [repr b] -> repr b -> repr b
default conditional ::
Sym.Unliftable repr => Sym.Liftable1 repr => Matchable (Sym.Output repr) =>
Eq a => repr a -> [TermGrammar (a -> Bool)] -> [repr b] -> repr b -> repr b
conditional repr a
a [TermGrammar (a -> Bool)]
ps [repr b]
bs = (Output repr b -> Output repr b) -> repr b -> repr b
forall (repr :: * -> *) a b.
Liftable1 repr =>
(Output repr a -> Output repr b) -> repr a -> repr b
Sym.lift1 (Output repr a
-> [TermGrammar (a -> Bool)]
-> [Output repr b]
-> Output repr b
-> Output repr b
forall (repr :: * -> *) a b.
(Matchable repr, Eq a) =>
repr a -> [TermGrammar (a -> Bool)] -> [repr b] -> repr b -> repr b
conditional (repr a -> Output repr a
forall (from :: * -> *) (to :: * -> *) a.
Trans from to =>
from a -> to a
Sym.trans repr a
a) [TermGrammar (a -> Bool)]
ps (repr b -> Output repr b
forall (from :: * -> *) (to :: * -> *) a.
Trans from to =>
from a -> to a
Sym.trans (repr b -> Output repr b) -> [repr b] -> [Output repr b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Functor.<$> [repr b]
bs))
match :: Eq a => repr a -> [TermGrammar a] -> (TermGrammar a -> repr b) -> repr b -> repr b
match repr a
a [TermGrammar a]
as TermGrammar a -> repr b
a2b = repr a -> [TermGrammar (a -> Bool)] -> [repr b] -> repr b -> repr b
forall (repr :: * -> *) a b.
(Matchable repr, Eq a) =>
repr a -> [TermGrammar (a -> Bool)] -> [repr b] -> repr b -> repr b
conditional repr a
a ((Term ValueCode (a -> a -> Bool)
forall (repr :: * -> *) a.
(Termable repr, Eq a) =>
repr (a -> a -> Bool)
H.eq Term ValueCode (a -> a -> Bool)
-> TermGrammar a -> TermGrammar (a -> Bool)
forall (repr :: * -> *) a b.
Termable repr =>
repr (a -> b) -> repr a -> repr b
H..@) (TermGrammar a -> TermGrammar (a -> Bool))
-> [TermGrammar a] -> [TermGrammar (a -> Bool)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Functor.<$> [TermGrammar a]
as) (TermGrammar a -> repr b
a2b (TermGrammar a -> repr b) -> [TermGrammar a] -> [repr b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Functor.<$> [TermGrammar a]
as)
class Foldable repr where
chainPre :: repr (a -> a) -> repr a -> repr a
chainPost :: repr a -> repr (a -> a) -> repr a
default chainPre ::
Applicable repr =>
Alternable repr =>
repr (a -> a) -> repr a -> repr a
default chainPost ::
Applicable repr =>
Alternable repr =>
repr a -> repr (a -> a) -> repr a
chainPre repr (a -> a)
op repr a
p = repr (a -> a)
go repr (a -> a) -> repr a -> repr a
forall (repr :: * -> *) a b.
Applicable repr =>
repr (a -> b) -> repr a -> repr b
<*> repr a
p
where go :: repr (a -> a)
go = Term ValueCode ((a -> a) -> (a -> a) -> a -> a)
forall (repr :: * -> *) b c a.
Termable repr =>
repr ((b -> c) -> (a -> b) -> a -> c)
(H..) Term ValueCode ((a -> a) -> (a -> a) -> a -> a)
-> repr (a -> a) -> repr ((a -> a) -> a -> a)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> repr (a -> a)
op repr ((a -> a) -> a -> a) -> repr (a -> a) -> repr (a -> a)
forall (repr :: * -> *) a b.
Applicable repr =>
repr (a -> b) -> repr a -> repr b
<*> repr (a -> a)
go repr (a -> a) -> repr (a -> a) -> repr (a -> a)
forall (repr :: * -> *) a.
Alternable repr =>
repr a -> repr a -> repr a
<|> TermGrammar (a -> a) -> repr (a -> a)
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar (a -> a)
forall (repr :: * -> *) a. Termable repr => repr (a -> a)
H.id
chainPost repr a
p repr (a -> a)
op = repr a
p repr a -> repr (a -> a) -> repr a
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> repr (a -> b) -> repr b
<**> repr (a -> a)
go
where go :: repr (a -> a)
go = Term ValueCode ((a -> a) -> (a -> a) -> a -> a)
forall (repr :: * -> *) b c a.
Termable repr =>
repr ((b -> c) -> (a -> b) -> a -> c)
(H..) Term ValueCode ((a -> a) -> (a -> a) -> a -> a)
-> repr (a -> a) -> repr ((a -> a) -> a -> a)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> repr (a -> a)
op repr ((a -> a) -> a -> a) -> repr (a -> a) -> repr (a -> a)
forall (repr :: * -> *) a b.
Applicable repr =>
repr (a -> b) -> repr a -> repr b
<*> repr (a -> a)
go repr (a -> a) -> repr (a -> a) -> repr (a -> a)
forall (repr :: * -> *) a.
Alternable repr =>
repr a -> repr a -> repr a
<|> TermGrammar (a -> a) -> repr (a -> a)
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar (a -> a)
forall (repr :: * -> *) a. Termable repr => repr (a -> a)
H.id
class Satisfiable tok repr where
satisfy :: [ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
default satisfy ::
Sym.Liftable repr => Satisfiable tok (Sym.Output repr) =>
[ErrorItem tok] ->
TermGrammar (tok -> Bool) -> repr tok
satisfy [ErrorItem tok]
es = Output repr tok -> repr tok
forall (repr :: * -> *) a. Liftable repr => Output repr a -> repr a
Sym.lift (Output repr tok -> repr tok)
-> (TermGrammar (tok -> Bool) -> Output repr tok)
-> TermGrammar (tok -> Bool)
-> repr tok
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ErrorItem tok] -> TermGrammar (tok -> Bool) -> Output repr tok
forall tok (repr :: * -> *).
Satisfiable tok repr =>
[ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
satisfy [ErrorItem tok]
es
item :: repr tok
item = [ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
forall tok (repr :: * -> *).
Satisfiable tok repr =>
[ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
satisfy [] (Term ValueCode (Bool -> tok -> Bool)
forall (repr :: * -> *) a b. Termable repr => repr (a -> b -> a)
H.const Term ValueCode (Bool -> tok -> Bool)
-> Term ValueCode Bool -> TermGrammar (tok -> Bool)
forall (repr :: * -> *) a b.
Termable repr =>
repr (a -> b) -> repr a -> repr b
H..@ Bool -> Term ValueCode Bool
forall (repr :: * -> *). Termable repr => Bool -> repr Bool
H.bool Bool
True)
data ErrorItem tok
= ErrorItemToken tok
| ErrorItemLabel String
| ErrorItemHorizon Int
| ErrorItemEnd
deriving instance Eq tok => Eq (ErrorItem tok)
deriving instance Ord tok => Ord (ErrorItem tok)
deriving instance Show tok => Show (ErrorItem tok)
deriving instance TH.Lift tok => TH.Lift (ErrorItem tok)
class Lookable repr where
look :: repr a -> repr a
negLook :: repr a -> repr ()
default look :: Sym.Liftable1 repr => Lookable (Sym.Output repr) => repr a -> repr a
default negLook :: Sym.Liftable1 repr => Lookable (Sym.Output repr) => repr a -> repr ()
look = (Output repr a -> Output repr a) -> repr a -> repr a
forall (repr :: * -> *) a b.
Liftable1 repr =>
(Output repr a -> Output repr b) -> repr a -> repr b
Sym.lift1 Output repr a -> Output repr a
forall (repr :: * -> *) a. Lookable repr => repr a -> repr a
look
negLook = (Output repr a -> Output repr ()) -> repr a -> repr ()
forall (repr :: * -> *) a b.
Liftable1 repr =>
(Output repr a -> Output repr b) -> repr a -> repr b
Sym.lift1 Output repr a -> Output repr ()
forall (repr :: * -> *) a. Lookable repr => repr a -> repr ()
negLook
eof :: repr ()
eof = Output repr () -> repr ()
forall (repr :: * -> *) a. Liftable repr => Output repr a -> repr a
Sym.lift Output repr ()
forall (repr :: * -> *). Lookable repr => repr ()
eof
default eof :: Sym.Liftable repr => Lookable (Sym.Output repr) => repr ()
{-# INLINE (<:>) #-}
infixl 4 <:>
(<:>) :: Applicable repr => repr a -> repr [a] -> repr [a]
<:> :: forall (repr :: * -> *) a.
Applicable repr =>
repr a -> repr [a] -> repr [a]
(<:>) = TermGrammar (a -> [a] -> [a]) -> repr a -> repr [a] -> repr [a]
forall (repr :: * -> *) a b c.
Applicable repr =>
TermGrammar (a -> b -> c) -> repr a -> repr b -> repr c
liftA2 TermGrammar (a -> [a] -> [a])
forall (repr :: * -> *) a. Termable repr => repr (a -> [a] -> [a])
H.cons
sequence :: Applicable repr => [repr a] -> repr [a]
sequence :: forall (repr :: * -> *) a. Applicable repr => [repr a] -> repr [a]
sequence = (repr a -> repr [a] -> repr [a])
-> repr [a] -> [repr a] -> repr [a]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
List.foldr repr a -> repr [a] -> repr [a]
forall (repr :: * -> *) a.
Applicable repr =>
repr a -> repr [a] -> repr [a]
(<:>) (TermGrammar [a] -> repr [a]
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar [a]
forall (repr :: * -> *) a. Termable repr => repr [a]
H.nil)
traverse :: Applicable repr => (a -> repr b) -> [a] -> repr [b]
traverse :: forall (repr :: * -> *) a b.
Applicable repr =>
(a -> repr b) -> [a] -> repr [b]
traverse a -> repr b
f = [repr b] -> repr [b]
forall (repr :: * -> *) a. Applicable repr => [repr a] -> repr [a]
sequence ([repr b] -> repr [b]) -> ([a] -> [repr b]) -> [a] -> repr [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> repr b) -> [a] -> [repr b]
forall a b. (a -> b) -> [a] -> [b]
List.map a -> repr b
f
repeat :: Applicable repr => Int -> repr a -> repr [a]
repeat :: forall (repr :: * -> *) a.
Applicable repr =>
Int -> repr a -> repr [a]
repeat Int
n repr a
p = (Int -> repr a) -> [Int] -> repr [a]
forall (repr :: * -> *) a b.
Applicable repr =>
(a -> repr b) -> [a] -> repr [b]
traverse (repr a -> Int -> repr a
forall a b. a -> b -> a
const repr a
p) [Int
1..Int
n]
between :: Applicable repr => repr o -> repr c -> repr a -> repr a
between :: forall (repr :: * -> *) o c a.
Applicable repr =>
repr o -> repr c -> repr a -> repr a
between repr o
open repr c
close repr a
p = repr o
open repr o -> repr a -> repr a
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> repr b -> repr b
*> repr a
p repr a -> repr c -> repr a
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> repr b -> repr a
<* repr c
close
string ::
Applicable repr => Alternable repr =>
Satisfiable Char repr =>
[Char] -> repr [Char]
string :: forall (repr :: * -> *).
(Applicable repr, Alternable repr, Satisfiable Char repr) =>
String -> repr String
string = repr String -> repr String
forall (repr :: * -> *) a. Alternable repr => repr a -> repr a
try (repr String -> repr String)
-> (String -> repr String) -> String -> repr String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> repr Char) -> String -> repr String
forall (repr :: * -> *) a b.
Applicable repr =>
(a -> repr b) -> [a] -> repr [b]
traverse Char -> repr Char
forall (repr :: * -> *).
(Applicable repr, Satisfiable Char repr) =>
Char -> repr Char
char
oneOf ::
TH.Lift tok => Eq tok =>
Satisfiable tok repr =>
[tok] -> repr tok
oneOf :: forall tok (repr :: * -> *).
(Lift tok, Eq tok, Satisfiable tok repr) =>
[tok] -> repr tok
oneOf [tok]
ts = [ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
forall tok (repr :: * -> *).
Satisfiable tok repr =>
[ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
satisfy [String -> ErrorItem tok
forall tok. String -> ErrorItem tok
ErrorItemLabel String
"oneOf"]
(ValueCode (tok -> Bool) -> TermGrammar (tok -> Bool)
forall (from :: * -> *) (to :: * -> *) a.
Trans from to =>
from a -> to a
Sym.trans ValueCode :: forall a. a -> CodeQ a -> ValueCode a
H.ValueCode
{ value :: tok -> Bool
value = (tok -> [tok] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`List.elem` [tok]
ts)
, code :: CodeQ (tok -> Bool)
code = [||\t -> $$(ofChars ts [||t||])||] })
noneOf ::
TH.Lift tok => Eq tok =>
Satisfiable tok repr =>
[tok] -> repr tok
noneOf :: forall tok (repr :: * -> *).
(Lift tok, Eq tok, Satisfiable tok repr) =>
[tok] -> repr tok
noneOf [tok]
cs = [ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
forall tok (repr :: * -> *).
Satisfiable tok repr =>
[ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
satisfy (tok -> ErrorItem tok
forall tok. tok -> ErrorItem tok
ErrorItemToken (tok -> ErrorItem tok) -> [tok] -> [ErrorItem tok]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Functor.<$> [tok]
cs) (ValueCode (tok -> Bool) -> TermGrammar (tok -> Bool)
forall (from :: * -> *) (to :: * -> *) a.
Trans from to =>
from a -> to a
Sym.trans ValueCode :: forall a. a -> CodeQ a -> ValueCode a
H.ValueCode
{ value :: tok -> Bool
value = Bool -> Bool
not (Bool -> Bool) -> (tok -> Bool) -> tok -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (tok -> [tok] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`List.elem` [tok]
cs)
, code :: CodeQ (tok -> Bool)
code = [||\c -> not $$(ofChars cs [||c||])||]
})
ofChars ::
TH.Lift tok => Eq tok =>
[tok] ->
TH.CodeQ tok ->
TH.CodeQ Bool
ofChars :: forall tok. (Lift tok, Eq tok) => [tok] -> CodeQ tok -> CodeQ Bool
ofChars = (tok -> (Code Q tok -> CodeQ Bool) -> Code Q tok -> CodeQ Bool)
-> (Code Q tok -> CodeQ Bool) -> [tok] -> Code Q tok -> CodeQ Bool
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
List.foldr (\tok
alt Code Q tok -> CodeQ Bool
acc ->
\Code Q tok
inp -> [|| alt == $$inp || $$(acc inp) ||])
(CodeQ Bool -> Code Q tok -> CodeQ Bool
forall a b. a -> b -> a
const [||False||])
more :: Applicable repr => Satisfiable Char repr => Lookable repr => repr ()
more :: forall (repr :: * -> *).
(Applicable repr, Satisfiable Char repr, Lookable repr) =>
repr ()
more = repr () -> repr ()
forall (repr :: * -> *) a. Lookable repr => repr a -> repr a
look (repr Char -> repr ()
forall (repr :: * -> *) a. Applicable repr => repr a -> repr ()
void (forall tok (repr :: * -> *). Satisfiable tok repr => repr tok
item @Char))
char ::
Applicable repr => Satisfiable Char repr =>
Char -> repr Char
char :: forall (repr :: * -> *).
(Applicable repr, Satisfiable Char repr) =>
Char -> repr Char
char Char
c = [ErrorItem Char] -> TermGrammar (Char -> Bool) -> repr Char
forall tok (repr :: * -> *).
Satisfiable tok repr =>
[ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
satisfy [Char -> ErrorItem Char
forall tok. tok -> ErrorItem tok
ErrorItemToken Char
c] (Term ValueCode (Char -> Char -> Bool)
forall (repr :: * -> *) a.
(Termable repr, Eq a) =>
repr (a -> a -> Bool)
H.eq Term ValueCode (Char -> Char -> Bool)
-> Term ValueCode Char -> TermGrammar (Char -> Bool)
forall (repr :: * -> *) a b.
Termable repr =>
repr (a -> b) -> repr a -> repr b
H..@ Char -> Term ValueCode Char
forall (repr :: * -> *) tok.
(Termable repr, Lift tok, Show tok) =>
tok -> repr tok
H.char Char
c) repr Char -> Term ValueCode Char -> repr Char
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> TermGrammar b -> repr b
$> Char -> Term ValueCode Char
forall (repr :: * -> *) tok.
(Termable repr, Lift tok, Show tok) =>
tok -> repr tok
H.char Char
c
anyChar :: Satisfiable Char repr => repr Char
anyChar :: forall (repr :: * -> *). Satisfiable Char repr => repr Char
anyChar = [ErrorItem Char] -> TermGrammar (Char -> Bool) -> repr Char
forall tok (repr :: * -> *).
Satisfiable tok repr =>
[ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
satisfy [] (Term ValueCode (Bool -> Char -> Bool)
forall (repr :: * -> *) a b. Termable repr => repr (a -> b -> a)
H.const Term ValueCode (Bool -> Char -> Bool)
-> Term ValueCode Bool -> TermGrammar (Char -> Bool)
forall (repr :: * -> *) a b.
Termable repr =>
repr (a -> b) -> repr a -> repr b
H..@ Bool -> Term ValueCode Bool
forall (repr :: * -> *). Termable repr => Bool -> repr Bool
H.bool Bool
True)
token ::
TH.Lift tok => Show tok => Eq tok =>
Applicable repr => Satisfiable tok repr =>
tok -> repr tok
token :: forall tok (repr :: * -> *).
(Lift tok, Show tok, Eq tok, Applicable repr,
Satisfiable tok repr) =>
tok -> repr tok
token tok
tok = [ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
forall tok (repr :: * -> *).
Satisfiable tok repr =>
[ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
satisfy [tok -> ErrorItem tok
forall tok. tok -> ErrorItem tok
ErrorItemToken tok
tok] (Term ValueCode (tok -> tok -> Bool)
forall (repr :: * -> *) a.
(Termable repr, Eq a) =>
repr (a -> a -> Bool)
H.eq Term ValueCode (tok -> tok -> Bool)
-> Term ValueCode tok -> TermGrammar (tok -> Bool)
forall (repr :: * -> *) a b.
Termable repr =>
repr (a -> b) -> repr a -> repr b
H..@ tok -> Term ValueCode tok
forall (repr :: * -> *) tok.
(Termable repr, Lift tok, Show tok) =>
tok -> repr tok
H.char tok
tok) repr tok -> Term ValueCode tok -> repr tok
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> TermGrammar b -> repr b
$> tok -> Term ValueCode tok
forall (repr :: * -> *) tok.
(Termable repr, Lift tok, Show tok) =>
tok -> repr tok
H.char tok
tok
tokens ::
TH.Lift tok => Eq tok => Show tok =>
Applicable repr => Alternable repr =>
Satisfiable tok repr => [tok] -> repr [tok]
tokens :: forall tok (repr :: * -> *).
(Lift tok, Eq tok, Show tok, Applicable repr, Alternable repr,
Satisfiable tok repr) =>
[tok] -> repr [tok]
tokens = repr [tok] -> repr [tok]
forall (repr :: * -> *) a. Alternable repr => repr a -> repr a
try (repr [tok] -> repr [tok])
-> ([tok] -> repr [tok]) -> [tok] -> repr [tok]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (tok -> repr tok) -> [tok] -> repr [tok]
forall (repr :: * -> *) a b.
Applicable repr =>
(a -> repr b) -> [a] -> repr [b]
traverse tok -> repr tok
forall tok (repr :: * -> *).
(Lift tok, Show tok, Eq tok, Applicable repr,
Satisfiable tok repr) =>
tok -> repr tok
token
void :: Applicable repr => repr a -> repr ()
void :: forall (repr :: * -> *) a. Applicable repr => repr a -> repr ()
void repr a
p = repr a
p repr a -> repr () -> repr ()
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> repr b -> repr b
*> repr ()
forall (repr :: * -> *). Applicable repr => repr ()
unit
unit :: Applicable repr => repr ()
unit :: forall (repr :: * -> *). Applicable repr => repr ()
unit = TermGrammar () -> repr ()
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar ()
forall (repr :: * -> *). Termable repr => repr ()
H.unit
pfoldr ::
Applicable repr => Foldable repr =>
TermGrammar (a -> b -> b) -> TermGrammar b -> repr a -> repr b
pfoldr :: forall (repr :: * -> *) a b.
(Applicable repr, Foldable repr) =>
TermGrammar (a -> b -> b) -> TermGrammar b -> repr a -> repr b
pfoldr TermGrammar (a -> b -> b)
f TermGrammar b
k repr a
p = repr (b -> b) -> repr b -> repr b
forall (repr :: * -> *) a.
Foldable repr =>
repr (a -> a) -> repr a -> repr a
chainPre (TermGrammar (a -> b -> b)
f TermGrammar (a -> b -> b) -> repr a -> repr (b -> b)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> repr a
p) (TermGrammar b -> repr b
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar b
k)
pfoldr1 ::
Applicable repr => Foldable repr =>
TermGrammar (a -> b -> b) -> TermGrammar b -> repr a -> repr b
pfoldr1 :: forall (repr :: * -> *) a b.
(Applicable repr, Foldable repr) =>
TermGrammar (a -> b -> b) -> TermGrammar b -> repr a -> repr b
pfoldr1 TermGrammar (a -> b -> b)
f TermGrammar b
k repr a
p = TermGrammar (a -> b -> b)
f TermGrammar (a -> b -> b) -> repr a -> repr (b -> b)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> repr a
p repr (b -> b) -> repr b -> repr b
forall (repr :: * -> *) a b.
Applicable repr =>
repr (a -> b) -> repr a -> repr b
<*> TermGrammar (a -> b -> b) -> TermGrammar b -> repr a -> repr b
forall (repr :: * -> *) a b.
(Applicable repr, Foldable repr) =>
TermGrammar (a -> b -> b) -> TermGrammar b -> repr a -> repr b
pfoldr TermGrammar (a -> b -> b)
f TermGrammar b
k repr a
p
pfoldl ::
Applicable repr => Foldable repr =>
TermGrammar (b -> a -> b) -> TermGrammar b -> repr a -> repr b
pfoldl :: forall (repr :: * -> *) b a.
(Applicable repr, Foldable repr) =>
TermGrammar (b -> a -> b) -> TermGrammar b -> repr a -> repr b
pfoldl TermGrammar (b -> a -> b)
f TermGrammar b
k repr a
p = repr b -> repr (b -> b) -> repr b
forall (repr :: * -> *) a.
Foldable repr =>
repr a -> repr (a -> a) -> repr a
chainPost (TermGrammar b -> repr b
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar b
k) ((Term ValueCode ((b -> a -> b) -> a -> b -> b)
forall (repr :: * -> *) a b c.
Termable repr =>
repr ((a -> b -> c) -> b -> a -> c)
H.flip Term ValueCode ((b -> a -> b) -> a -> b -> b)
-> repr (b -> a -> b) -> repr (a -> b -> b)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> TermGrammar (b -> a -> b) -> repr (b -> a -> b)
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar (b -> a -> b)
f) repr (a -> b -> b) -> repr a -> repr (b -> b)
forall (repr :: * -> *) a b.
Applicable repr =>
repr (a -> b) -> repr a -> repr b
<*> repr a
p)
pfoldl1 ::
Applicable repr => Foldable repr =>
TermGrammar (b -> a -> b) -> TermGrammar b -> repr a -> repr b
pfoldl1 :: forall (repr :: * -> *) b a.
(Applicable repr, Foldable repr) =>
TermGrammar (b -> a -> b) -> TermGrammar b -> repr a -> repr b
pfoldl1 TermGrammar (b -> a -> b)
f TermGrammar b
k repr a
p = repr b -> repr (b -> b) -> repr b
forall (repr :: * -> *) a.
Foldable repr =>
repr a -> repr (a -> a) -> repr a
chainPost (TermGrammar (b -> a -> b)
f TermGrammar (b -> a -> b) -> repr b -> repr (a -> b)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> TermGrammar b -> repr b
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar b
k repr (a -> b) -> repr a -> repr b
forall (repr :: * -> *) a b.
Applicable repr =>
repr (a -> b) -> repr a -> repr b
<*> repr a
p) ((Term ValueCode ((b -> a -> b) -> a -> b -> b)
forall (repr :: * -> *) a b c.
Termable repr =>
repr ((a -> b -> c) -> b -> a -> c)
H.flip Term ValueCode ((b -> a -> b) -> a -> b -> b)
-> repr (b -> a -> b) -> repr (a -> b -> b)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> TermGrammar (b -> a -> b) -> repr (b -> a -> b)
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure TermGrammar (b -> a -> b)
f) repr (a -> b -> b) -> repr a -> repr (b -> b)
forall (repr :: * -> *) a b.
Applicable repr =>
repr (a -> b) -> repr a -> repr b
<*> repr a
p)
chainl1' ::
Applicable repr => Foldable repr =>
TermGrammar (a -> b) -> repr a -> repr (b -> a -> b) -> repr b
chainl1' :: forall (repr :: * -> *) a b.
(Applicable repr, Foldable repr) =>
TermGrammar (a -> b) -> repr a -> repr (b -> a -> b) -> repr b
chainl1' TermGrammar (a -> b)
f repr a
p repr (b -> a -> b)
op = repr b -> repr (b -> b) -> repr b
forall (repr :: * -> *) a.
Foldable repr =>
repr a -> repr (a -> a) -> repr a
chainPost (TermGrammar (a -> b)
f TermGrammar (a -> b) -> repr a -> repr b
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> repr a
p) (Term ValueCode ((b -> a -> b) -> a -> b -> b)
forall (repr :: * -> *) a b c.
Termable repr =>
repr ((a -> b -> c) -> b -> a -> c)
H.flip Term ValueCode ((b -> a -> b) -> a -> b -> b)
-> repr (b -> a -> b) -> repr (a -> b -> b)
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> repr (b -> a -> b)
op repr (a -> b -> b) -> repr a -> repr (b -> b)
forall (repr :: * -> *) a b.
Applicable repr =>
repr (a -> b) -> repr a -> repr b
<*> repr a
p)
chainl1 ::
Applicable repr => Foldable repr =>
repr a -> repr (a -> a -> a) -> repr a
chainl1 :: forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
repr a -> repr (a -> a -> a) -> repr a
chainl1 = TermGrammar (a -> a) -> repr a -> repr (a -> a -> a) -> repr a
forall (repr :: * -> *) a b.
(Applicable repr, Foldable repr) =>
TermGrammar (a -> b) -> repr a -> repr (b -> a -> b) -> repr b
chainl1' TermGrammar (a -> a)
forall (repr :: * -> *) a. Termable repr => repr (a -> a)
H.id
chainl ::
Applicable repr => Alternable repr => Foldable repr =>
repr a -> repr (a -> a -> a) -> TermGrammar a -> repr a
chainl :: forall (repr :: * -> *) a.
(Applicable repr, Alternable repr, Foldable repr) =>
repr a -> repr (a -> a -> a) -> TermGrammar a -> repr a
chainl repr a
p repr (a -> a -> a)
op TermGrammar a
x = TermGrammar a -> repr a -> repr a
forall (repr :: * -> *) a.
(Applicable repr, Alternable repr) =>
TermGrammar a -> repr a -> repr a
option TermGrammar a
x (repr a -> repr (a -> a -> a) -> repr a
forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
repr a -> repr (a -> a -> a) -> repr a
chainl1 repr a
p repr (a -> a -> a)
op)
many ::
Applicable repr => Foldable repr =>
repr a -> repr [a]
many :: forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
repr a -> repr [a]
many = TermGrammar (a -> [a] -> [a])
-> TermGrammar [a] -> repr a -> repr [a]
forall (repr :: * -> *) a b.
(Applicable repr, Foldable repr) =>
TermGrammar (a -> b -> b) -> TermGrammar b -> repr a -> repr b
pfoldr TermGrammar (a -> [a] -> [a])
forall (repr :: * -> *) a. Termable repr => repr (a -> [a] -> [a])
H.cons TermGrammar [a]
forall (repr :: * -> *) a. Termable repr => repr [a]
H.nil
manyN ::
Applicable repr => Foldable repr =>
Int -> repr a -> repr [a]
manyN :: forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
Int -> repr a -> repr [a]
manyN Int
n repr a
p = (Int -> repr [a] -> repr [a]) -> repr [a] -> [Int] -> repr [a]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
List.foldr ((repr [a] -> repr [a]) -> Int -> repr [a] -> repr [a]
forall a b. a -> b -> a
const (repr a
p repr a -> repr [a] -> repr [a]
forall (repr :: * -> *) a.
Applicable repr =>
repr a -> repr [a] -> repr [a]
<:>)) (repr a -> repr [a]
forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
repr a -> repr [a]
many repr a
p) [Int
1..Int
n]
some ::
Applicable repr => Foldable repr =>
repr a -> repr [a]
some :: forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
repr a -> repr [a]
some = Int -> repr a -> repr [a]
forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
Int -> repr a -> repr [a]
manyN Int
1
skipMany ::
Applicable repr => Foldable repr =>
repr a -> repr ()
skipMany :: forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
repr a -> repr ()
skipMany = repr () -> repr ()
forall (repr :: * -> *) a. Applicable repr => repr a -> repr ()
void (repr () -> repr ()) -> (repr a -> repr ()) -> repr a -> repr ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TermGrammar (() -> a -> ()) -> TermGrammar () -> repr a -> repr ()
forall (repr :: * -> *) b a.
(Applicable repr, Foldable repr) =>
TermGrammar (b -> a -> b) -> TermGrammar b -> repr a -> repr b
pfoldl TermGrammar (() -> a -> ())
forall (repr :: * -> *) a b. Termable repr => repr (a -> b -> a)
H.const TermGrammar ()
forall (repr :: * -> *). Termable repr => repr ()
H.unit
skipManyN ::
Applicable repr => Foldable repr =>
Int -> repr a -> repr ()
skipManyN :: forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
Int -> repr a -> repr ()
skipManyN Int
n repr a
p = (Int -> repr () -> repr ()) -> repr () -> [Int] -> repr ()
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
List.foldr ((repr () -> repr ()) -> Int -> repr () -> repr ()
forall a b. a -> b -> a
const (repr a
p repr a -> repr () -> repr ()
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> repr b -> repr b
*>)) (repr a -> repr ()
forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
repr a -> repr ()
skipMany repr a
p) [Int
1..Int
n]
skipSome ::
Applicable repr => Foldable repr =>
repr a -> repr ()
skipSome :: forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
repr a -> repr ()
skipSome = Int -> repr a -> repr ()
forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
Int -> repr a -> repr ()
skipManyN Int
1
sepBy ::
Applicable repr => Alternable repr => Foldable repr =>
repr a -> repr b -> repr [a]
sepBy :: forall (repr :: * -> *) a b.
(Applicable repr, Alternable repr, Foldable repr) =>
repr a -> repr b -> repr [a]
sepBy repr a
p repr b
sep = TermGrammar [a] -> repr [a] -> repr [a]
forall (repr :: * -> *) a.
(Applicable repr, Alternable repr) =>
TermGrammar a -> repr a -> repr a
option TermGrammar [a]
forall (repr :: * -> *) a. Termable repr => repr [a]
H.nil (repr a -> repr b -> repr [a]
forall (repr :: * -> *) a b.
(Applicable repr, Alternable repr, Foldable repr) =>
repr a -> repr b -> repr [a]
sepBy1 repr a
p repr b
sep)
sepBy1 ::
Applicable repr => Alternable repr => Foldable repr =>
repr a -> repr b -> repr [a]
sepBy1 :: forall (repr :: * -> *) a b.
(Applicable repr, Alternable repr, Foldable repr) =>
repr a -> repr b -> repr [a]
sepBy1 repr a
p repr b
sep = repr a
p repr a -> repr [a] -> repr [a]
forall (repr :: * -> *) a.
Applicable repr =>
repr a -> repr [a] -> repr [a]
<:> repr a -> repr [a]
forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
repr a -> repr [a]
many (repr b
sep repr b -> repr a -> repr a
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> repr b -> repr b
*> repr a
p)
endBy ::
Applicable repr => Alternable repr => Foldable repr =>
repr a -> repr b -> repr [a]
endBy :: forall (repr :: * -> *) a b.
(Applicable repr, Alternable repr, Foldable repr) =>
repr a -> repr b -> repr [a]
endBy repr a
p repr b
sep = repr a -> repr [a]
forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
repr a -> repr [a]
many (repr a
p repr a -> repr b -> repr a
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> repr b -> repr a
<* repr b
sep)
endBy1 ::
Applicable repr => Alternable repr => Foldable repr =>
repr a -> repr b -> repr [a]
endBy1 :: forall (repr :: * -> *) a b.
(Applicable repr, Alternable repr, Foldable repr) =>
repr a -> repr b -> repr [a]
endBy1 repr a
p repr b
sep = repr a -> repr [a]
forall (repr :: * -> *) a.
(Applicable repr, Foldable repr) =>
repr a -> repr [a]
some (repr a
p repr a -> repr b -> repr a
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> repr b -> repr a
<* repr b
sep)
sepEndBy ::
Applicable repr => Alternable repr => Foldable repr =>
repr a -> repr b -> repr [a]
sepEndBy :: forall (repr :: * -> *) a b.
(Applicable repr, Alternable repr, Foldable repr) =>
repr a -> repr b -> repr [a]
sepEndBy repr a
p repr b
sep = TermGrammar [a] -> repr [a] -> repr [a]
forall (repr :: * -> *) a.
(Applicable repr, Alternable repr) =>
TermGrammar a -> repr a -> repr a
option TermGrammar [a]
forall (repr :: * -> *) a. Termable repr => repr [a]
H.nil (repr a -> repr b -> repr [a]
forall (repr :: * -> *) a b.
(Applicable repr, Alternable repr, Foldable repr) =>
repr a -> repr b -> repr [a]
sepEndBy1 repr a
p repr b
sep)
sepEndBy1 ::
Applicable repr => Alternable repr => Foldable repr =>
repr a -> repr b -> repr [a]
sepEndBy1 :: forall (repr :: * -> *) a b.
(Applicable repr, Alternable repr, Foldable repr) =>
repr a -> repr b -> repr [a]
sepEndBy1 repr a
p repr b
sep =
let seb1 :: repr [a]
seb1 = repr a
p repr a -> repr (a -> [a]) -> repr [a]
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> repr (a -> b) -> repr b
<**> (repr b
sep repr b -> repr (a -> [a]) -> repr (a -> [a])
forall (repr :: * -> *) a b.
Applicable repr =>
repr a -> repr b -> repr b
*> (Term ValueCode ((a -> [a] -> [a]) -> [a] -> a -> [a])
forall (repr :: * -> *) a b c.
Termable repr =>
repr ((a -> b -> c) -> b -> a -> c)
H.flip Term ValueCode ((a -> [a] -> [a]) -> [a] -> a -> [a])
-> Term ValueCode (a -> [a] -> [a])
-> Term ValueCode ([a] -> a -> [a])
forall (repr :: * -> *) a b.
Termable repr =>
repr (a -> b) -> repr a -> repr b
H..@ Term ValueCode (a -> [a] -> [a])
forall (repr :: * -> *) a. Termable repr => repr (a -> [a] -> [a])
H.cons Term ValueCode ([a] -> a -> [a]) -> repr [a] -> repr (a -> [a])
forall (repr :: * -> *) a b.
Applicable repr =>
TermGrammar (a -> b) -> repr a -> repr b
<$> TermGrammar [a] -> repr [a] -> repr [a]
forall (repr :: * -> *) a.
(Applicable repr, Alternable repr) =>
TermGrammar a -> repr a -> repr a
option TermGrammar [a]
forall (repr :: * -> *) a. Termable repr => repr [a]
H.nil repr [a]
seb1)
repr (a -> [a]) -> repr (a -> [a]) -> repr (a -> [a])
forall (repr :: * -> *) a.
Alternable repr =>
repr a -> repr a -> repr a
<|> TermGrammar (a -> [a]) -> repr (a -> [a])
forall (repr :: * -> *) a.
Applicable repr =>
TermGrammar a -> repr a
pure (Term ValueCode ((a -> [a] -> [a]) -> [a] -> a -> [a])
forall (repr :: * -> *) a b c.
Termable repr =>
repr ((a -> b -> c) -> b -> a -> c)
H.flip Term ValueCode ((a -> [a] -> [a]) -> [a] -> a -> [a])
-> Term ValueCode (a -> [a] -> [a])
-> Term ValueCode ([a] -> a -> [a])
forall (repr :: * -> *) a b.
Termable repr =>
repr (a -> b) -> repr a -> repr b
H..@ Term ValueCode (a -> [a] -> [a])
forall (repr :: * -> *) a. Termable repr => repr (a -> [a] -> [a])
H.cons Term ValueCode ([a] -> a -> [a])
-> TermGrammar [a] -> TermGrammar (a -> [a])
forall (repr :: * -> *) a b.
Termable repr =>
repr (a -> b) -> repr a -> repr b
H..@ TermGrammar [a]
forall (repr :: * -> *) a. Termable repr => repr [a]
H.nil))
in repr [a]
seb1