module UVMHS.Lib.Parser.CParser where

import UVMHS.Core

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

import UVMHS.Lib.Parser.ParserContext
import UVMHS.Lib.Parser.Core
import UVMHS.Lib.Parser.ParserError
import UVMHS.Lib.Parser.ParserInput
import UVMHS.Lib.Parser.Regex

data CParser t a = CParser
  { forall t a. CParser t a -> t ⇰ CParser t a
cParserNext  t  CParser t a
  , forall t a. CParser t a -> Parser t a
cParserFallback  Parser t a
  }

onCParser  (Parser t a  Parser t a)  CParser t a  CParser t a
onCParser :: forall t a.
(Parser t a -> Parser t a) -> CParser t a -> CParser t a
onCParser Parser t a -> Parser t a
f (CParser t ⇰ CParser t a
n Parser t a
b) = (t ⇰ CParser t a) -> Parser t a -> CParser t a
forall t a. (t ⇰ CParser t a) -> Parser t a -> CParser t a
CParser ((CParser t a -> CParser t a)
-> (t ⇰ CParser t a) -> t ⇰ CParser t a
forall a b. (a -> b) -> (t ⇰ a) -> t ⇰ b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ((Parser t a -> Parser t a) -> CParser t a -> CParser t a
forall t a.
(Parser t a -> Parser t a) -> CParser t a -> CParser t a
onCParser Parser t a -> Parser t a
f) t ⇰ CParser t a
n) (Parser t a -> CParser t a) -> Parser t a -> CParser t a
forall a b. (a -> b) -> a -> b
$ Parser t a -> Parser t a
f Parser t a
b

toCParser  Parser t a  CParser t a
toCParser :: forall t a. Parser t a -> CParser t a
toCParser Parser t a
p = (t ⇰ CParser t a) -> Parser t a -> CParser t a
forall t a. (t ⇰ CParser t a) -> Parser t a -> CParser t a
CParser t ⇰ CParser t a
forall k a. k ⇰ a
dø𝐷 Parser t a
p

frCParser  (Ord t)  CParser t a  Parser t a
frCParser :: forall t a. Ord t => CParser t a -> Parser t a
frCParser (CParser t ⇰ CParser t a
n Parser t a
b) 
  | (t ⇰ CParser t a) -> 𝔹
forall a t. ToIter a t => t -> 𝔹
isEmpty t ⇰ CParser t a
n = Parser t a
b
  | 𝔹
otherwise = [Parser t a] -> Parser t a
forall (m :: * -> *) a t.
(Monad m, MonadFail m, ToIter (m a) t) =>
t -> m a
tries
      [ do ParserToken t
t  Parser t (ParserToken t)
forall t. Parser t (ParserToken t)
pPluck
           case t ⇰ CParser t a
n (t ⇰ CParser t a) -> t -> 𝑂 (CParser t a)
forall k v t. Lookup k v t => t -> k -> 𝑂 v
⋕? ParserToken t -> t
forall t. ParserToken t -> t
parserTokenValue ParserToken t
t of
             Some CParser t a
cp  do
               ParserToken t -> Parser t ()
forall t. ParserToken t -> Parser t ()
pRecord ParserToken t
t
               CParser t a -> Parser t a
forall t a. Ord t => CParser t a -> Parser t a
frCParser CParser t a
cp
             𝑂 (CParser t a)
None  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)
      , Parser t a
b
      ]

instance Return (CParser t) where 
  return   a. a  CParser t a
  return :: forall a. a -> CParser t a
return a
x = Parser t a -> CParser t a
forall t a. Parser t a -> CParser t a
toCParser (Parser t a -> CParser t a) -> Parser t a -> CParser t a
forall a b. (a -> b) -> a -> b
$ a -> Parser t a
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return a
x
instance (Ord t)  Bind (CParser t) where
  (≫=)   a b. CParser t a  (a  CParser t b)  CParser t b
  CParser t ⇰ CParser t a
n Parser t a
b ≫= :: forall a b. CParser t a -> (a -> CParser t b) -> CParser t b
≫= a -> CParser t b
k = 
    (t ⇰ CParser t b) -> Parser t b -> CParser t b
forall t a. (t ⇰ CParser t a) -> Parser t a -> CParser t a
CParser ((CParser t a -> CParser t b)
-> (t ⇰ CParser t a) -> t ⇰ CParser t b
forall a b. (a -> b) -> (t ⇰ a) -> t ⇰ b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ((a -> CParser t b) -> CParser t a -> CParser t b
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
extend a -> CParser t b
k) t ⇰ CParser t a
n) 
            (Parser 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
forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
≫= CParser t b -> Parser t b
forall t a. Ord t => CParser t a -> Parser t a
frCParser (CParser t b -> Parser t b)
-> (a -> CParser t b) -> a -> Parser t b
forall b c a. (b -> c) -> (a -> b) -> a -> c
 a -> CParser t b
k) 
instance (Ord t)  Functor (CParser t) where map :: forall a b. (a -> b) -> CParser t a -> CParser t b
map = (a -> b) -> CParser t a -> CParser t b
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
mmap
instance (Ord t)  Monad (CParser t)

instance (Ord t)  MonadFail (CParser t) where
  abort   a. CParser t a
  abort :: forall a. CParser t a
abort = Parser t a -> CParser t a
forall t a. Parser t a -> CParser t a
toCParser Parser t a
forall a. Parser t a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort
  (⎅)   a. CParser t a  CParser t a  CParser t a
  CParser t a
cp₁ ⎅ :: forall a. CParser t a -> CParser t a -> CParser t a
 CParser t a
cp₂ = Parser t a -> CParser t a
forall t a. Parser t a -> CParser t a
toCParser (Parser t a -> CParser t a) -> Parser t a -> CParser t a
forall a b. (a -> b) -> a -> b
$ CParser t a -> Parser t a
forall t a. Ord t => CParser t a -> Parser t a
frCParser CParser t a
cp₁ Parser t a -> Parser t a -> Parser t a
forall a. Parser t a -> Parser t a -> Parser t a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a -> m a -> m a
 CParser t a -> Parser t a
forall t a. Ord t => CParser t a -> Parser t a
frCParser CParser t a
cp₂

