{-# LANGUAGE PatternSynonyms #-}
module Parsley.Internal.Core.Primitives (
    Parser,
    Reg,
    module Parsley.Internal.Core.Primitives
  ) where

import Prelude hiding                      (pure, (<*>))
import Parsley.Internal.Core.CombinatorAST (Combinator(..), ScopeRegister(..), Reg(..), Parser(..), PosSelector(..))
import Parsley.Internal.Core.Defunc        (Defunc, charPred)

import Parsley.Internal.Common.Indexed     (Fix(In), (:+:)(..))

-- Core smart constructors
{-# INLINE pure #-}
pure :: Defunc a -> Parser a
pure :: Defunc a -> Parser a
pure = Fix (Combinator :+: ScopeRegister) a -> Parser a
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser (Fix (Combinator :+: ScopeRegister) a -> Parser a)
-> (Defunc a -> Fix (Combinator :+: ScopeRegister) a)
-> Defunc a
-> Parser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
-> Fix (Combinator :+: ScopeRegister) a
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In ((:+:)
   Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
 -> Fix (Combinator :+: ScopeRegister) a)
-> (Defunc a
    -> (:+:)
         Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a)
-> Defunc a
-> Fix (Combinator :+: ScopeRegister) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Combinator (Fix (Combinator :+: ScopeRegister)) a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (Combinator (Fix (Combinator :+: ScopeRegister)) a
 -> (:+:)
      Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a)
-> (Defunc a -> Combinator (Fix (Combinator :+: ScopeRegister)) a)
-> Defunc a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Defunc a -> Combinator (Fix (Combinator :+: ScopeRegister)) a
forall a (k :: Type -> Type). Defunc a -> Combinator k a
Pure

{-# INLINE satisfy #-}
satisfy :: Defunc (Char -> Bool) -> Parser Char
satisfy :: Defunc (Char -> Bool) -> Parser Char
satisfy = Fix (Combinator :+: ScopeRegister) Char -> Parser Char
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser (Fix (Combinator :+: ScopeRegister) Char -> Parser Char)
-> (Defunc (Char -> Bool)
    -> Fix (Combinator :+: ScopeRegister) Char)
-> Defunc (Char -> Bool)
-> Parser Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) Char
-> Fix (Combinator :+: ScopeRegister) Char
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In ((:+:)
   Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) Char
 -> Fix (Combinator :+: ScopeRegister) Char)
-> (Defunc (Char -> Bool)
    -> (:+:)
         Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) Char)
-> Defunc (Char -> Bool)
-> Fix (Combinator :+: ScopeRegister) Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Combinator (Fix (Combinator :+: ScopeRegister)) Char
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) Char
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (Combinator (Fix (Combinator :+: ScopeRegister)) Char
 -> (:+:)
      Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) Char)
-> (Defunc (Char -> Bool)
    -> Combinator (Fix (Combinator :+: ScopeRegister)) Char)
-> Defunc (Char -> Bool)
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CharPred -> Combinator (Fix (Combinator :+: ScopeRegister)) Char
forall (k :: Type -> Type). CharPred -> Combinator k Char
Satisfy (CharPred -> Combinator (Fix (Combinator :+: ScopeRegister)) Char)
-> (Defunc (Char -> Bool) -> CharPred)
-> Defunc (Char -> Bool)
-> Combinator (Fix (Combinator :+: ScopeRegister)) Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Defunc (Char -> Bool) -> CharPred
charPred

