module UVMHS.Lib.Parser.Core where

import UVMHS.Core

import UVMHS.Lib.Pretty
import UVMHS.Lib.Window
import UVMHS.Lib.Annotated

import UVMHS.Lib.Parser.ParserInput
import UVMHS.Lib.Parser.ParserContext
import UVMHS.Lib.Parser.ParserError
import UVMHS.Lib.Parser.Loc

---------------
-- ParserEnv --
---------------

data ParserEnv = ParserEnv
  { ParserEnv -> 𝔹
parserEnvReportErrors  𝔹
  , ParserEnv -> Formats
parserEnvRenderFormat  Formats
  , ParserEnv -> 𝕊 ∧ 𝐼 𝕊
parserEnvErrorStack  𝕊  𝐼 𝕊
  , ParserEnv -> 𝕊
parserEnvSourceName  𝕊
  }
makeLenses ''ParserEnv
makePrettyRecord ''ParserEnv

parserEnv₀  𝕊  ParserEnv
parserEnv₀ :: 𝕊 -> ParserEnv
parserEnv₀ = 𝔹 -> Formats -> (𝕊 ∧ 𝐼 𝕊) -> 𝕊 -> ParserEnv
ParserEnv 𝔹
True Formats
forall a. Null a => a
null ((𝕊 ∧ 𝐼 𝕊) -> 𝕊 -> ParserEnv) -> (𝕊 ∧ 𝐼 𝕊) -> 𝕊 -> ParserEnv
forall a b. (a -> b) -> a -> b
$ 𝕊
"<top level>" 𝕊 -> 𝐼 𝕊 -> 𝕊 ∧ 𝐼 𝕊
forall a b. a -> b -> a ∧ b
:* 𝐼 𝕊
forall a. Null a => a
null

---------------
-- ParserOut --
---------------

type ParserOut t = AddNull (ParserError t)

-----------------
-- ParserState --
-----------------

data ParserState t = ParserState
  { forall t. ParserState t -> WindowR Doc Doc
parserStatePrefix  WindowR Doc Doc
  , forall t. ParserState t -> ParserContext
parserStateSkipContext  ParserContext
  , forall t. ParserState t -> ParserContext
parserStateContext  ParserContext
  , forall t. ParserState t -> WindowL Doc Doc
parserStateSuffix  WindowL Doc Doc
  , forall t. ParserState t -> AddBT Loc
parserStateEndPos  AddBT Loc
  , forall t. ParserState t -> 𝑆 (ParserToken t)
parserStateInput  𝑆 (ParserToken t)
  }
makeLenses ''ParserState
makePrettyRecord ''ParserState

parserState₀  𝑆 (ParserToken t)  ParserState t
parserState₀ :: forall t. 𝑆 (ParserToken t) -> ParserState t
parserState₀ = WindowR Doc Doc
-> ParserContext
-> ParserContext
-> WindowL Doc Doc
-> AddBT Loc
-> 𝑆 (ParserToken t)
-> ParserState t
forall t.
WindowR Doc Doc
-> ParserContext
-> ParserContext
-> WindowL Doc Doc
-> AddBT Loc
-> 𝑆 (ParserToken t)
-> ParserState t
ParserState WindowR Doc Doc
forall a. Null a => a
null ParserContext
forall a. Null a => a
null ParserContext
forall a. Null a => a
null WindowL Doc Doc
forall a. Null a => a
null (AddBT Loc -> 𝑆 (ParserToken t) -> ParserState t)
-> AddBT Loc -> 𝑆 (ParserToken t) -> ParserState t
forall a b. (a -> b) -> a -> b
$ Loc -> AddBT Loc
forall a. a -> AddBT a
AddBT Loc
forall a. Bot a => a
bot

-- # Parser

newtype Parser t a = Parser { forall t a.
Parser t a
-> ReaderT
     ParserEnv (StateT (ParserState t) (FailT ((∧) (ParserOut t)))) a
unParser  ReaderT ParserEnv (StateT (ParserState t) (FailT ((∧) (ParserOut t)))) a } 
  deriving 
  ( (forall a b. (a -> b) -> Parser t a -> Parser t b)
-> Functor (Parser t)
forall a b. (a -> b) -> Parser t a -> Parser t b
forall t a b. (a -> b) -> Parser t a -> Parser t b
forall (t :: * -> *).
(forall a b. (a -> b) -> t a -> t b) -> Functor t
$cmap :: forall t a b. (a -> b) -> Parser t a -> Parser t b
map :: forall a b. (a -> b) -> Parser t a -> Parser t b
Functor,(forall a. a -> Parser t a) -> Return (Parser t)
forall a. a -> Parser t a
forall t a. a -> Parser t a
forall (m :: * -> *). (forall a. a -> m a) -> Return m
$creturn :: forall t a. a -> Parser t a
return :: forall a. a -> Parser t a
Return,(forall a b. Parser t a -> (a -> Parser t b) -> Parser t b)
-> Bind (Parser t)
forall a b. Parser t a -> (a -> Parser t b) -> Parser t b
forall t a b. Parser t a -> (a -> Parser t b) -> Parser t b
forall (m :: * -> *).
(forall a b. m a -> (a -> m b) -> m b) -> Bind m
$c≫= :: forall t a b. Parser t a -> (a -> Parser t b) -> Parser t b
≫= :: forall a b. Parser t a -> (a -> Parser t b) -> Parser t b
Bind,Bind (Parser t)
Return (Parser t)
Functor (Parser t)
(Functor (Parser t), Return (Parser t), Bind (Parser t)) =>
Monad (Parser t)
forall t. Bind (Parser t)
forall t. Return (Parser t)
forall t. Functor (Parser t)
forall (m :: * -> *). (Functor m, Return m, Bind m) => Monad m
Monad
  , (forall a. Parser t a)
-> (forall a. Parser t a -> Parser t a -> Parser t a)
-> MonadFail (Parser t)
forall a. Parser t a
forall a. Parser t a -> Parser t a -> Parser t a
forall t a. Parser t a
forall t a. Parser t a -> Parser t a -> Parser t a
forall {k} (m :: k -> *).
(forall (a :: k). m a)
-> (forall (a :: k). m a -> m a -> m a) -> MonadFail m
$cabort :: forall t a. Parser t a
abort :: forall a. Parser t a
$c⎅ :: forall t a. Parser t a -> Parser t a -> Parser t a
⎅ :: forall a. Parser t a -> Parser t a -> Parser t a
MonadFail
  , MonadReader ParserEnv
  , MonadWriter (ParserOut t)
  , MonadState (ParserState t)
  )