instance Null (CParser t a) where
  null  CParser t a
  null :: CParser t a
null = Parser t a -> CParser t a
forall t a. Parser t a -> CParser t a
toCParser Parser t a
forall a. Parser t a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort
instance (Ord t)  Append (CParser t a) where
  (⧺)  CParser t a  CParser t a  CParser t a
  CParser t ⇰ CParser t a
n₁ Parser t a
b₁ ⧺ :: CParser t a -> CParser t a -> CParser t a
 CParser t ⇰ CParser t a
n₂ Parser t a
b₂ = (t ⇰ CParser t a) -> Parser t a -> CParser t a
forall t a. (t ⇰ CParser t a) -> Parser t a -> CParser t a
CParser ((CParser t a -> CParser t a -> CParser t a)
-> (t ⇰ CParser t a) -> (t ⇰ CParser t a) -> t ⇰ CParser t a
forall a. (a -> a -> a) -> (t ⇰ a) -> (t ⇰ a) -> t ⇰ a
forall k s (d :: * -> *) a.
Dict k s d =>
(a -> a -> a) -> d a -> d a -> d a
dunionBy CParser t a -> CParser t a -> CParser t a
forall a. Append a => a -> a -> a
(⧺) t ⇰ CParser t a
n₁ t ⇰ CParser t a
n₂) (Parser t a
b₁ Parser t a -> Parser t a -> Parser t a
forall a. Parser t a -> Parser t a -> Parser t a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a -> m a -> m a
 Parser t a
b₂)
instance (Ord t)  Monoid (CParser t a)

instance Eps (CParser t ()) where
  eps  CParser t ()
  eps :: CParser t ()
eps = Parser t () -> CParser t ()
forall t a. Parser t a -> CParser t a
toCParser (Parser t () -> CParser t ()) -> Parser t () -> CParser t ()
forall a b. (a -> b) -> a -> b
$ () -> Parser t ()
forall a. a -> Parser t a
forall (m :: * -> *) a. Return m => a -> m a
return ()
instance (Ord t)  Seq (CParser t ()) where
  (▷)  CParser t ()  CParser t ()  CParser t ()
  CParser t ()
cp₁ ▷ :: CParser t () -> CParser t () -> CParser t ()
 CParser t ()
cp₂ = (Parser t () -> Parser t ()) -> CParser t () -> CParser t ()
forall t a.
(Parser t a -> Parser t a) -> CParser t a -> CParser t a
onCParser (\ Parser t ()
p  Parser t ()
p Parser t () -> Parser t () -> Parser t ()
forall (m :: * -> *) a b. Bind m => m a -> m b -> m b
 CParser t () -> Parser t ()
forall t a. Ord t => CParser t a -> Parser t a
frCParser CParser t ()
cp₂) CParser t ()
cp₁
instance (Ord t)  Seqoid (CParser t ())

cpRender  (Ord t)  Formats  CParser t a  CParser t a
cpRender :: forall t a. Ord t => Formats -> CParser t a -> CParser t a
cpRender Formats
fm = Parser t a -> CParser t a
forall t a. Parser t a -> CParser t a
toCParser (Parser t a -> CParser t a)
-> (Parser t a -> Parser t a) -> Parser t a -> CParser t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 Formats -> Parser t a -> Parser t a
forall t a. Formats -> Parser t a -> Parser t a
pRender Formats
fm (Parser t a -> CParser t a)
-> (CParser t a -> Parser t a) -> CParser t a -> CParser t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 CParser t a -> Parser t a
forall t a. Ord t => CParser t a -> Parser t a
frCParser

cpErr  (Ord t)  𝕊  CParser t a  CParser t a
cpErr :: forall t a. Ord t => 𝕊 -> CParser t a -> CParser t a
cpErr 𝕊
s = Parser t a -> CParser t a
forall t a. Parser t a -> CParser t a
toCParser (Parser t a -> CParser t a)
-> (Parser t a -> Parser t a) -> Parser t a -> CParser 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
pErr 𝕊
s (Parser t a -> CParser t a)
-> (CParser t a -> Parser t a) -> CParser t a -> CParser t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 CParser t a -> Parser t a
forall t a. Ord t => CParser t a -> Parser t a
frCParser

cpToken  (Ord t)  t  CParser t t
cpToken :: forall t. Ord t => t -> CParser t t
cpToken t
t = (t ⇰ CParser t t) -> Parser t t -> CParser t t
forall t a. (t ⇰ CParser t a) -> Parser t a -> CParser t a
CParser (t
t t -> CParser t t -> t ⇰ CParser t t
forall a. t -> a -> t ⇰ a
forall k s (d :: * -> *) a. Dict k s d => k -> a -> d a
 t -> CParser t t
forall a. a -> CParser t a
forall (m :: * -> *) a. Return m => a -> m a
return t
t) Parser t t
forall a. Parser t a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort

cpFinal  (Ord t)  CParser t a  CParser t a
cpFinal :: forall t a. Ord t => CParser t a -> CParser t a
cpFinal = Parser t a -> CParser t a
forall t a. Parser t a -> CParser t a
toCParser (Parser t a -> CParser t a)
-> (Parser t a -> Parser t a) -> Parser t a -> CParser 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
pFinal (Parser t a -> CParser t a)
-> (CParser t a -> Parser t a) -> CParser t a -> CParser t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 CParser t a -> Parser t a
forall t a. Ord t => CParser t a -> Parser t a
frCParser

cpShaped  (t  𝑂 a)  CParser t a
cpShaped :: forall t a. (t -> 𝑂 a) -> CParser t a
cpShaped = Parser t a -> CParser t a
forall t a. Parser t a -> CParser t a
toCParser (Parser t a -> CParser t a)
-> ((t -> 𝑂 a) -> Parser t a) -> (t -> 𝑂 a) -> CParser t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 (t -> 𝑂 a) -> Parser t a
forall t a. (t -> 𝑂 a) -> Parser t a
pShaped

cpSatisfies  (t  𝔹)  CParser t t
cpSatisfies :: forall t. (t -> 𝔹) -> CParser t t
cpSatisfies = Parser t t -> CParser t t
forall t a. Parser t a -> CParser t a
toCParser (Parser t t -> CParser t t)
-> ((t -> 𝔹) -> Parser t t) -> (t -> 𝔹) -> CParser t t
forall b c a. (b -> c) -> (a -> b) -> a -> c
 (t -> 𝔹) -> Parser t t