{-# INLINE conditional #-}
conditional :: [(Defunc (a -> Bool), Parser b)] -> Parser a -> Parser b -> Parser b
conditional :: [(Defunc (a -> Bool), Parser b)]
-> Parser a -> Parser b -> Parser b
conditional [(Defunc (a -> Bool), Parser b)]
cs (Parser Fix (Combinator :+: ScopeRegister) a
p) (Parser Fix (Combinator :+: ScopeRegister) b
def) =
  let ([Defunc (a -> Bool)]
fs, [Parser b]
qs) = [(Defunc (a -> Bool), Parser b)]
-> ([Defunc (a -> Bool)], [Parser b])
forall a b. [(a, b)] -> ([a], [b])
unzip [(Defunc (a -> Bool), Parser b)]
cs
  in Fix (Combinator :+: ScopeRegister) b -> Parser b
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) b
-> Fix (Combinator :+: ScopeRegister) b
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) b
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) b
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (Fix (Combinator :+: ScopeRegister) a
-> [Defunc (a -> Bool)]
-> [Fix (Combinator :+: ScopeRegister) b]
-> Fix (Combinator :+: ScopeRegister) b
-> Combinator (Fix (Combinator :+: ScopeRegister)) b
forall (k :: Type -> Type) a b.
k a -> [Defunc (a -> Bool)] -> [k b] -> k b -> Combinator k b
Match Fix (Combinator :+: ScopeRegister) a
p [Defunc (a -> Bool)]
fs ((Parser b -> Fix (Combinator :+: ScopeRegister) b)
-> [Parser b] -> [Fix (Combinator :+: ScopeRegister) b]
forall a b. (a -> b) -> [a] -> [b]
map Parser b -> Fix (Combinator :+: ScopeRegister) b
forall a. Parser a -> Fix (Combinator :+: ScopeRegister) a
unParser [Parser b]
qs) Fix (Combinator :+: ScopeRegister) b
def)))

{-# INLINE (<*>) #-}
(<*>) :: Parser (a -> b) -> Parser a -> Parser b
Parser Fix (Combinator :+: ScopeRegister) (a -> b)
p <*> :: Parser (a -> b) -> Parser a -> Parser b
<*> Parser Fix (Combinator :+: ScopeRegister) a
q = Fix (Combinator :+: ScopeRegister) b -> Parser b
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) b
-> Fix (Combinator :+: ScopeRegister) b
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) b
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) b
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (Fix (Combinator :+: ScopeRegister) (a -> b)
p Fix (Combinator :+: ScopeRegister) (a -> b)
-> Fix (Combinator :+: ScopeRegister) a
-> Combinator (Fix (Combinator :+: ScopeRegister)) b
forall (k :: Type -> Type) a b. k (a -> b) -> k a -> Combinator k b
:<*>: Fix (Combinator :+: ScopeRegister) a
q)))

{-# INLINE (<*) #-}
(<*) :: Parser a -> Parser b -> Parser a
Parser Fix (Combinator :+: ScopeRegister) a
p <* :: Parser a -> Parser b -> Parser a
<* Parser Fix (Combinator :+: ScopeRegister) b
q = Fix (Combinator :+: ScopeRegister) a -> Parser a
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
-> Fix (Combinator :+: ScopeRegister) a
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (Fix (Combinator :+: ScopeRegister) a
p Fix (Combinator :+: ScopeRegister) a
-> Fix (Combinator :+: ScopeRegister) b
-> Combinator (Fix (Combinator :+: ScopeRegister)) a
forall (k :: Type -> Type) a b. k a -> k b -> Combinator k a
:<*: Fix (Combinator :+: ScopeRegister) b
q)))

{-# INLINE (*>) #-}
(*>) :: Parser a -> Parser b -> Parser b
Parser Fix (Combinator :+: ScopeRegister) a
p *> :: Parser a -> Parser b -> Parser b
*> Parser Fix (Combinator :+: ScopeRegister) b
q = Fix (Combinator :+: ScopeRegister) b -> Parser b
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) b
-> Fix (Combinator :+: ScopeRegister) b
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) b
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) b
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (Fix (Combinator :+: ScopeRegister) a
p Fix (Combinator :+: ScopeRegister) a
-> Fix (Combinator :+: ScopeRegister) b
-> Combinator (Fix (Combinator :+: ScopeRegister)) b
forall (k :: Type -> Type) a b. k a -> k b -> Combinator k b
:*>: Fix (Combinator :+: ScopeRegister) b
q)))

{-# INLINE empty #-}
empty :: Parser a
empty :: Parser a
empty = Fix (Combinator :+: ScopeRegister) a -> Parser a
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
-> Fix (Combinator :+: ScopeRegister) a
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L Combinator (Fix (Combinator :+: ScopeRegister)) a
forall (k :: Type -> Type) a. Combinator k a
Empty))