runParser  ParserEnv  ParserState t  Parser t a  ParserOut t  𝑂 (ParserState t  a)
runParser :: forall t a.
ParserEnv
-> ParserState t
-> Parser t a
-> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
runParser ParserEnv
e ParserState t
s = FailT ((∧) (ParserOut t)) (ParserState t ∧ a)
-> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT (FailT ((∧) (ParserOut t)) (ParserState t ∧ a)
 -> ParserOut t ∧ 𝑂 (ParserState t ∧ a))
-> (StateT (ParserState t) (FailT ((∧) (ParserOut t))) a
    -> FailT ((∧) (ParserOut t)) (ParserState t ∧ a))
-> StateT (ParserState t) (FailT ((∧) (ParserOut t))) a
-> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 ParserState t
-> StateT (ParserState t) (FailT ((∧) (ParserOut t))) a
-> FailT ((∧) (ParserOut t)) (ParserState t ∧ a)
forall s (m :: * -> *) a. s -> StateT s m a -> m (s ∧ a)
runStateT ParserState t
s (StateT (ParserState t) (FailT ((∧) (ParserOut t))) a
 -> ParserOut t ∧ 𝑂 (ParserState t ∧ a))
-> (ReaderT
      ParserEnv (StateT (ParserState t) (FailT ((∧) (ParserOut t)))) a
    -> StateT (ParserState t) (FailT ((∧) (ParserOut t))) a)
-> ReaderT
     ParserEnv (StateT (ParserState t) (FailT ((∧) (ParserOut t)))) a
-> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 ParserEnv
-> ReaderT
     ParserEnv (StateT (ParserState t) (FailT ((∧) (ParserOut t)))) a
-> StateT (ParserState t) (FailT ((∧) (ParserOut t))) a
forall {k} r (m :: k -> *) (a :: k). r -> ReaderT r m a -> m a
runReaderT ParserEnv
e (ReaderT
   ParserEnv (StateT (ParserState t) (FailT ((∧) (ParserOut t)))) a
 -> ParserOut t ∧ 𝑂 (ParserState t ∧ a))
-> (Parser t a
    -> ReaderT
         ParserEnv (StateT (ParserState t) (FailT ((∧) (ParserOut t)))) a)
-> Parser t a
-> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 Parser t a
-> ReaderT
     ParserEnv (StateT (ParserState t) (FailT ((∧) (ParserOut t)))) a
forall t a.
Parser t a
-> ReaderT
     ParserEnv (StateT (ParserState t) (FailT ((∧) (ParserOut t)))) a
unParser

-------------------------
-- Low Level Interface --
-------------------------

pNewExpressionContext  Parser t a  Parser t a
pNewExpressionContext :: forall t a. Parser t a -> Parser t a
pNewExpressionContext Parser t a
aM = do
  WindowR Doc Doc
pp  (ParserState t ⟢ WindowR Doc Doc) -> Parser t (WindowR Doc Doc)
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ WindowR Doc Doc
forall t. ParserState t ⟢ WindowR Doc Doc
parserStatePrefixL
  ParserContext
pk  (ParserState t ⟢ ParserContext) -> Parser t ParserContext
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateSkipContextL
  ParserContext
pc  (ParserState t ⟢ ParserContext) -> Parser t ParserContext
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateContextL
  (ParserState t ⟢ WindowR Doc Doc) -> WindowR Doc Doc -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ WindowR Doc Doc
forall t. ParserState t ⟢ WindowR Doc Doc
parserStatePrefixL (WindowR Doc Doc -> Parser t ()) -> WindowR Doc Doc -> Parser t ()
forall a b. (a -> b) -> a -> b
$ [WindowR Doc Doc] -> WindowR Doc Doc
forall a t. (Monoid a, ToIter a t) => t -> a
concat [WindowR Doc Doc
pp,ParserContext -> WindowR Doc Doc
parserContextDisplayR ParserContext
pk,ParserContext -> WindowR Doc Doc
parserContextDisplayR ParserContext
pc]
  (ParserState t ⟢ ParserContext) -> ParserContext -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateSkipContextL ParserContext
forall a. Null a => a
null
  (ParserState t ⟢ ParserContext) -> ParserContext -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateContextL ParserContext
forall a. Null a => a
null
  a
a  Parser t a
aM
  ParserContext
pk'  (ParserState t ⟢ ParserContext) -> Parser t ParserContext
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateSkipContextL
  ParserContext
pc'  (ParserState t ⟢ ParserContext) -> Parser t ParserContext
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateContextL
  (ParserState t ⟢ WindowR Doc Doc) -> WindowR Doc Doc -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ WindowR Doc Doc