forall t. (t -> 𝔹) -> Parser t t
pSatisfies 

cpAny  CParser t t
cpAny :: forall t. CParser t t
cpAny = Parser t t -> CParser t t
forall t a. Parser t a -> CParser t a
toCParser Parser t t
forall t. Parser t t
pAny

cpWord   s t. (Eq t,s  𝐼 t)  s  CParser t s
cpWord :: forall s t. (Eq t, s ⇄ 𝐼 t) => s -> CParser t s
cpWord = Parser t s -> CParser t s
forall t a. Parser t a -> CParser t a
toCParser (Parser t s -> CParser t s)
-> (s -> Parser t s) -> s -> CParser t s
forall b c a. (b -> c) -> (a -> b) -> a -> c
 s -> Parser t s
forall s t. (Eq t, s ⇄ 𝐼 t) => s -> Parser t s
pWord

cpOptional  (Ord t)  CParser t a  CParser t (𝑂 a)
cpOptional :: forall t a. Ord t => CParser t a -> CParser t (𝑂 a)
cpOptional = Parser t (𝑂 a) -> CParser t (𝑂 a)
forall t a. Parser t a -> CParser t a
toCParser (Parser t (𝑂 a) -> CParser t (𝑂 a))
-> (Parser t a -> Parser t (𝑂 a)) -> Parser t a -> CParser 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)
pOptional (Parser t a -> CParser t (𝑂 a))
-> (CParser t a -> Parser t a) -> CParser t a -> CParser t (𝑂 a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 CParser t a -> Parser t a
forall t a. Ord t => CParser t a -> Parser t a
frCParser

cpMany  (Ord t)  CParser t a  CParser t (𝐿 a)
cpMany :: forall t a. Ord t => CParser t a -> CParser t (𝐿 a)
cpMany CParser t a
xM = [CParser t (𝐿 a)] -> CParser t (𝐿 a)
forall (m :: * -> *) a t.
(Monad m, MonadFail m, ToIter (m a) t) =>
t -> m a
tries
  [ CParser t a -> CParser t (𝐿 a)
forall t a. Ord t => CParser t a -> CParser t (𝐿 a)
cpOneOrMore CParser t a
xM
  , 𝐿 a -> CParser t (𝐿 a)
forall a. a -> CParser t a
forall (m :: * -> *) a. Return m => a -> m a
return 𝐿 a
forall a. 𝐿 a
Nil
  ]

cpOneOrMore  (Ord t)  CParser t a  CParser t (𝐿 a)
cpOneOrMore :: forall t a. Ord t => CParser t a -> CParser t (𝐿 a)
cpOneOrMore CParser t a
xM = do
  a
x  CParser t a
xM
  𝐿 a
xs  CParser t a -> CParser t (𝐿 a)
forall t a. Ord t => CParser t a -> CParser t (𝐿 a)
cpMany CParser t a
xM
  𝐿 a -> CParser t (𝐿 a)
forall a. a -> CParser t a
forall (m :: * -> *) a. Return m => a -> m a
return (𝐿 a -> CParser t (𝐿 a)) -> 𝐿 a -> CParser t (𝐿 a)
forall a b. (a -> b) -> a -> b
$ a
xa -> 𝐿 a -> 𝐿 a
forall a. a -> 𝐿 a -> 𝐿 a
:&𝐿 a
xs

cpManySepBy  (Ord t)  CParser t ()  CParser t a  CParser t (𝐿 a)
cpManySepBy :: forall t a. Ord t => CParser t () -> CParser t a -> CParser t (𝐿 a)
cpManySepBy CParser t ()
sepM CParser t a
xM = [CParser t (𝐿 a)] -> CParser t (𝐿 a)
forall (m :: * -> *) a t.
(Monad m, MonadFail m, ToIter (m a) t) =>
t -> m a
tries
  [ CParser t () -> CParser t a -> CParser t (𝐿 a)
forall t a. Ord t => CParser t () -> CParser t a -> CParser t (𝐿 a)
cpOneOrMoreSepBy CParser t ()
sepM CParser t a
xM
  , 𝐿 a -> CParser t (𝐿 a)
forall a. a -> CParser t a
forall (m :: * -> *) a. Return m => a -> m a
return 𝐿 a
forall a. 𝐿 a
Nil
  ]

cpOneOrMoreSepBy  (Ord t)  CParser t ()  CParser t a  CParser t (𝐿 a)
cpOneOrMoreSepBy :: forall t a. Ord t => CParser t () -> CParser t a -> CParser t (𝐿 a)
cpOneOrMoreSepBy CParser t ()
sepM CParser t a
xM = do
  a
x  CParser 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) -> CParser t (𝐿 (() ∧ a)) -> CParser t (𝐿 a)
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
^$ CParser t (() ∧ a) -> CParser t (𝐿 (() ∧ a))
forall t a. Ord t => CParser t a -> CParser t (𝐿 a)
cpMany (CParser t (() ∧ a) -> CParser t (𝐿 (() ∧ a)))
-> CParser t (() ∧ a) -> CParser t (𝐿 (() ∧ a))
forall a b. (a -> b) -> a -> b
$ CParser t ()
sepM CParser t () -> CParser t a -> CParser t (() ∧ a)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m (a ∧ b)
 CParser t a
xM
  𝐿 a -> CParser t (𝐿 a)
forall a. a -> CParser t a
forall (m :: * -> *) a. Return m => a -> m a
return (𝐿 a -> CParser t (𝐿 a)) -> 𝐿 a -> CParser t (𝐿 a)
forall a b. (a -> b) -> a -> b
$ a
x a -> 𝐿 a -> 𝐿 a
forall a. a -> 𝐿 a -> 𝐿 a
:& 𝐿 a
xs

----------------------------
-- Basic Language Parsing --
----------------------------