{-# INLINE (<|>) #-}
(<|>) :: Parser a -> Parser a -> Parser a
Parser Fix (Combinator :+: ScopeRegister) a
p <|> :: Parser a -> Parser a -> Parser a
<|> Parser Fix (Combinator :+: ScopeRegister) a
q = Fix (Combinator :+: ScopeRegister) a -> Parser a
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
-> Fix (Combinator :+: ScopeRegister) a
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (Fix (Combinator :+: ScopeRegister) a
p Fix (Combinator :+: ScopeRegister) a
-> Fix (Combinator :+: ScopeRegister) a
-> Combinator (Fix (Combinator :+: ScopeRegister)) a
forall (k :: Type -> Type) a. k a -> k a -> Combinator k a
:<|>: Fix (Combinator :+: ScopeRegister) a
q)))

{-# INLINE lookAhead #-}
lookAhead :: Parser a -> Parser a
lookAhead :: Parser a -> Parser a
lookAhead = Fix (Combinator :+: ScopeRegister) a -> Parser a
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser (Fix (Combinator :+: ScopeRegister) a -> Parser a)
-> (Parser a -> Fix (Combinator :+: ScopeRegister) a)
-> Parser a
-> Parser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
-> Fix (Combinator :+: ScopeRegister) a
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In ((:+:)
   Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
 -> Fix (Combinator :+: ScopeRegister) a)
-> (Parser a
    -> (:+:)
         Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a)
-> Parser a
-> Fix (Combinator :+: ScopeRegister) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Combinator (Fix (Combinator :+: ScopeRegister)) a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (Combinator (Fix (Combinator :+: ScopeRegister)) a
 -> (:+:)
      Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a)
-> (Parser a -> Combinator (Fix (Combinator :+: ScopeRegister)) a)
-> Parser a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fix (Combinator :+: ScopeRegister) a
-> Combinator (Fix (Combinator :+: ScopeRegister)) a
forall (k :: Type -> Type) a. k a -> Combinator k a
LookAhead (Fix (Combinator :+: ScopeRegister) a
 -> Combinator (Fix (Combinator :+: ScopeRegister)) a)
-> (Parser a -> Fix (Combinator :+: ScopeRegister) a)
-> Parser a
-> Combinator (Fix (Combinator :+: ScopeRegister)) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser a -> Fix (Combinator :+: ScopeRegister) a
forall a. Parser a -> Fix (Combinator :+: ScopeRegister) a
unParser

{-# INLINE notFollowedBy #-}
notFollowedBy :: Parser a -> Parser ()
notFollowedBy :: Parser a -> Parser ()
notFollowedBy = Fix (Combinator :+: ScopeRegister) () -> Parser ()
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser (Fix (Combinator :+: ScopeRegister) () -> Parser ())
-> (Parser a -> Fix (Combinator :+: ScopeRegister) ())
-> Parser a
-> Parser ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) ()
-> Fix (Combinator :+: ScopeRegister) ()
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In ((:+:)
   Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) ()
 -> Fix (Combinator :+: ScopeRegister) ())
-> (Parser a
    -> (:+:)
         Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) ())
-> Parser a
-> Fix (Combinator :+: ScopeRegister) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Combinator (Fix (Combinator :+: ScopeRegister)) ()
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) ()
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (Combinator (Fix (Combinator :+: ScopeRegister)) ()
 -> (:+:)
      Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) ())
-> (Parser a -> Combinator (Fix (Combinator :+: ScopeRegister)) ())
-> Parser a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fix (Combinator :+: ScopeRegister) a
-> Combinator (Fix (Combinator :+: ScopeRegister)) ()
forall (k :: Type -> Type) a. k a -> Combinator k ()
NotFollowedBy (Fix (Combinator :+: ScopeRegister) a
 -> Combinator (Fix (Combinator :+: ScopeRegister)) ())
-> (Parser a -> Fix (Combinator :+: ScopeRegister) a)
-> Parser a
-> Combinator (Fix (Combinator :+: ScopeRegister)) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser a -> Fix (Combinator :+: ScopeRegister) a
forall a. Parser a -> Fix (Combinator :+: ScopeRegister) a
unParser