forall t. ParserState t ⟢ WindowR Doc Doc
parserStatePrefixL WindowR Doc Doc
pp
  if ParserContext -> LocRange
parserContextLocRange ParserContext
pc LocRange -> LocRange -> 𝔹
forall a. Eq a => a -> a -> 𝔹
 LocRange
forall a. Bot a => a
bot
    then do
      (ParserState t ⟢ ParserContext) -> ParserContext -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateSkipContextL (ParserContext -> Parser t ()) -> ParserContext -> Parser t ()
forall a b. (a -> b) -> a -> b
$ ParserContext
pk ParserContext -> ParserContext -> ParserContext
forall a. Append a => a -> a -> a
 ParserContext
pk'
      (ParserState t ⟢ ParserContext) -> ParserContext -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateContextL ParserContext
pc'
    else do
      (ParserState t ⟢ ParserContext) -> ParserContext -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateSkipContextL ParserContext
pk
      (ParserState t ⟢ ParserContext) -> ParserContext -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateContextL (ParserContext -> Parser t ()) -> ParserContext -> Parser t ()
forall a b. (a -> b) -> a -> b
$ ParserContext
pc ParserContext -> ParserContext -> ParserContext
forall a. Append a => a -> a -> a
 ParserContext
pk' ParserContext -> ParserContext -> ParserContext
forall a. Append a => a -> a -> a
 ParserContext
pc'
  a -> Parser t a
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return a
a

pGetContext  Parser t (WindowR Doc Doc  ParserContext  WindowL Doc Doc)
pGetContext :: forall t.
Parser t ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
pGetContext = do
  WindowR Doc Doc
pp  (ParserState t ⟢ WindowR Doc Doc) -> Parser t (WindowR Doc Doc)
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ WindowR Doc Doc
forall t. ParserState t ⟢ WindowR Doc Doc
parserStatePrefixL
  ParserContext
pk  (ParserState t ⟢ ParserContext) -> Parser t ParserContext
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateSkipContextL
  ParserContext
pc  (ParserState t ⟢ ParserContext) -> Parser t ParserContext
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateContextL
  WindowL Doc Doc
ps  (ParserState t ⟢ WindowL Doc Doc) -> Parser t (WindowL Doc Doc)
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ WindowL Doc Doc
forall t. ParserState t ⟢ WindowL Doc Doc
parserStateSuffixL
  ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