cpSyntax  𝕊  CParser TokenBasic TokenBasic
cpSyntax :: 𝕊 -> CParser TokenBasic TokenBasic
cpSyntax = TokenBasic -> CParser TokenBasic TokenBasic
forall t. Ord t => t -> CParser t t
cpToken (TokenBasic -> CParser TokenBasic TokenBasic)
-> (𝕊 -> TokenBasic) -> 𝕊 -> CParser TokenBasic TokenBasic
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕊 -> TokenBasic
SyntaxTBasic

cpNatural  CParser TokenBasic 
cpNatural :: CParser TokenBasic ℕ
cpNatural = (TokenBasic -> 𝑂 ℕ) -> CParser TokenBasic ℕ
forall t a. (t -> 𝑂 a) -> CParser t a
cpShaped ((TokenBasic -> 𝑂 ℕ) -> CParser TokenBasic ℕ)
-> (TokenBasic -> 𝑂 ℕ) -> CParser TokenBasic ℕ
forall a b. (a -> b) -> a -> b
$ (TokenBasic ⌲ ℕ) -> TokenBasic -> 𝑂 ℕ
forall a b. (a ⌲ b) -> a -> 𝑂 b
view TokenBasic ⌲ ℕ
naturalTBasicL

cpInteger  CParser TokenBasic 
cpInteger :: CParser TokenBasic ℤ
cpInteger = (TokenBasic -> 𝑂 ℤ) -> CParser TokenBasic ℤ
forall t a. (t -> 𝑂 a) -> CParser t a
cpShaped ((TokenBasic -> 𝑂 ℤ) -> CParser TokenBasic ℤ)
-> (TokenBasic -> 𝑂 ℤ) -> CParser TokenBasic ℤ
forall a b. (a -> b) -> a -> b
$ (TokenBasic ⌲ ℤ) -> TokenBasic -> 𝑂 ℤ
forall a b. (a ⌲ b) -> a -> 𝑂 b
view TokenBasic ⌲ ℤ
integerTBasicL

cpDouble  CParser TokenBasic 𝔻
cpDouble :: CParser TokenBasic 𝔻
cpDouble = (TokenBasic -> 𝑂 𝔻) -> CParser TokenBasic 𝔻
forall t a. (t -> 𝑂 a) -> CParser t a
cpShaped ((TokenBasic -> 𝑂 𝔻) -> CParser TokenBasic 𝔻)
-> (TokenBasic -> 𝑂 𝔻) -> CParser TokenBasic 𝔻
forall a b. (a -> b) -> a -> b
$ (TokenBasic ⌲ 𝔻) -> TokenBasic -> 𝑂 𝔻
forall a b. (a ⌲ b) -> a -> 𝑂 b
view TokenBasic ⌲ 𝔻
doubleTBasicL

cpString  CParser TokenBasic 𝕊
cpString :: CParser TokenBasic 𝕊
cpString = (TokenBasic -> 𝑂 𝕊) -> CParser TokenBasic 𝕊
forall t a. (t -> 𝑂 a) -> CParser t a
cpShaped ((TokenBasic -> 𝑂 𝕊) -> CParser TokenBasic 𝕊)
-> (TokenBasic -> 𝑂 𝕊) -> CParser TokenBasic 𝕊
forall a b. (a -> b) -> a -> b
$ (TokenBasic ⌲ 𝕊) -> TokenBasic -> 𝑂 𝕊
forall a b. (a ⌲ b) -> a -> 𝑂 b
view TokenBasic ⌲ 𝕊
stringTBasicL

cpChar  CParser TokenBasic 
cpChar :: CParser TokenBasic ℂ
cpChar = (TokenBasic -> 𝑂 ℂ) -> CParser TokenBasic ℂ
forall t a. (t -> 𝑂 a) -> CParser t a
cpShaped ((TokenBasic -> 𝑂 ℂ) -> CParser TokenBasic ℂ)
-> (TokenBasic -> 𝑂 ℂ) -> CParser TokenBasic ℂ
forall a b. (a -> b) -> a -> b
$ (TokenBasic ⌲ ℂ) -> TokenBasic -> 𝑂 ℂ
forall a b. (a ⌲ b) -> a -> 𝑂 b
view TokenBasic ⌲ ℂ
charTBasicL

cpSyntaxWS  𝕊  CParser TokenWSBasic TokenWSBasic
cpSyntaxWS :: 𝕊 -> CParser TokenWSBasic TokenWSBasic
cpSyntaxWS = TokenWSBasic -> CParser TokenWSBasic TokenWSBasic
forall t. Ord t => t -> CParser t t
cpToken (TokenWSBasic -> CParser TokenWSBasic TokenWSBasic)
-> (𝕊 -> TokenWSBasic) -> 𝕊 -> CParser TokenWSBasic TokenWSBasic
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕊 -> TokenWSBasic
SyntaxTWSBasic

cpNaturalWS  CParser TokenWSBasic 
cpNaturalWS :: CParser TokenWSBasic ℕ
cpNaturalWS = (TokenWSBasic -> 𝑂 ℕ) -> CParser TokenWSBasic ℕ
forall t a. (t -> 𝑂 a) -> CParser t a
cpShaped ((TokenWSBasic -> 𝑂 ℕ) -> CParser TokenWSBasic ℕ)
-> (TokenWSBasic -> 𝑂 ℕ) -> CParser TokenWSBasic ℕ
forall a b. (a -> b) -> a -> b
$ (TokenWSBasic ⌲ ℕ) -> TokenWSBasic -> 𝑂 ℕ
forall a b. (a ⌲ b) -> a -> 𝑂 b
view TokenWSBasic ⌲ ℕ
naturalTWSBasicL

cpIntegerWS  CParser TokenWSBasic 
cpIntegerWS :: CParser TokenWSBasic ℤ
cpIntegerWS = (TokenWSBasic -> 𝑂 ℤ) -> CParser TokenWSBasic ℤ
forall t a. (t -> 𝑂 a) -> CParser t a
cpShaped ((TokenWSBasic -> 𝑂 ℤ) -> CParser TokenWSBasic ℤ)
-> (TokenWSBasic -> 𝑂 ℤ) -> CParser TokenWSBasic ℤ
forall a b. (a -> b) -> a -> b
$ (TokenWSBasic ⌲ ℤ) -> TokenWSBasic -> 𝑂 ℤ
forall a b. (a ⌲ b) -> a -> 𝑂 b
view TokenWSBasic ⌲ ℤ
integerTWSBasicL