{-# INLINE try #-}
try :: Parser a -> Parser a
try :: Parser a -> Parser a
try = Fix (Combinator :+: ScopeRegister) a -> Parser a
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser (Fix (Combinator :+: ScopeRegister) a -> Parser a)
-> (Parser a -> Fix (Combinator :+: ScopeRegister) a)
-> Parser a
-> Parser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
-> Fix (Combinator :+: ScopeRegister) a
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In ((:+:)
   Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
 -> Fix (Combinator :+: ScopeRegister) a)
-> (Parser a
    -> (:+:)
         Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a)
-> Parser a
-> Fix (Combinator :+: ScopeRegister) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Combinator (Fix (Combinator :+: ScopeRegister)) a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (Combinator (Fix (Combinator :+: ScopeRegister)) a
 -> (:+:)
      Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a)
-> (Parser a -> Combinator (Fix (Combinator :+: ScopeRegister)) a)
-> Parser a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fix (Combinator :+: ScopeRegister) a
-> Combinator (Fix (Combinator :+: ScopeRegister)) a
forall (k :: Type -> Type) a. k a -> Combinator k a
Try (Fix (Combinator :+: ScopeRegister) a
 -> Combinator (Fix (Combinator :+: ScopeRegister)) a)
-> (Parser a -> Fix (Combinator :+: ScopeRegister) a)
-> Parser a
-> Combinator (Fix (Combinator :+: ScopeRegister)) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser a -> Fix (Combinator :+: ScopeRegister) a
forall a. Parser a -> Fix (Combinator :+: ScopeRegister) a
unParser

{-# INLINE branch #-}
branch :: Parser (Either a b) -> Parser (a -> c) -> Parser (b -> c) -> Parser c
branch :: Parser (Either a b)
-> Parser (a -> c) -> Parser (b -> c) -> Parser c
branch (Parser Fix (Combinator :+: ScopeRegister) (Either a b)
c) (Parser Fix (Combinator :+: ScopeRegister) (a -> c)
p) (Parser Fix (Combinator :+: ScopeRegister) (b -> c)
q) = Fix (Combinator :+: ScopeRegister) c -> Parser c
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) c
-> Fix (Combinator :+: ScopeRegister) c
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) c
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) c
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (Fix (Combinator :+: ScopeRegister) (Either a b)
-> Fix (Combinator :+: ScopeRegister) (a -> c)
-> Fix (Combinator :+: ScopeRegister) (b -> c)
-> Combinator (Fix (Combinator :+: ScopeRegister)) c
forall (k :: Type -> Type) a b c.
k (Either a b) -> k (a -> c) -> k (b -> c) -> Combinator k c
Branch Fix (Combinator :+: ScopeRegister) (Either a b)
c Fix (Combinator :+: ScopeRegister) (a -> c)
p Fix (Combinator :+: ScopeRegister) (b -> c)
q)))

{-# INLINE loop #-}
loop :: Parser () -> Parser a -> Parser a
loop :: Parser () -> Parser a -> Parser a
loop (Parser Fix (Combinator :+: ScopeRegister) ()
body) (Parser Fix (Combinator :+: ScopeRegister) a
exit) = Fix (Combinator :+: ScopeRegister) a -> Parser a
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
-> Fix (Combinator :+: ScopeRegister) a
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (Fix (Combinator :+: ScopeRegister) ()
-> Fix (Combinator :+: ScopeRegister) a
-> Combinator (Fix (Combinator :+: ScopeRegister)) a
forall (k :: Type -> Type) a. k () -> k a -> Combinator k a
Loop Fix (Combinator :+: ScopeRegister) ()
body Fix (Combinator :+: ScopeRegister) a
exit)))

{-# INLINE newRegister #-}
newRegister :: Parser a -> (forall r. Reg r a -> Parser b) -> Parser b
newRegister :: Parser a -> (forall r. Reg r a -> Parser b) -> Parser b
newRegister (Parser Fix (Combinator :+: ScopeRegister) a
p) forall r. Reg r a -> Parser b
f = Fix (Combinator :+: ScopeRegister) b -> Parser b
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) b
-> Fix (Combinator :+: ScopeRegister) b
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (ScopeRegister (Fix (Combinator :+: ScopeRegister)) b
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) b
forall k k (g :: k -> k -> Type) (k :: k) (a :: k)
       (f :: k -> k -> Type).