-> Parser t ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return (((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
 -> Parser t ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc))
-> ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
-> Parser t ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
forall a b. (a -> b) -> a -> b
$ (WindowR Doc Doc
pp WindowR Doc Doc -> WindowR Doc Doc -> WindowR Doc Doc
forall a. Append a => a -> a -> a
 ParserContext -> WindowR Doc Doc
parserContextDisplayR ParserContext
pk) WindowR Doc Doc -> ParserContext -> WindowR Doc Doc ∧ ParserContext
forall a b. a -> b -> a ∧ b
:* ParserContext
pc (WindowR Doc Doc ∧ ParserContext)
-> WindowL Doc Doc
-> (WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc
forall a b. a -> b -> a ∧ b
:* WindowL Doc Doc
ps
  
pGetContextRendered  Parser t SrcCxt
pGetContextRendered :: forall t. Parser t SrcCxt
pGetContextRendered = do
  WindowR Doc Doc
pp :* ParserContext
pc :* WindowL Doc Doc
ps  Parser t ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
forall t.
Parser t ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
pGetContext
  𝕊
n  (ParserEnv ⟢ 𝕊) -> Parser t 𝕊
forall r'. (ParserEnv ⟢ r') -> Parser t r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL ParserEnv ⟢ 𝕊
parserEnvSourceNameL
  SrcCxt -> Parser t SrcCxt
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return (SrcCxt -> Parser t SrcCxt) -> SrcCxt -> Parser t SrcCxt
forall a b. (a -> b) -> a -> b
$ 𝕊
-> LocRange
-> WindowR Doc Doc
-> WindowL Doc Doc
-> WindowL Doc Doc
-> SrcCxt
SrcCxt 𝕊
n (ParserContext -> LocRange
parserContextLocRange ParserContext
pc) WindowR Doc Doc
pp (ParserContext -> WindowL Doc Doc
parserContextDisplayL ParserContext
pc) WindowL Doc Doc
ps

pWithContext  Parser t a  Parser t (WindowR Doc Doc  ParserContext  WindowL Doc Doc  a)
pWithContext :: forall t a.
Parser t a
-> Parser
     t (((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc) ∧ a)
pWithContext Parser t a
aM = do
  a
x  Parser t a
aM
  WindowR Doc Doc
pp :* ParserContext
pc :* WindowL Doc Doc
ps  Parser t ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
forall t.
Parser t ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
pGetContext
  (((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc) ∧ a)
-> Parser
     t (((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc) ∧ a)
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return ((((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc) ∧ a)
 -> Parser
      t (((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc) ∧ a))
-> (((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc) ∧ a)
-> Parser
     t (((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc) ∧ a)
forall a b. (a -> b) -> a -> b
$ WindowR Doc Doc
pp WindowR Doc Doc -> ParserContext -> WindowR Doc Doc ∧ ParserContext
forall a b. a -> b -> a ∧ b
:* ParserContext
pc (WindowR Doc Doc ∧ ParserContext)
-> WindowL Doc Doc
-> (WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc
forall a b. a -> b -> a ∧ b
:* WindowL Doc Doc
ps ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
-> a -> ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc) ∧ a
forall a b. a -> b -> a ∧ b
:* a
x

pFail  ParserContext  WindowL Doc Doc  Parser t a
pFail :: forall t a. ParserContext -> WindowL Doc Doc -> Parser t a
pFail ParserContext
tc WindowL Doc Doc
ps = do
  Parser t 𝔹 -> (() -> Parser t ()) -> Parser t ()
forall (m :: * -> *). Monad m => m 𝔹 -> (() -> m ()) -> m ()
whenM ((ParserEnv ⟢ 𝔹) -> Parser t 𝔹
forall r'. (ParserEnv ⟢ r') -> Parser t r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL ParserEnv ⟢ 𝔹
parserEnvReportErrorsL) ((() -> Parser t ()) -> Parser t ())
-> (() -> Parser t ()) -> Parser t ()
forall a b. (a -> b) -> a -> b
$ \ ()  do
    let l :: AddBT Loc
l = LocRange -> AddBT Loc
locRangeEnd (LocRange -> AddBT Loc) -> LocRange -> AddBT Loc
forall a b. (a -> b) -> a -> b
$ ParserContext -> LocRange
parserContextLocRange ParserContext
tc
        d :: WindowR Doc Doc
d = ParserContext -> WindowR Doc Doc
parserContextError ParserContext
tc
    𝕊
e :* 𝐼 𝕊
es  (ParserEnv ⟢ (𝕊 ∧ 𝐼 𝕊)) -> Parser t (𝕊 ∧ 𝐼 𝕊)
forall r'. (ParserEnv ⟢ r') -> Parser t r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL ParserEnv ⟢ (𝕊 ∧ 𝐼 𝕊)
parserEnvErrorStackL
    WindowR Doc Doc
pp :* ParserContext
pc :* WindowL Doc Doc
_  Parser t ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
forall t.
Parser t ((WindowR Doc Doc ∧ ParserContext) ∧ WindowL Doc Doc)
pGetContext
    AddNull (ParserError t) -> Parser t ()
forall o (m :: * -> *). MonadWriter o m => o -> m ()
tell (AddNull (ParserError t) -> Parser t ())
-> AddNull (ParserError t) -> Parser t ()
forall a b. (a -> b) -> a -> b
$ ParserError t -> AddNull (ParserError t)
forall a. a -> AddNull a
AddNull (ParserError t -> AddNull (ParserError t))
-> ParserError t -> AddNull (ParserError t)
forall a b. (a -> b) -> a -> b
$ AddBT Loc
-> WindowR Doc Doc
-> WindowL Doc Doc
-> 𝐼 ParserErrorInfo
-> ParserError t
forall {k} (t :: k).
AddBT Loc
-> WindowR Doc Doc
-> WindowL Doc Doc
-> 𝐼 ParserErrorInfo
-> ParserError t
ParserError AddBT Loc
l WindowR Doc Doc
d WindowL Doc Doc
ps (𝐼 ParserErrorInfo -> ParserError t)
-> 𝐼 ParserErrorInfo -> ParserError t
forall a b. (a -> b) -> a -> b
$ ParserErrorInfo -> 𝐼 ParserErrorInfo
forall a t. Single a t => a -> t
single (ParserErrorInfo -> 𝐼 ParserErrorInfo)
-> ParserErrorInfo -> 𝐼 ParserErrorInfo
forall a b. (a -> b) -> a -> b
$ WindowR Doc Doc -> WindowR Doc Doc -> 𝕊 -> 𝐼 𝕊 -> ParserErrorInfo
ParserErrorInfo WindowR Doc Doc
pp (ParserContext -> WindowR Doc Doc
parserContextDisplayR ParserContext
pc) 𝕊
e 𝐼 𝕊
es
  Parser t a
forall a. Parser t a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort

pErr  𝕊  Parser t a  Parser t a
pErr :: forall t a. 𝕊 -> Parser t a -> Parser t a
pErr 𝕊
msg = (ParserEnv -> ParserEnv) -> Parser t a -> Parser t a
forall (m :: * -> *) r a.
(Monad m, MonadReader r m) =>
(r -> r) -> m a -> m a
mapEnv ((ParserEnv -> ParserEnv) -> Parser t a -> Parser t a)
-> (ParserEnv -> ParserEnv) -> Parser t a -> Parser t a
forall a b. (a -> b) -> a -> b
$ (ParserEnv ⟢ (𝕊 ∧ 𝐼 𝕊))
-> ((𝕊 ∧ 𝐼 𝕊) -> 𝕊 ∧ 𝐼 𝕊) -> ParserEnv -> ParserEnv
forall a b. (a ⟢ b) -> (b -> b) -> a -> a
forall (t :: * -> * -> *) a b.
Alter t =>
t a b -> (b -> b) -> a -> a
alter ParserEnv ⟢ (𝕊 ∧ 𝐼 𝕊)
parserEnvErrorStackL (((𝕊 ∧ 𝐼 𝕊) -> 𝕊 ∧ 𝐼 𝕊) -> ParserEnv -> ParserEnv)
-> ((𝕊 ∧ 𝐼 𝕊) -> 𝕊 ∧ 𝐼 𝕊) -> ParserEnv -> ParserEnv
forall a b. (a -> b) -> a -> b
$ \ (𝕊
msg' :* 𝐼 𝕊
stack)  𝕊
msg 𝕊 -> 𝐼 𝕊 -> 𝕊 ∧ 𝐼 𝕊
forall a b. a -> b -> a ∧ b
:* (𝐼 𝕊
stack 𝐼 𝕊 -> 𝐼 𝕊 -> 𝐼 𝕊
forall a. Append a => a -> a -> a
 𝕊 -> 𝐼 𝕊
forall a t. Single a t => a -> t
single 𝕊
msg')

pNewErrContext  𝕊  Parser t a  Parser t a
pNewErrContext :: forall t a. 𝕊 -> Parser t a -> Parser t a
pNewErrContext 𝕊
msg = (ParserEnv -> ParserEnv) -> Parser t a -> Parser t a
forall (m :: * -> *) r a.
(Monad m, MonadReader r m) =>
(r -> r) -> m a -> m a
mapEnv ((ParserEnv -> ParserEnv) -> Parser t a -> Parser t a)
-> (ParserEnv -> ParserEnv) -> Parser t a -> Parser t a
forall a b. (a -> b) -> a -> b
$ (ParserEnv ⟢ (𝕊 ∧ 𝐼 𝕊)) -> (𝕊 ∧ 𝐼 𝕊) -> ParserEnv -> ParserEnv
forall (t :: * -> * -> *) a b. Alter t => t a b -> b -> a -> a
update ParserEnv ⟢ (𝕊 ∧ 𝐼 𝕊)
parserEnvErrorStackL ((𝕊 ∧ 𝐼 𝕊) -> ParserEnv -> ParserEnv)
-> (𝕊 ∧ 𝐼 𝕊) -> ParserEnv -> ParserEnv
forall a b. (a -> b) -> a -> b
$ 𝕊
msg 𝕊 -> 𝐼 𝕊 -> 𝕊 ∧ 𝐼 𝕊
forall a b. a -> b -> a ∧ b
:* 𝐼 𝕊
forall a. Null a => a
null

pNewContext  𝕊  Parser t a  Parser t a
pNewContext :: forall t a. 𝕊 -> Parser t a -> Parser t a
pNewContext 𝕊
msg = Parser t a -> Parser t a
forall t a. Parser t a -> Parser t a
pNewExpressionContext (Parser t a -> Parser t a)
-> (Parser t a -> Parser t a) -> Parser t a -> Parser t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕊 -> Parser t a -> Parser t a
forall t a. 𝕊 -> Parser t a -> Parser t a
pNewErrContext 𝕊
msg

pWithContextRendered  Parser t a  Parser t (𝐴 SrcCxt a)
pWithContextRendered :: forall t a. Parser t a -> Parser t (𝐴 SrcCxt a)
pWithContextRendered Parser t a
aM = do
  a
x  Parser t a
aM
  SrcCxt
fc  Parser t SrcCxt
forall t. Parser t SrcCxt
pGetContextRendered
  𝐴 SrcCxt a -> Parser t (𝐴 SrcCxt a)
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return (𝐴 SrcCxt a -> Parser t (𝐴 SrcCxt a))
-> 𝐴 SrcCxt a -> Parser t (𝐴 SrcCxt a)
forall a b. (a -> b) -> a -> b
$ SrcCxt -> a -> 𝐴 SrcCxt a
forall e a. e -> a -> 𝐴 e a
𝐴 SrcCxt
fc a
x

pRender  Formats  Parser t a  Parser t a
pRender :: forall t a. Formats -> Parser t a -> Parser t a
pRender Formats
fmt = (ParserEnv -> ParserEnv) -> Parser t a -> Parser t a
forall (m :: * -> *) r a.
(Monad m, MonadReader r m) =>
(r -> r) -> m a -> m a
mapEnv ((ParserEnv -> ParserEnv) -> Parser t a -> Parser t a)
-> (ParserEnv -> ParserEnv) -> Parser t a -> Parser t a
forall a b. (a -> b) -> a -> b
$ (ParserEnv ⟢ Formats)
-> (Formats -> Formats) -> ParserEnv -> ParserEnv
forall a b. (a ⟢ b) -> (b -> b) -> a -> a
forall (t :: * -> * -> *) a b.
Alter t =>
t a b -> (b -> b) -> a -> a
alter ParserEnv ⟢ Formats
parserEnvRenderFormatL ((Formats -> Formats) -> ParserEnv -> ParserEnv)
-> (Formats -> Formats) -> ParserEnv -> ParserEnv
forall a b. (a -> b) -> a -> b
$ Formats -> Formats -> Formats
forall a. Append a => a -> a -> a
(⧺) Formats
fmt

pAdvance  Parser t (AddBT Loc  ParserToken t)
pAdvance :: forall t. Parser t (AddBT Loc ∨ ParserToken t)
pAdvance = do
  𝑆 (ParserToken t)
pi  (ParserState t ⟢ 𝑆 (ParserToken t)) -> Parser t (𝑆 (ParserToken t))
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ 𝑆 (ParserToken t)
forall t. ParserState t ⟢ 𝑆 (ParserToken t)
parserStateInputL
  AddBT Loc
ep  (ParserState t ⟢ AddBT Loc) -> Parser t (AddBT Loc)
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ AddBT Loc
forall t. ParserState t ⟢ AddBT Loc
parserStateEndPosL
  case 𝑆 (ParserToken t) -> () -> 𝑂 (ParserToken t ∧ 𝑆 (ParserToken t))
forall a. 𝑆 a -> () -> 𝑂 (a ∧ 𝑆 a)
un𝑆 𝑆 (ParserToken t)
pi () of
    𝑂 (ParserToken t ∧ 𝑆 (ParserToken t))
None  (AddBT Loc ∨ ParserToken t) -> Parser t (AddBT Loc ∨ ParserToken t)
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return ((AddBT Loc ∨ ParserToken t)
 -> Parser t (AddBT Loc ∨ ParserToken t))
-> (AddBT Loc ∨ ParserToken t)
-> Parser t (AddBT Loc ∨ ParserToken t)
forall a b. (a -> b) -> a -> b
$ AddBT Loc -> AddBT Loc ∨ ParserToken t
forall a b. a -> a ∨ b
Inl AddBT Loc
ep
    Some (ParserToken t
x 𝔹
sk ParserContext
tc WindowL Doc Doc
ts :* 𝑆 (ParserToken t)
pi')  do
      let ep' :: AddBT Loc
ep' = Loc -> Loc
bumpCol₁ (Loc -> Loc) -> AddBT Loc -> AddBT Loc
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
^$ LocRange -> AddBT Loc
locRangeEnd (LocRange -> AddBT Loc) -> LocRange -> AddBT Loc
forall a b. (a -> b) -> a -> b
$ ParserContext -> LocRange
parserContextLocRange ParserContext
tc
      (ParserState t ⟢ 𝑆 (ParserToken t))
-> 𝑆 (ParserToken t) -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ 𝑆 (ParserToken t)
forall t. ParserState t ⟢ 𝑆 (ParserToken t)
parserStateInputL 𝑆 (ParserToken t)
pi'
      (ParserState t ⟢ AddBT Loc) -> AddBT Loc -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ AddBT Loc
forall t. ParserState t ⟢ AddBT Loc
parserStateEndPosL AddBT Loc
ep'
      if 𝔹
sk
        then do
          ParserContext
pk  (ParserState t ⟢ ParserContext) -> Parser t ParserContext
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateSkipContextL
          ParserContext
pc  (ParserState t ⟢ ParserContext) -> Parser t ParserContext
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateContextL
          if ParserContext -> LocRange
parserContextLocRange ParserContext
pc LocRange -> LocRange -> 𝔹
forall a. Eq a => a -> a -> 𝔹
 LocRange
forall a. Bot a => a
bot
            then (ParserState t ⟢ ParserContext) -> ParserContext -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateSkipContextL (ParserContext -> Parser t ()) -> ParserContext -> Parser t ()
forall a b. (a -> b) -> a -> b
$ ParserContext
pk ParserContext -> ParserContext -> ParserContext
forall a. Append a => a -> a -> a
 ParserContext
tc
            else (ParserState t ⟢ ParserContext) -> ParserContext -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateContextL (ParserContext -> Parser t ()) -> ParserContext -> Parser t ()
forall a b. (a -> b) -> a -> b
$ ParserContext
pc ParserContext -> ParserContext -> ParserContext
forall a. Append a => a -> a -> a
 ParserContext
tc
          Parser t (AddBT Loc ∨ ParserToken t)
forall t. Parser t (AddBT Loc ∨ ParserToken t)
pAdvance
        else do
          Formats
fmt  (ParserEnv ⟢ Formats) -> Parser t Formats
forall r'. (ParserEnv ⟢ r') -> Parser t r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL ParserEnv ⟢ Formats
parserEnvRenderFormatL
          (AddBT Loc ∨ ParserToken t) -> Parser t (AddBT Loc ∨ ParserToken t)
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return ((AddBT Loc ∨ ParserToken t)
 -> Parser t (AddBT Loc ∨ ParserToken t))
-> (AddBT Loc ∨ ParserToken t)
-> Parser t (AddBT Loc ∨ ParserToken t)
forall a b. (a -> b) -> a -> b
$ ParserToken t -> AddBT Loc ∨ ParserToken t
forall a b. b -> a ∨ b
Inr (ParserToken t -> AddBT Loc ∨ ParserToken t)
-> ParserToken t -> AddBT Loc ∨ ParserToken t
forall a b. (a -> b) -> a -> b
$ t -> 𝔹 -> ParserContext -> WindowL Doc Doc -> ParserToken t
forall t.
t -> 𝔹 -> ParserContext -> WindowL Doc Doc -> ParserToken t
ParserToken t
x 𝔹
sk (Formats -> ParserContext -> ParserContext
formatParserContext Formats
fmt ParserContext
tc) WindowL Doc Doc
ts

pPluck  Parser t (ParserToken t)
pPluck :: forall t. Parser t (ParserToken t)
pPluck = do
  AddBT Loc ∨ ParserToken t
tM  Parser t (AddBT Loc ∨ ParserToken t)
forall t. Parser t (AddBT Loc ∨ ParserToken t)
pAdvance
  case AddBT Loc ∨ ParserToken t
tM of
    Inl AddBT Loc
l  {- pErr "more input" $ -} ParserContext -> WindowL Doc Doc -> Parser t (ParserToken t)
forall t a. ParserContext -> WindowL Doc Doc -> Parser t a
pFail (AddBT Loc -> ParserContext
eofContext AddBT Loc
l) WindowL Doc Doc
forall a. Null a => a
null
    Inr ParserToken t
t  ParserToken t -> Parser t (ParserToken t)
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return ParserToken t
t

pRecord  ParserToken t  Parser t ()
pRecord :: forall t. ParserToken t -> Parser t ()
pRecord ParserToken t
t = do
  (ParserState t ⟢ ParserContext)
-> (ParserContext -> ParserContext) -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> (a -> a) -> m ()
modifyL ParserState t ⟢ ParserContext
forall t. ParserState t ⟢ ParserContext
parserStateContextL ((ParserContext -> ParserContext) -> Parser t ())
-> (ParserContext -> ParserContext) -> Parser t ()
forall a b. (a -> b) -> a -> b
$ \ ParserContext
c  ParserContext
c ParserContext -> ParserContext -> ParserContext
forall a. Append a => a -> a -> a
 ParserToken t -> ParserContext
forall t. ParserToken t -> ParserContext
parserTokenContext ParserToken t
t
  (ParserState t ⟢ WindowL Doc Doc) -> WindowL Doc Doc -> Parser t ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL ParserState t ⟢ WindowL Doc Doc
forall t. ParserState t ⟢ WindowL Doc Doc
parserStateSuffixL (WindowL Doc Doc -> Parser t ()) -> WindowL Doc Doc -> Parser t ()
forall a b. (a -> b) -> a -> b
$ ParserToken t -> WindowL Doc Doc
forall t. ParserToken t -> WindowL Doc Doc
parserTokenSuffix ParserToken t
t 

pEnd  Parser t ()
pEnd :: forall t. Parser t ()
pEnd = do
  AddBT Loc ∨ ParserToken t
tM  Parser t (AddBT Loc ∨ ParserToken t)
forall t. Parser t (AddBT Loc ∨ ParserToken t)
pAdvance
  case AddBT Loc ∨ ParserToken t
tM of
    Inl AddBT Loc
_  () -> Parser t ()
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return ()
    Inr ParserToken t
t  𝕊 -> Parser t () -> Parser t ()
forall t a. 𝕊 -> Parser t a -> Parser t a
pNewContext 𝕊
"end of input" (Parser t () -> Parser t ()) -> Parser t () -> Parser t ()
forall a b. (a -> b) -> a -> b
$ ParserContext -> WindowL Doc Doc -> Parser t ()
forall t a. ParserContext -> WindowL Doc Doc -> Parser t a
pFail (ParserToken t -> ParserContext
forall t. ParserToken t -> ParserContext
parserTokenContext ParserToken t
t) (ParserToken t -> WindowL Doc Doc
forall t. ParserToken t -> WindowL Doc Doc
parserTokenSuffix ParserToken t
t)

----------------
-- High Level --
----------------

pFinal  Parser t a  Parser t a
pFinal :: forall t a. Parser t a -> Parser t a
pFinal Parser t a
aM = do
  a
a  Parser t a
aM
  Parser t ()
forall t. Parser t ()
pEnd
  a -> Parser t a
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return a
a

pAny  Parser t t
pAny :: forall t. Parser t t
pAny = do
  ParserToken t
t  Parser t (ParserToken t)
forall t. Parser t (ParserToken t)
pPluck
  ParserToken t -> Parser t ()
forall t. ParserToken t -> Parser t ()
pRecord ParserToken t
t
  t -> Parser t t
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return (t -> Parser t t) -> t -> Parser t t
forall a b. (a -> b) -> a -> b
$ ParserToken t -> t
forall t. ParserToken t -> t
parserTokenValue ParserToken t
t

pShaped  {- 𝕊 → -} (t  𝑂 a)  Parser t a
pShaped :: forall t a. (t -> 𝑂 a) -> Parser t a
pShaped {- msg -} t -> 𝑂 a
sh = do
  ParserToken t
t  Parser t (ParserToken t)
forall t. Parser t (ParserToken t)
pPluck
  case t -> 𝑂 a
sh (t -> 𝑂 a) -> t -> 𝑂 a
forall a b. (a -> b) -> a -> b
$ ParserToken t -> t
forall t. ParserToken t -> t
parserTokenValue ParserToken t
t of
    𝑂 a
None  {- pErr msg $ -} ParserContext -> WindowL Doc Doc -> Parser t a
forall t a. ParserContext -> WindowL Doc Doc -> Parser t a
pFail (ParserToken t -> ParserContext
forall t. ParserToken t -> ParserContext
parserTokenContext ParserToken t
t) (ParserToken t -> WindowL Doc Doc
forall t. ParserToken t -> WindowL Doc Doc
parserTokenSuffix ParserToken t
t)
    Some a
x  do
      ParserToken t -> Parser t ()
forall t. ParserToken t -> Parser t ()
pRecord ParserToken t
t
      a -> Parser t a
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return a
x

pSatisfies  {- 𝕊 → -} (t  𝔹)  Parser t t
pSatisfies :: forall t. (t -> 𝔹) -> Parser t t
pSatisfies {- msg -} t -> 𝔹
p = (t -> 𝑂 t) -> Parser t t
forall t a. (t -> 𝑂 a) -> Parser t a
pShaped {- msg -} ((t -> 𝑂 t) -> Parser t t) -> (t -> 𝑂 t) -> Parser t t
forall a b. (a -> b) -> a -> b
$ \ t
x  case t -> 𝔹
p t
x of
  𝔹
True  t -> 𝑂 t
forall a. a -> 𝑂 a
Some t
x 
  𝔹
False  𝑂 t
forall a. 𝑂 a
None

pDie  {- 𝕊 → -} Parser t a
pDie :: forall t a. Parser t a
pDie {- msg -} = do
  Parser t t -> Parser t ()
forall (m :: * -> *) a. Functor m => m a -> m ()
void (Parser t t -> Parser t ()) -> Parser t t -> Parser t ()
forall a b. (a -> b) -> a -> b
$ (t -> 𝔹) -> Parser t t
forall t. (t -> 𝔹) -> Parser t t
pSatisfies {- msg -} ((t -> 𝔹) -> Parser t t) -> (t -> 𝔹) -> Parser t t
forall a b. (a -> b) -> a -> b
$ 𝔹 -> t -> 𝔹
forall a b. a -> b -> a
const 𝔹
False
  Parser t a
forall a. Parser t a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort

pToken  (Eq t {- ,Pretty t -})  t  Parser t t
pToken :: forall t. Eq t => t -> Parser t t
pToken t
l = (t -> 𝔹) -> Parser t t
forall t. (t -> 𝔹) -> Parser t t
pSatisfies {- (ppshow l) -} ((t -> 𝔹) -> Parser t t) -> (t -> 𝔹) -> Parser t t
forall a b. (a -> b) -> a -> b
$ t -> t -> 𝔹
forall a. Eq a => a -> a -> 𝔹
(≡) t
l

pOptional  Parser t a  Parser t (𝑂 a)
pOptional :: forall t a. Parser t a -> Parser t (𝑂 a)
pOptional Parser t a
p = [Parser t (𝑂 a)] -> Parser t (𝑂 a)
forall (m :: * -> *) a t.
(Monad m, MonadFail m, ToIter (m a) t) =>
t -> m a
tries [(a -> 𝑂 a) -> Parser t a -> Parser t (𝑂 a)
forall a b. (a -> b) -> Parser t a -> Parser t b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map a -> 𝑂 a
forall a. a -> 𝑂 a
Some Parser t a
p,𝑂 a -> Parser t (𝑂 a)
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return 𝑂 a
forall a. 𝑂 a
None]

pMany  Parser t a  Parser t (𝐿 a)
pMany :: forall t a. Parser t a -> Parser t (𝐿 a)
pMany Parser t a
xM = [Parser t (𝐿 a)] -> Parser t (𝐿 a)
forall (m :: * -> *) a t.
(Monad m, MonadFail m, ToIter (m a) t) =>
t -> m a
tries
  [ Parser t a -> Parser t (𝐿 a)
forall t a. Parser t a -> Parser t (𝐿 a)
pOneOrMore Parser t a
xM
  , 𝐿 a -> Parser t (𝐿 a)
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return 𝐿 a
forall a. 𝐿 a
Nil
  ]

pOneOrMore  Parser t a  Parser t (𝐿 a)
pOneOrMore :: forall t a. Parser t a -> Parser t (𝐿 a)
pOneOrMore Parser t a
xM = do
  a
x  Parser t a
xM
  𝐿 a
xs  Parser t a -> Parser t (𝐿 a)
forall t a. Parser t a -> Parser t (𝐿 a)
pMany Parser t a
xM
  𝐿 a -> Parser t (𝐿 a)
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return (𝐿 a -> Parser t (𝐿 a)) -> 𝐿 a -> Parser t (𝐿 a)
forall a b. (a -> b) -> a -> b
$ a
xa -> 𝐿 a -> 𝐿 a
forall a. a -> 𝐿 a -> 𝐿 a
:&𝐿 a
xs

pManySepBy  Parser t ()  Parser t a  Parser t (𝐿 a)
pManySepBy :: forall t a. Parser t () -> Parser t a -> Parser t (𝐿 a)
pManySepBy Parser t ()
sepM Parser t a
xM = [Parser t (𝐿 a)] -> Parser t (𝐿 a)
forall (m :: * -> *) a t.
(Monad m, MonadFail m, ToIter (m a) t) =>
t -> m a
tries
  [ Parser t () -> Parser t a -> Parser t (𝐿 a)
forall t a. Parser t () -> Parser t a -> Parser t (𝐿 a)
pOneOrMoreSepBy Parser t ()
sepM Parser t a
xM
  , 𝐿 a -> Parser t (𝐿 a)
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return 𝐿 a
forall a. 𝐿 a
Nil
  ]

pOneOrMoreSepBy  Parser t ()  Parser t a  Parser t (𝐿 a)
pOneOrMoreSepBy :: forall t a. Parser t () -> Parser t a -> Parser t (𝐿 a)
pOneOrMoreSepBy Parser t ()
sepM Parser t a
xM = do
  a
x  Parser t a
xM
  𝐿 a
xs  ((() ∧ a) -> a) -> 𝐿 (() ∧ a) -> 𝐿 a
forall a b. (a -> b) -> 𝐿 a -> 𝐿 b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map (() ∧ a) -> a
forall a b. (a ∧ b) -> b
snd (𝐿 (() ∧ a) -> 𝐿 a) -> Parser t (𝐿 (() ∧ a)) -> Parser t (𝐿 a)
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
^$ Parser t (() ∧ a) -> Parser t (𝐿 (() ∧ a))
forall t a. Parser t a -> Parser t (𝐿 a)
pMany (Parser t (() ∧ a) -> Parser t (𝐿 (() ∧ a)))
-> Parser t (() ∧ a) -> Parser t (𝐿 (() ∧ a))
forall a b. (a -> b) -> a -> b
$ Parser t ()
sepM Parser t () -> Parser t a -> Parser t (() ∧ a)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m (a ∧ b)
 Parser t a
xM
  𝐿 a -> Parser t (𝐿 a)
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return (𝐿 a -> Parser t (𝐿 a)) -> 𝐿 a -> Parser t (𝐿 a)
forall a b. (a -> b) -> a -> b
$ a
x a -> 𝐿 a -> 𝐿 a
forall a. a -> 𝐿 a -> 𝐿 a
:& 𝐿 a
xs

------------------------
-- High-level Helpers --
------------------------

pWord   s t. (Eq t,s  𝐼 t)  s  Parser t s
pWord :: forall s t. (Eq t, s ⇄ 𝐼 t) => s -> Parser t s
pWord s
s = 𝐼 t -> s
forall a b. (a ⇄ b) => b -> a
isofr (𝐼 t -> s) -> Parser t (𝐼 t) -> Parser t s
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
^$ (t -> Parser t t) -> 𝐼 t -> Parser t (𝐼 t)
forall (t :: * -> *) (m :: * -> *) a b.
(FunctorM t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> 𝐼 a -> m (𝐼 b)
mapM t -> Parser t t
forall t. Eq t => t -> Parser t t
pToken (s -> 𝐼 t
forall a b. (a ⇄ b) => a -> b
isoto s
s  𝐼 t)