cpDoubleWS  CParser TokenWSBasic 𝔻
cpDoubleWS :: CParser TokenWSBasic 𝔻
cpDoubleWS = (TokenWSBasic -> 𝑂 𝔻) -> CParser TokenWSBasic 𝔻
forall t a. (t -> 𝑂 a) -> CParser t a
cpShaped ((TokenWSBasic -> 𝑂 𝔻) -> CParser TokenWSBasic 𝔻)
-> (TokenWSBasic -> 𝑂 𝔻) -> CParser TokenWSBasic 𝔻
forall a b. (a -> b) -> a -> b
$ (TokenWSBasic ⌲ 𝔻) -> TokenWSBasic -> 𝑂 𝔻
forall a b. (a ⌲ b) -> a -> 𝑂 b
view TokenWSBasic ⌲ 𝔻
doubleTWSBasicL

cpStringWS  CParser TokenWSBasic 𝕊
cpStringWS :: CParser TokenWSBasic 𝕊
cpStringWS = (TokenWSBasic -> 𝑂 𝕊) -> CParser TokenWSBasic 𝕊
forall t a. (t -> 𝑂 a) -> CParser t a
cpShaped ((TokenWSBasic -> 𝑂 𝕊) -> CParser TokenWSBasic 𝕊)
-> (TokenWSBasic -> 𝑂 𝕊) -> CParser TokenWSBasic 𝕊
forall a b. (a -> b) -> a -> b
$ (TokenWSBasic ⌲ 𝕊) -> TokenWSBasic -> 𝑂 𝕊
forall a b. (a ⌲ b) -> a -> 𝑂 b
view TokenWSBasic ⌲ 𝕊
stringTWSBasicL

cpBlockWS  𝕊  CParser TokenWSBasic TokenWSBasic
cpBlockWS :: 𝕊 -> CParser TokenWSBasic TokenWSBasic
cpBlockWS = TokenWSBasic -> CParser TokenWSBasic TokenWSBasic
forall t. Ord t => t -> CParser t t
cpToken (TokenWSBasic -> CParser TokenWSBasic TokenWSBasic)
-> (𝕊 -> TokenWSBasic) -> 𝕊 -> CParser TokenWSBasic TokenWSBasic
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕊 -> TokenWSBasic
BlockTWSBasic

cpOpenWS  CParser TokenWSBasic ()
cpOpenWS :: CParser TokenWSBasic ()
cpOpenWS = CParser TokenWSBasic TokenWSBasic -> CParser TokenWSBasic ()
forall (m :: * -> *) a. Functor m => m a -> m ()
void (CParser TokenWSBasic TokenWSBasic -> CParser TokenWSBasic ())
-> CParser TokenWSBasic TokenWSBasic -> CParser TokenWSBasic ()
forall a b. (a -> b) -> a -> b
$ TokenWSBasic -> CParser TokenWSBasic TokenWSBasic
forall t. Ord t => t -> CParser t t
cpToken TokenWSBasic
OpenTWSBasic

cpCloseWS  CParser TokenWSBasic ()
cpCloseWS :: CParser TokenWSBasic ()
cpCloseWS = CParser TokenWSBasic TokenWSBasic -> CParser TokenWSBasic ()
forall (m :: * -> *) a. Functor m => m a -> m ()
void (CParser TokenWSBasic TokenWSBasic -> CParser TokenWSBasic ())
-> CParser TokenWSBasic TokenWSBasic -> CParser TokenWSBasic ()
forall a b. (a -> b) -> a -> b
$ TokenWSBasic -> CParser TokenWSBasic TokenWSBasic
forall t. Ord t => t -> CParser t t
cpToken TokenWSBasic
CloseTWSBasic

cpDelimWS  CParser TokenWSBasic ()
cpDelimWS :: CParser TokenWSBasic ()
cpDelimWS = CParser TokenWSBasic TokenWSBasic -> CParser TokenWSBasic ()
forall (m :: * -> *) a. Functor m => m a -> m ()
void (CParser TokenWSBasic TokenWSBasic -> CParser TokenWSBasic ())
-> CParser TokenWSBasic TokenWSBasic -> CParser TokenWSBasic ()
forall a b. (a -> b) -> a -> b
$ TokenWSBasic -> CParser TokenWSBasic TokenWSBasic
forall t. Ord t => t -> CParser t t
cpToken TokenWSBasic
DelimiterTWSBasic

cpNewExpressionContext  (Ord t)  CParser t a  CParser t a
cpNewExpressionContext :: forall t a. Ord t => CParser t a -> CParser t a
cpNewExpressionContext = Parser t a -> CParser t a
forall t a. Parser t a -> CParser t a
toCParser (Parser t a -> CParser t a)
-> (Parser t a -> Parser t a) -> Parser t a -> CParser 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
pNewExpressionContext (Parser t a -> CParser t a)
-> (CParser t a -> Parser t a) -> CParser t a -> CParser t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 CParser t a -> Parser t a
forall t a. Ord t => CParser t a -> Parser t a
frCParser

cpNewErrContext  (Ord t)  𝕊  CParser t a  CParser t a
cpNewErrContext :: forall t a. Ord t => 𝕊 -> CParser t a -> CParser t a
cpNewErrContext 𝕊
msg = Parser t a -> CParser t a
forall t a. Parser t a -> CParser t a
toCParser (Parser t a -> CParser t a)
-> (Parser t a -> Parser t a) -> Parser t a -> CParser 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 (Parser t a -> CParser t a)
-> (CParser t a -> Parser t a) -> CParser t a -> CParser t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 CParser t a -> Parser t a
forall t a. Ord t => CParser t a -> Parser t a
frCParser

cpNewContext  (Ord t)  𝕊  CParser t a  CParser t a
cpNewContext :: forall t a. Ord t => 𝕊 -> CParser t a -> CParser t a
cpNewContext 𝕊
s = Parser t a -> CParser t a
forall t a. Parser t a -> CParser t a
toCParser (Parser t a -> CParser t a)
-> (Parser t a -> Parser t a) -> Parser t a -> CParser 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
pNewContext 𝕊
s (Parser t a -> CParser t a)
-> (CParser t a -> Parser t a) -> CParser t a -> CParser t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 CParser t a -> Parser t a
forall t a. Ord t => CParser t a -> Parser t a
frCParser