g k a -> (:+:) f g k a
R (Fix (Combinator :+: ScopeRegister) a
-> (forall r. Reg r a -> Fix (Combinator :+: ScopeRegister) b)
-> ScopeRegister (Fix (Combinator :+: ScopeRegister)) b
forall (k :: Type -> Type) a b.
k a -> (forall r. Reg r a -> k b) -> ScopeRegister k b
ScopeRegister Fix (Combinator :+: ScopeRegister) a
p (Parser b -> Fix (Combinator :+: ScopeRegister) b
forall a. Parser a -> Fix (Combinator :+: ScopeRegister) a
unParser (Parser b -> Fix (Combinator :+: ScopeRegister) b)
-> (Reg r a -> Parser b)
-> Reg r a
-> Fix (Combinator :+: ScopeRegister) b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Reg r a -> Parser b
forall r. Reg r a -> Parser b
f))))

{-# INLINE get #-}
get :: Reg r a -> Parser a
get :: Reg r a -> Parser a
get (Reg ΣVar a
reg) = Fix (Combinator :+: ScopeRegister) a -> Parser a
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
-> Fix (Combinator :+: ScopeRegister) a
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (ΣVar a -> Combinator (Fix (Combinator :+: ScopeRegister)) a
forall a (k :: Type -> Type). ΣVar a -> Combinator k a
GetRegister ΣVar a
reg)))

{-# INLINE put #-}
put :: Reg r a -> Parser a -> Parser ()
put :: Reg r a -> Parser a -> Parser ()
put (Reg ΣVar a
reg) (Parser Fix (Combinator :+: ScopeRegister) a
p) = Fix (Combinator :+: ScopeRegister) () -> Parser ()
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) ()
-> Fix (Combinator :+: ScopeRegister) ()
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) ()
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) ()
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (ΣVar a
-> Fix (Combinator :+: ScopeRegister) a
-> Combinator (Fix (Combinator :+: ScopeRegister)) ()
forall a (k :: Type -> Type). ΣVar a -> k a -> Combinator k ()
PutRegister ΣVar a
reg Fix (Combinator :+: ScopeRegister) a
p)))

{-# INLINE line #-}
line :: Parser Int
line :: Parser Int
line = Fix (Combinator :+: ScopeRegister) Int -> Parser Int
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) Int
-> Fix (Combinator :+: ScopeRegister) Int
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) Int
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) Int
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (PosSelector -> Combinator (Fix (Combinator :+: ScopeRegister)) Int
forall (k :: Type -> Type). PosSelector -> Combinator k Int
Position PosSelector
Line)))

{-# INLINE col #-}
col :: Parser Int
col :: Parser Int
col = Fix (Combinator :+: ScopeRegister) Int -> Parser Int
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) Int
-> Fix (Combinator :+: ScopeRegister) Int
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) Int
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) Int
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (PosSelector -> Combinator (Fix (Combinator :+: ScopeRegister)) Int
forall (k :: Type -> Type). PosSelector -> Combinator k Int
Position PosSelector
Col)))

{-# INLINE debug #-}
debug :: String -> Parser a -> Parser a
debug :: String -> Parser a -> Parser a
debug String
name (Parser Fix (Combinator :+: ScopeRegister) a
p) = Fix (Combinator :+: ScopeRegister) a -> Parser a
forall a. Fix (Combinator :+: ScopeRegister) a -> Parser a
Parser ((:+:)
  Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
-> Fix (Combinator :+: ScopeRegister) a
forall k (f :: (k -> Type) -> k -> Type) (a :: k).
f (Fix f) a -> Fix f a
In (Combinator (Fix (Combinator :+: ScopeRegister)) a
-> (:+:)
     Combinator ScopeRegister (Fix (Combinator :+: ScopeRegister)) a
forall k k (f :: k -> k -> Type) (k :: k) (a :: k)
       (g :: k -> k -> Type).
f k a -> (:+:) f g k a
L (String
-> Fix (Combinator :+: ScopeRegister) a
-> Combinator (Fix (Combinator :+: ScopeRegister)) a
forall (k :: Type -> Type) a. String -> k a -> Combinator k a
Debug String
name Fix (Combinator :+: ScopeRegister) a
p)))