cpWithContextRendered  (Ord t)  CParser t a  CParser t (𝐴 SrcCxt a)
cpWithContextRendered :: forall t a. Ord t => CParser t a -> CParser t (𝐴 SrcCxt a)
cpWithContextRendered = Parser t (𝐴 SrcCxt a) -> CParser t (𝐴 SrcCxt a)
forall t a. Parser t a -> CParser t a
toCParser (Parser t (𝐴 SrcCxt a) -> CParser t (𝐴 SrcCxt a))
-> (Parser t a -> Parser t (𝐴 SrcCxt a))
-> Parser t a
-> CParser t (𝐴 SrcCxt a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 Parser t a -> Parser t (𝐴 SrcCxt a)
forall t a. Parser t a -> Parser t (𝐴 SrcCxt a)
pWithContextRendered (Parser t a -> CParser t (𝐴 SrcCxt a))
-> (CParser t a -> Parser t a)
-> CParser t a
-> CParser t (𝐴 SrcCxt a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 CParser t a -> Parser t a
forall t a. Ord t => CParser t a -> Parser t a
frCParser

cpNewWithContextRendered  (Ord t)  𝕊  CParser t a  CParser t (𝐴 SrcCxt a)
cpNewWithContextRendered :: forall t a. Ord t => 𝕊 -> CParser t a -> CParser t (𝐴 SrcCxt a)
cpNewWithContextRendered 𝕊
s = 𝕊 -> CParser t (𝐴 SrcCxt a) -> CParser t (𝐴 SrcCxt a)
forall t a. Ord t => 𝕊 -> CParser t a -> CParser t a
cpNewContext 𝕊
s (CParser t (𝐴 SrcCxt a) -> CParser t (𝐴 SrcCxt a))
-> (CParser t a -> CParser t (𝐴 SrcCxt a))
-> CParser t a
-> CParser t (𝐴 SrcCxt a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 CParser t a -> CParser t (𝐴 SrcCxt a)
forall t a. Ord t => CParser t a -> CParser t (𝐴 SrcCxt a)
cpWithContextRendered

cpGetContextRendered  CParser t SrcCxt
cpGetContextRendered :: forall t. CParser t SrcCxt
cpGetContextRendered = Parser t SrcCxt -> CParser t SrcCxt
forall t a. Parser t a -> CParser t a
toCParser Parser t SrcCxt
forall t. Parser t SrcCxt
pGetContextRendered

cpNewGetContextRendered  (Ord t)  CParser t SrcCxt
cpNewGetContextRendered :: forall t. Ord t => CParser t SrcCxt
cpNewGetContextRendered = CParser t SrcCxt -> CParser t SrcCxt
forall t a. Ord t => CParser t a -> CParser t a
cpNewExpressionContext CParser t SrcCxt
forall t. CParser t SrcCxt
cpGetContextRendered

cpManyContext  (Ord t,Comonad f)  ( b. CParser t b  CParser t (f b))  CParser t a  CParser t (𝐿 (f a))
cpManyContext :: forall t (f :: * -> *) a.
(Ord t, Comonad f) =>
(forall b. CParser t b -> CParser t (f b))
-> CParser t a -> CParser t (𝐿 (f a))
cpManyContext forall b. CParser t b -> CParser t (f b)
f CParser t a
xM = [CParser t (𝐿 (f a))] -> CParser t (𝐿 (f a))
forall (m :: * -> *) a t.
(Monad m, MonadFail m, ToIter (m a) t) =>
t -> m a
tries
  [ (forall b. CParser t b -> CParser t (f b))
-> CParser t a -> CParser t (𝐿 (f a))
forall t (f :: * -> *) a.
(Ord t, Comonad f) =>
(forall b. CParser t b -> CParser t (f b))
-> CParser t a -> CParser t (𝐿 (f a))
cpOneOrMoreContext CParser t b -> CParser t (f b)
forall b. CParser t b -> CParser t (f b)
f CParser t a
xM
  , 𝐿 (f a) -> CParser t (𝐿 (f a))
forall a. a -> CParser t a
forall (m :: * -> *) a. Return m => a -> m a
return 𝐿 (f a)
forall a. 𝐿 a
Nil
  ]

cpOneOrMoreContext  (Ord t,Comonad f)  ( b. CParser t b  CParser t (f b))  CParser t a  CParser t (𝐿 (f a))
cpOneOrMoreContext :: forall t (f :: * -> *) a.
(Ord t, Comonad f) =>
(forall b. CParser t b -> CParser t (f b))
-> CParser t a -> CParser t (𝐿 (f a))
cpOneOrMoreContext forall b. CParser t b -> CParser t (f b)
f CParser t a
xM = do
  f (a ∧ 𝐿 (f a))
xxs  CParser t (a ∧ 𝐿 (f a)) -> CParser t (f (a ∧ 𝐿 (f a)))
forall b. CParser t b -> CParser t (f b)
f (CParser t (a ∧ 𝐿 (f a)) -> CParser t (f (a ∧ 𝐿 (f a))))
-> CParser t (a ∧ 𝐿 (f a)) -> CParser t (f (a ∧ 𝐿 (f a)))
forall a b. (a -> b) -> a -> b
$ do
    a
x  CParser t a
xM
    𝐿 (f a)
xs  (forall b. CParser t b -> CParser t (f b))
-> CParser t a -> CParser t (𝐿 (f a))
forall t (f :: * -> *) a.
(Ord t, Comonad f) =>
(forall b. CParser t b -> CParser t (f b))
-> CParser t a -> CParser t (𝐿 (f a))
cpManyContext CParser t b -> CParser t (f b)
forall b. CParser t b -> CParser t (f b)
f CParser t a
xM
    (a ∧ 𝐿 (f a)) -> CParser t (a ∧ 𝐿 (f a))
forall a. a -> CParser t a
forall (m :: * -> *) a. Return m => a -> m a
return ((a ∧ 𝐿 (f a)) -> CParser t (a ∧ 𝐿 (f a)))
-> (a ∧ 𝐿 (f a)) -> CParser t (a ∧ 𝐿 (f a))
forall a b. (a -> b) -> a -> b
$ a
x a -> 𝐿 (f a) -> a ∧ 𝐿 (f a)
forall a b. a -> b -> a ∧ b
:* 𝐿 (f a)
xs
  let a
x :* 𝐿 (f a)
xs = f (a ∧ 𝐿 (f a)) -> a ∧ 𝐿 (f a)
forall a. f a -> a
forall (w :: * -> *) a. Extract w => w a -> a
extract f (a ∧ 𝐿 (f a))
xxs
  𝐿 (f a) -> CParser t (𝐿 (f a))
forall a. a -> CParser t a
forall (m :: * -> *) a. Return m => a -> m a
return (𝐿 (f a) -> CParser t (𝐿 (f a))) -> 𝐿 (f a) -> CParser t (𝐿 (f a))
forall a b. (a -> b) -> a -> b
$ f (a ∧ 𝐿 (f a)) -> a -> f a
forall (w :: * -> *) a b. Cobind w => w a -> b -> w b
siphon f (a ∧ 𝐿 (f a))
xxs a
x f a -> 𝐿 (f a) -> 𝐿 (f a)
forall a. a -> 𝐿 a -> 𝐿 a
:& 𝐿 (f a)
xs

cpManySepByContext  (Ord t,Comonad f)  ( b. CParser t b  CParser t (f b))  CParser t ()  CParser t a  CParser t (𝐿 (f a))
cpManySepByContext :: forall t (f :: * -> *) a.
(Ord t, Comonad f) =>
(forall b. CParser t b -> CParser t (f b))
-> CParser t () -> CParser t a -> CParser t (𝐿 (f a))
cpManySepByContext forall b. CParser t b -> CParser t (f b)
f CParser t ()
sepM CParser t a
xM = [CParser t (𝐿 (f a))] -> CParser t (𝐿 (f a))
forall (m :: * -> *) a t.
(Monad m, MonadFail m, ToIter (m a) t) =>
t -> m a
tries
  [ (forall b. CParser t b -> CParser t (f b))
-> CParser t () -> CParser t a -> CParser t (𝐿 (f a))
forall t (f :: * -> *) a.
(Ord t, Comonad f) =>
(forall b. CParser t b -> CParser t (f b))
-> CParser t () -> CParser t a -> CParser t (𝐿 (f a))
cpOneOrMoreSepByContext CParser t b -> CParser t (f b)
forall b. CParser t b -> CParser t (f b)
f CParser t ()
sepM CParser t a
xM
  , 𝐿 (f a) -> CParser t (𝐿 (f a))
forall a. a -> CParser t a
forall (m :: * -> *) a. Return m => a -> m a
return 𝐿 (f a)
forall a. 𝐿 a
Nil
  ]

cpOneOrMoreSepByContext  (Ord t,Comonad f)  ( b. CParser t b  CParser t (f b))  CParser t ()  CParser t a  CParser t (𝐿 (f a))
cpOneOrMoreSepByContext :: forall t (f :: * -> *) a.
(Ord t, Comonad f) =>
(forall b. CParser t b -> CParser t (f b))
-> CParser t () -> CParser t a -> CParser t (𝐿 (f a))
cpOneOrMoreSepByContext forall b. CParser t b -> CParser t (f b)
f CParser t ()
sepM CParser t a
xM = do
  f (a ∧ 𝐿 (f a))
xxs  CParser t (a ∧ 𝐿 (f a)) -> CParser t (f (a ∧ 𝐿 (f a)))
forall b. CParser t b -> CParser t (f b)
f (CParser t (a ∧ 𝐿 (f a)) -> CParser t (f (a ∧ 𝐿 (f a))))
-> CParser t (a ∧ 𝐿 (f a)) -> CParser t (f (a ∧ 𝐿 (f a)))
forall a b. (a -> b) -> a -> b
$ do
    a
x  CParser t a
xM
    𝐿 (f a)
xs  (forall b. CParser t b -> CParser t (f b))
-> CParser t a -> CParser t (𝐿 (f a))
forall t (f :: * -> *) a.
(Ord t, Comonad f) =>
(forall b. CParser t b -> CParser t (f b))
-> CParser t a -> CParser t (𝐿 (f a))
cpManyContext CParser t b -> CParser t (f b)
forall b. CParser t b -> CParser t (f b)
f (CParser t a -> CParser t (𝐿 (f a)))
-> CParser t a -> CParser t (𝐿 (f a))
forall a b. (a -> b) -> a -> b
$ ((() ∧ a) -> a) -> CParser t (() ∧ a) -> CParser t a
forall a b. (a -> b) -> CParser t a -> CParser t b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map (() ∧ a) -> a
forall a b. (a ∧ b) -> b
snd (CParser t (() ∧ a) -> CParser t a)
-> CParser t (() ∧ a) -> CParser t a
forall a b. (a -> b) -> a -> b
$ CParser t ()
sepM CParser t () -> CParser t a -> CParser t (() ∧ a)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m (a ∧ b)
 CParser t a
xM
    (a ∧ 𝐿 (f a)) -> CParser t (a ∧ 𝐿 (f a))
forall a. a -> CParser t a
forall (m :: * -> *) a. Return m => a -> m a
return ((a ∧ 𝐿 (f a)) -> CParser t (a ∧ 𝐿 (f a)))
-> (a ∧ 𝐿 (f a)) -> CParser t (a ∧ 𝐿 (f a))
forall a b. (a -> b) -> a -> b
$ a
x a -> 𝐿 (f a) -> a ∧ 𝐿 (f a)
forall a b. a -> b -> a ∧ b
:* 𝐿 (f a)
xs
  let a
x :* 𝐿 (f a)
xs = f (a ∧ 𝐿 (f a)) -> a ∧ 𝐿 (f a)
forall a. f a -> a
forall (w :: * -> *) a. Extract w => w a -> a
extract f (a ∧ 𝐿 (f a))
xxs
  𝐿 (f a) -> CParser t (𝐿 (f a))
forall a. a -> CParser t a
forall (m :: * -> *) a. Return m => a -> m a
return (𝐿 (f a) -> CParser t (𝐿 (f a))) -> 𝐿 (f a) -> CParser t (𝐿 (f a))
forall a b. (a -> b) -> a -> b
$ f (a ∧ 𝐿 (f a)) -> a -> f a
forall (w :: * -> *) a b. Cobind w => w a -> b -> w b
siphon f (a ∧ 𝐿 (f a))
xxs a
x f a -> 𝐿 (f a) -> 𝐿 (f a)
forall a. a -> 𝐿 a -> 𝐿 a
:& 𝐿 (f a)
xs

---------------------
-- Running Parsers --
---------------------
             
runParser₀  (ToIter (ParserToken t) ts,Ord t)  𝕊  ts  CParser t a  ParserOut t  𝑂 (ParserState t  a)
runParser₀ :: forall t ts a.
(ToIter (ParserToken t) ts, Ord t) =>
𝕊 -> ts -> CParser t a -> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
runParser₀ 𝕊
so = ((Parser t a -> ParserOut t ∧ 𝑂 (ParserState t ∧ a))
-> (CParser t a -> Parser t a)
-> CParser t a
-> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 CParser t a -> Parser t a
forall t a. Ord t => CParser t a -> Parser t a
frCParser) ((Parser t a -> ParserOut t ∧ 𝑂 (ParserState t ∧ a))
 -> CParser t a -> ParserOut t ∧ 𝑂 (ParserState t ∧ a))
-> (ParserState t
    -> Parser t a -> ParserOut t ∧ 𝑂 (ParserState t ∧ a))
-> ParserState t
-> CParser t a
-> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 ParserEnv
-> ParserState t
-> Parser t a
-> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
forall t a.
ParserEnv
-> ParserState t
-> Parser t a
-> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
runParser (𝕊 -> ParserEnv
parserEnv₀ 𝕊
so) (ParserState t
 -> CParser t a -> ParserOut t ∧ 𝑂 (ParserState t ∧ a))
-> (𝑆 (ParserToken t) -> ParserState t)
-> 𝑆 (ParserToken t)
-> CParser t a
-> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝑆 (ParserToken t) -> ParserState t
forall t. 𝑆 (ParserToken t) -> ParserState t
parserState₀ (𝑆 (ParserToken t)
 -> CParser t a -> ParserOut t ∧ 𝑂 (ParserState t ∧ a))
-> (ts -> 𝑆 (ParserToken t))
-> ts
-> CParser t a
-> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 ts -> 𝑆 (ParserToken t)
forall a t. ToIter a t => t -> 𝑆 a
stream

parse  (Pretty a,ToIter (ParserToken t) ts,Ord t)  CParser t a  𝕊  ts  Doc  a
parse :: forall a t ts.
(Pretty a, ToIter (ParserToken t) ts, Ord t) =>
CParser t a -> 𝕊 -> ts -> Doc ∨ a
parse CParser t a
p 𝕊
so ts
ts = case 𝕊 -> ts -> CParser t a -> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
forall t ts a.
(ToIter (ParserToken t) ts, Ord t) =>
𝕊 -> ts -> CParser t a -> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
runParser₀ 𝕊
so ts
ts (CParser t a -> ParserOut t ∧ 𝑂 (ParserState t ∧ a))
-> CParser t a -> ParserOut t ∧ 𝑂 (ParserState t ∧ a)
forall a b. (a -> b) -> a -> b
$ CParser t a -> CParser t a
forall t a. Ord t => CParser t a -> CParser t a
cpFinal CParser t a
p of
  (ParserOut t
pe :* 𝑂 (ParserState t ∧ a)
None)  Doc -> Doc ∨ a
forall a b. a -> a ∨ b
Inl (Doc -> Doc ∨ a) -> Doc -> Doc ∨ a
forall a b. (a -> b) -> a -> b
$ 𝕊 -> ParserOut t -> Doc
forall {k} (t :: k). 𝕊 -> AddNull (ParserError t) -> Doc
displaySourceError 𝕊
so ParserOut t
pe
  (ParserOut t
_ :* Some (ParserState t
_ :* a
x))  a -> Doc ∨ a
forall a b. b -> a ∨ b
Inr a
x

parseIO  (Pretty a,ToIter (ParserToken t) ts,Ord t)  CParser t a  𝕊  ts  IO a
parseIO :: forall a t ts.
(Pretty a, ToIter (ParserToken t) ts, Ord t) =>
CParser t a -> 𝕊 -> ts -> IO a
parseIO CParser t a
p 𝕊
s ts
ts = case CParser t a -> 𝕊 -> ts -> Doc ∨ a
forall a t ts.
(Pretty a, ToIter (ParserToken t) ts, Ord t) =>
CParser t a -> 𝕊 -> ts -> Doc ∨ a
parse CParser t a
p 𝕊
s ts
ts of
  Inl Doc
d  Doc -> IO ()
forall a. Pretty a => a -> IO ()
pprint Doc
d IO () -> IO a -> IO a
forall (m :: * -> *) a b. Bind m => m a -> m b -> m b
 IO a
forall a. IO a
abortIO
  Inr a
a  a -> IO a
forall a. a -> IO a
forall (m :: * -> *) a. Return m => a -> m a
return a
a

parseIOMain  (Pretty a,ToIter (ParserToken t) ts,Ord t)  CParser t a  𝕊  ts  IO ()
parseIOMain :: forall a t ts.
(Pretty a, ToIter (ParserToken t) ts, Ord t) =>
CParser t a -> 𝕊 -> ts -> IO ()
parseIOMain CParser t a
p 𝕊
s ts
ts = do
  a
x  CParser t a -> 𝕊 -> ts -> IO a
forall a t ts.
(Pretty a, ToIter (ParserToken t) ts, Ord t) =>
CParser t a -> 𝕊 -> ts -> IO a
parseIO CParser t a
p 𝕊
s ts
ts
  Doc -> IO ()
forall a. Pretty a => a -> IO ()
pprint (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
forall t. ToIter Doc t => t -> Doc
ppVertical 
    [ 𝕊 -> Doc
ppHeader 𝕊
"Success"
    , a -> Doc
forall a. Pretty a => a -> Doc
pretty a
x
    ]