{-# LANGUAGE FlexibleContexts, FlexibleInstances, GADTs, GeneralizedNewtypeDeriving, InstanceSigs,
             RankNTypes, ScopedTypeVariables, StandaloneDeriving, TypeApplications, TypeFamilies, TypeOperators,
             UndecidableInstances #-}
{-# OPTIONS -fno-full-laziness #-}
module Text.Grampa.ContextFree.LeftRecursive (Fixed, Parser, SeparatedParser(..), FallibleWithExpectations(..),
                                              longest, peg, terminalPEG,
                                              liftPositive, liftPure, mapPrimitive,
                                              parseSeparated, separated)
where

import Control.Applicative
import Control.Monad (Monad(..), MonadPlus(..), void)
import Control.Monad.Trans.State.Lazy (State, evalState, get, put)

import Data.Functor.Compose (Compose(..))
import Data.Maybe (isJust)

import Data.Semigroup (Semigroup(..))
import Data.Monoid (Monoid(mempty), All(..), Any(..))
import Data.Monoid.Null (MonoidNull(null))
import Data.Monoid.Factorial (FactorialMonoid)
import Data.Monoid.Textual (TextualMonoid)
import Data.Semigroup.Cancellative (LeftReductive)
import qualified Data.Monoid.Factorial as Factorial
import qualified Data.Monoid.Textual as Textual
import Data.String (fromString)
import Data.Type.Equality ((:~:)(Refl))

import qualified Text.Parser.Char as Char
import Text.Parser.Char (CharParsing)
import Text.Parser.Combinators (Parsing(..))
import Text.Parser.LookAhead (LookAheadParsing(..))

import qualified Rank2
import Text.Grampa.Class (GrammarParsing(..), InputParsing(..), InputCharParsing(..), MultiParsing(..),
                          AmbiguousParsing(..), Ambiguous(..),
                          ConsumedInputParsing(..), DeterministicParsing(..),
                          TailsParsing(parseTails, parseAllTails), Expected(..))
import Text.Grampa.Internal (ResultList(..), FailureInfo(..), AmbiguousAlternative(ambiguousOr))
import qualified Text.Grampa.ContextFree.SortedMemoizing as Memoizing
import qualified Text.Grampa.PEG.Backtrack.Measured as Backtrack

import Prelude hiding (cycle, null, span, take, takeWhile)

type Parser = Fixed Memoizing.Parser

type ResultAppend p (g :: (* -> *) -> *) s =
   GrammarFunctor (p g s) Rank2.~> GrammarFunctor (p g s) Rank2.~> GrammarFunctor (p g s)

data Fixed p g s a =
   Parser {
      Fixed p g s a -> p g s a
complete, Fixed p g s a -> p g s a
direct, Fixed p g s a -> p g s a
direct0, Fixed p g s a -> p g s a
direct1, Fixed p g s a -> p g s a
indirect :: p g s a,
      Fixed p g s a -> Maybe (AmbiguityWitness a)
isAmbiguous :: Maybe (AmbiguityWitness a),
      Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants :: Rank2.Apply g => g (Const (ParserFlags g)) -> ParserFlags g}
   | DirectParser {
      complete, direct0, direct1 :: p g s a}
   | PositiveDirectParser {
      complete :: p g s a}

data AmbiguityWitness a where
   AmbiguityWitness :: (a :~: Ambiguous b) -> AmbiguityWitness a

data SeparatedParser p (g :: (* -> *) -> *) s a = FrontParser (p g s a)
                                                | CycleParser {
                                                     SeparatedParser p g s a -> p g s a
cycleParser  :: p g s a,
                                                     SeparatedParser p g s a -> p g s a
backParser   :: p g s a,
                                                     SeparatedParser p g s a -> ResultAppend p g s a
appendResultsArrow :: ResultAppend p g s a,
                                                     SeparatedParser p g s a -> g (Const Bool)
dependencies :: g (Const Bool)}
                                                | BackParser {
                                                     backParser :: p g s a}

data ParserFlags g = ParserFlags {
   ParserFlags g -> Bool
nullable :: Bool,
   ParserFlags g -> g (Const Bool)
dependsOn :: g (Const Bool)}

deriving instance Show (g (Const Bool)) => Show (ParserFlags g)

data ParserFunctor p g s a = ParserResultsFunctor {ParserFunctor p g s a -> GrammarFunctor (p g s) a
parserResults :: GrammarFunctor (p g s) a}
                           | ParserFlagsFunctor {ParserFunctor p g s a -> ParserFlags g
parserFlags :: ParserFlags g}

newtype Union (g :: (* -> *) -> *) = Union{Union g -> g (Const Bool)
getUnion :: g (Const Bool)}

--instance Rank2.Applicative g => Monoid (Union g) where
--   mempty = Union (Rank2.pure $ Const False)

instance (Rank2.Apply g, Rank2.Distributive g) => Semigroup (Union g) where
   Union g1 :: g (Const Bool)
g1 <> :: Union g -> Union g -> Union g
<> Union g2 :: g (Const Bool)
g2 = g (Const Bool) -> Union g
forall (g :: (* -> *) -> *). g (Const Bool) -> Union g
Union ((forall a. Const Bool a -> Const Bool a -> Const Bool a)
-> g (Const Bool) -> g (Const Bool) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. Const Bool a -> Const Bool a -> Const Bool a
union g (Const Bool)
g1 g (Const Bool)
g2)

instance (Rank2.Apply g, Rank2.Distributive g) => Monoid (Union g) where
   mempty :: Union g
mempty = g (Const Bool) -> Union g
forall (g :: (* -> *) -> *). g (Const Bool) -> Union g
Union ((forall a. Const Bool (Any a) -> Const Bool a)
-> Const Bool (g Any) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (m :: * -> *) (p :: k -> *)
       (q :: k -> *).
(Distributive g, Functor m) =>
(forall (a :: k). m (p a) -> q a) -> m (g p) -> g q
Rank2.cotraverse (Bool -> Const Bool a
forall k a (b :: k). a -> Const a b
Const (Bool -> Const Bool a)
-> (Const Bool (Any a) -> Bool)
-> Const Bool (Any a)
-> Const Bool a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const Bool (Any a) -> Bool
forall a k (b :: k). Const a b -> a
getConst) (Bool -> Const Bool (g Any)
forall k a (b :: k). a -> Const a b
Const Bool
False))
   mappend :: Union g -> Union g -> Union g
mappend (Union g1 :: g (Const Bool)
g1) (Union g2 :: g (Const Bool)
g2) = g (Const Bool) -> Union g
forall (g :: (* -> *) -> *). g (Const Bool) -> Union g
Union ((forall a. Const Bool a -> Const Bool a -> Const Bool a)
-> g (Const Bool) -> g (Const Bool) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. Const Bool a -> Const Bool a -> Const Bool a
union g (Const Bool)
g1 g (Const Bool)
g2)

mapPrimitive :: (p g s a -> p g s a) -> Fixed p g s a -> Fixed p g s a
mapPrimitive :: (p g s a -> p g s a) -> Fixed p g s a -> Fixed p g s a
mapPrimitive f :: p g s a -> p g s a
f p :: Fixed p g s a
p@PositiveDirectParser{} = PositiveDirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser{complete :: p g s a
complete= p g s a -> p g s a
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p)}
mapPrimitive f :: p g s a -> p g s a
f p :: Fixed p g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{complete :: p g s a
complete= p g s a -> p g s a
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
                                               direct0 :: p g s a
direct0= p g s a -> p g s a
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p),
                                               direct1 :: p g s a
direct1= p g s a -> p g s a
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p)}
mapPrimitive f :: p g s a -> p g s a
f p :: Fixed p g s a
p@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{complete :: p g s a
complete= p g s a -> p g s a
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
                                   isAmbiguous :: Maybe (AmbiguityWitness a)
isAmbiguous= Fixed p g s a -> Maybe (AmbiguityWitness a)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> Maybe (AmbiguityWitness a)
isAmbiguous Fixed p g s a
p,
                                   cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p,
                                   indirect :: p g s a
indirect= p g s a -> p g s a
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p),
                                   direct :: p g s a
direct= p g s a -> p g s a
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p),
                                   direct0 :: p g s a
direct0= p g s a -> p g s a
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p),
                                   direct1 :: p g s a
direct1= p g s a -> p g s a
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p)}

general, general' :: Alternative (p g s) => Fixed p g s a -> Fixed p g s a

general :: Fixed p g s a -> Fixed p g s a
general p :: Fixed p g s a
p = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
   complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p,
   direct :: p g s a
direct = Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p',
   direct0 :: p g s a
direct0= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p',
   direct1 :: p g s a
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p',
   indirect :: p g s a
indirect= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p',
   isAmbiguous :: Maybe (AmbiguityWitness a)
isAmbiguous= case Fixed p g s a
p
                of Parser{isAmbiguous :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> Maybe (AmbiguityWitness a)
isAmbiguous= Maybe (AmbiguityWitness a)
a} -> Maybe (AmbiguityWitness a)
a
                   _ -> Maybe (AmbiguityWitness a)
forall a. Maybe a
Nothing,
   cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p'}
   where p' :: Fixed p g s a
p' = Fixed p g s a -> Fixed p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general' Fixed p g s a
p

general' :: Fixed p g s a -> Fixed p g s a
general' p :: Fixed p g s a
p@PositiveDirectParser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
   complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p,
   direct :: p g s a
direct = Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p,
   direct0 :: p g s a
direct0= p g s a
forall (f :: * -> *) a. Alternative f => f a
empty,
   direct1 :: p g s a
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p,
   indirect :: p g s a
indirect= p g s a
forall (f :: * -> *) a. Alternative f => f a
empty,
   isAmbiguous :: Maybe (AmbiguityWitness a)
isAmbiguous= Maybe (AmbiguityWitness a)
forall a. Maybe a
Nothing,
   cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \cd :: g (Const (ParserFlags g))
cd-> Bool -> g (Const Bool) -> ParserFlags g
forall (g :: (* -> *) -> *).
Bool -> g (Const Bool) -> ParserFlags g
ParserFlags Bool
False (Const Bool a -> Const (ParserFlags g) a -> Const Bool a
forall a b. a -> b -> a
const (Bool -> Const Bool a
forall k a (b :: k). a -> Const a b
Const Bool
False) (forall a. Const (ParserFlags g) a -> Const Bool a)
-> g (Const (ParserFlags g)) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.<$> g (Const (ParserFlags g))
cd)}
general' p :: Fixed p g s a
p@DirectParser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
   complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p,
   direct :: p g s a
direct = Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p,
   direct0 :: p g s a
direct0= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p,
   direct1 :: p g s a
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p,
   indirect :: p g s a
indirect= p g s a
forall (f :: * -> *) a. Alternative f => f a
empty,
   isAmbiguous :: Maybe (AmbiguityWitness a)
isAmbiguous= Maybe (AmbiguityWitness a)
forall a. Maybe a
Nothing,
   cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \cd :: g (Const (ParserFlags g))
cd-> Bool -> g (Const Bool) -> ParserFlags g
forall (g :: (* -> *) -> *).
Bool -> g (Const Bool) -> ParserFlags g
ParserFlags Bool
True (Const Bool a -> Const (ParserFlags g) a -> Const Bool a
forall a b. a -> b -> a
const (Bool -> Const Bool a
forall k a (b :: k). a -> Const a b
Const Bool
False) (forall a. Const (ParserFlags g) a -> Const Bool a)
-> g (Const (ParserFlags g)) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.<$> g (Const (ParserFlags g))
cd)}
general' p :: Fixed p g s a
p@Parser{} = Fixed p g s a
p

-- | Parser of general context-free grammars, including left recursion.
--
-- @
-- 'parseComplete' :: ("Rank2".'Rank2.Apply' g, "Rank2".'Rank2.Traversable' g, 'FactorialMonoid' s) =>
--                  g (LeftRecursive.'Fixed g s) -> s -> g ('Compose' ('ParseResults' s) [])
-- @
instance (Eq s, LeftReductive s, FactorialMonoid s, Alternative (p g s),
          TailsParsing (p g s), GrammarConstraint (p g s) g, ParserGrammar (p g s) ~ g,
          Functor (ResultFunctor (p g s)),
          s ~ ParserInput (p g s), GrammarFunctor (p g s) ~ rl s, FallibleWithExpectations rl,
          AmbiguousAlternative (GrammarFunctor (p g s))) =>
         MultiParsing (Fixed p g s) where
   type GrammarConstraint (Fixed p g s) g' = (GrammarConstraint (p g s) g', g ~ g',
                                              Rank2.Apply g, Rank2.Distributive g, Rank2.Traversable g)
   type ResultFunctor (Fixed p g s) = ResultFunctor (p g s)
   parsePrefix :: (Rank2.Apply g, Rank2.Distributive g, Rank2.Traversable g, Eq s, FactorialMonoid s) =>
                  g (Fixed p g s) -> s -> g (Compose (ResultFunctor (p g s)) ((,) s))
   parsePrefix :: g (Fixed p g s) -> s -> g (Compose (ResultFunctor (p g s)) ((,) s))
parsePrefix g :: g (Fixed p g s)
g input :: s
input = (forall a. rl s a -> Compose (ResultFunctor (p g s)) ((,) s) a)
-> g (rl s) -> g (Compose (ResultFunctor (p g s)) ((,) s))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (ResultFunctor (p g s) (s, a)
-> Compose (ResultFunctor (p g s)) ((,) s) a
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (ResultFunctor (p g s) (s, a)
 -> Compose (ResultFunctor (p g s)) ((,) s) a)
-> (rl s a -> ResultFunctor (p g s) (s, a))
-> rl s a
-> Compose (ResultFunctor (p g s)) ((,) s) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserInput (p g s)
-> GrammarFunctor (p g s) a
-> ResultFunctor (p g s) (ParserInput (p g s), a)
forall (m :: * -> *) a.
GrammarParsing m =>
ParserInput m
-> GrammarFunctor m a -> ResultFunctor m (ParserInput m, a)
parsingResult @(p g s) s
ParserInput (p g s)
input)
                                    ((s, g (rl s)) -> g (rl s)
forall a b. (a, b) -> b
snd ((s, g (rl s)) -> g (rl s)) -> (s, g (rl s)) -> g (rl s)
forall a b. (a -> b) -> a -> b
$ [(s, g (rl s))] -> (s, g (rl s))
forall a. [a] -> a
head ([(s, g (rl s))] -> (s, g (rl s)))
-> [(s, g (rl s))] -> (s, g (rl s))
forall a b. (a -> b) -> a -> b
$ g (Fixed p g s) -> s -> [(s, g (GrammarFunctor (p g s)))]
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       (rl :: * -> * -> *).
(Apply g, Distributive g, Traversable g, Eq s, FactorialMonoid s,
 LeftReductive s, Alternative (p g s), TailsParsing (p g s),
 GrammarConstraint (p g s) g, s ~ ParserInput (p g s),
 GrammarFunctor (p g s) ~ rl s, FallibleWithExpectations rl,
 AmbiguousAlternative (GrammarFunctor (p g s))) =>
g (Fixed p g s) -> s -> [(s, g (GrammarFunctor (p g s)))]
parseRecursive g (Fixed p g s)
g s
input)
   {-# INLINE parsePrefix #-}
   parseComplete :: (Rank2.Apply g, Rank2.Distributive g, Rank2.Traversable g, Eq s, FactorialMonoid s) =>
                    g (Fixed p g s) -> s -> g (ResultFunctor (p g s))
   parseComplete :: g (Fixed p g s) -> s -> g (ResultFunctor (p g s))
parseComplete g :: g (Fixed p g s)
g = \input :: s
input-> let close :: g (p g s)
                                  close :: g (p g s)
close = (forall a. p g s a -> p g s a) -> g (p g s) -> g (p g s)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (p g s a -> p g s () -> p g s a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* p g s ()
forall (m :: * -> *). Parsing m => m ()
eof) g (p g s)
forall (m :: * -> *) (g :: (* -> *) -> *).
(GrammarParsing m, g ~ ParserGrammar m, GrammarConstraint m g,
 Distributive g) =>
g m
selfReferring
                              in (forall a. rl s a -> ResultFunctor (p g s) a)
-> g (rl s) -> g (ResultFunctor (p g s))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (((s, a) -> a
forall a b. (a, b) -> b
snd ((s, a) -> a)
-> ResultFunctor (p g s) (s, a) -> ResultFunctor (p g s) a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (ResultFunctor (p g s) (s, a) -> ResultFunctor (p g s) a)
-> (rl s a -> ResultFunctor (p g s) (s, a))
-> rl s a
-> ResultFunctor (p g s) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserInput (p g s)
-> GrammarFunctor (p g s) a
-> ResultFunctor (p g s) (ParserInput (p g s), a)
forall (m :: * -> *) a.
GrammarParsing m =>
ParserInput m
-> GrammarFunctor m a -> ResultFunctor m (ParserInput m, a)
parsingResult @(p g s) s
ParserInput (p g s)
input)
                                            ((s, g (rl s)) -> g (rl s)
forall a b. (a, b) -> b
snd ((s, g (rl s)) -> g (rl s)) -> (s, g (rl s)) -> g (rl s)
forall a b. (a -> b) -> a -> b
$ [(s, g (rl s))] -> (s, g (rl s))
forall a. [a] -> a
head ([(s, g (rl s))] -> (s, g (rl s)))
-> [(s, g (rl s))] -> (s, g (rl s))
forall a b. (a -> b) -> a -> b
$ g (p g s)
-> [(ParserInput (p g s), g (GrammarFunctor (p g s)))]
-> [(ParserInput (p g s), g (GrammarFunctor (p g s)))]
forall (m :: * -> *) (g :: (* -> *) -> *).
(TailsParsing m, GrammarConstraint m g, Functor g) =>
g m
-> [(ParserInput m, g (GrammarFunctor m))]
-> [(ParserInput m, g (GrammarFunctor m))]
parseAllTails g (p g s)
close ([(ParserInput (p g s), g (GrammarFunctor (p g s)))]
 -> [(s, g (rl s))])
-> [(ParserInput (p g s), g (GrammarFunctor (p g s)))]
-> [(s, g (rl s))]
forall a b. (a -> b) -> a -> b
$ g (SeparatedParser p g s) -> s -> [(s, g (GrammarFunctor (p g s)))]
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *)
       (rl :: * -> * -> *) s.
(Apply g, Foldable g, Eq s, FactorialMonoid s, LeftReductive s,
 TailsParsing (p g s), GrammarConstraint (p g s) g,
 GrammarFunctor (p g s) ~ rl s, FallibleWithExpectations rl,
 s ~ ParserInput (p g s)) =>
g (SeparatedParser p g s) -> s -> [(s, g (GrammarFunctor (p g s)))]
parseSeparated g (SeparatedParser p g s)
g' s
input)
      where g' :: g (SeparatedParser p g s)
g' = g (Fixed p g s) -> g (SeparatedParser p g s)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *)
       s.
(Alternative (p g s), Apply g, Distributive g, Traversable g,
 AmbiguousAlternative (GrammarFunctor (p g s))) =>
g (Fixed p g s) -> g (SeparatedParser p g s)
separated g (Fixed p g s)
g
   {-# INLINE parseComplete #-}

instance (Eq s, LeftReductive s, FactorialMonoid s, Alternative (p g s),
          TailsParsing (p g s), GrammarConstraint (p g s) g, ParserGrammar (p g s) ~ g,
          Functor (ResultFunctor (p g s)),
          s ~ ParserInput (p g s), GrammarFunctor (p g s) ~ rl s, FallibleWithExpectations rl,
          AmbiguousAlternative (GrammarFunctor (p g s))) =>
         GrammarParsing (Fixed p g s) where
   type ParserGrammar (Fixed p g s) = g
   type GrammarFunctor (Fixed p g s) = ParserFunctor p g s
   parsingResult :: s -> ParserFunctor p g s a -> ResultFunctor (p g s) (s, a)
   parsingResult :: s -> ParserFunctor p g s a -> ResultFunctor (p g s) (s, a)
parsingResult s :: s
s = ParserInput (p g s)
-> GrammarFunctor (p g s) a
-> ResultFunctor (p g s) (ParserInput (p g s), a)
forall (m :: * -> *) a.
GrammarParsing m =>
ParserInput m
-> GrammarFunctor m a -> ResultFunctor m (ParserInput m, a)
parsingResult @(p g s) s
ParserInput (p g s)
s (rl s a -> ResultFunctor (p g s) (s, a))
-> (ParserFunctor p g s a -> rl s a)
-> ParserFunctor p g s a
-> ResultFunctor (p g s) (s, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserFunctor p g s a -> rl s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
ParserFunctor p g s a -> GrammarFunctor (p g s) a
parserResults
   nonTerminal :: (Rank2.Apply g, Rank2.Distributive g, Rank2.Traversable g) =>
                  (g (ParserFunctor p g s) -> ParserFunctor p g s a) -> Fixed p g s a
   nonTerminal :: (g (ParserFunctor p g s) -> ParserFunctor p g s a) -> Fixed p g s a
nonTerminal f :: g (ParserFunctor p g s) -> ParserFunctor p g s a
f = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
      complete :: p g s a
complete= p g s a
ind,
      direct :: p g s a
direct= p g s a
forall (f :: * -> *) a. Alternative f => f a
empty,
      direct0 :: p g s a
direct0= p g s a
forall (f :: * -> *) a. Alternative f => f a
empty,
      direct1 :: p g s a
direct1= p g s a
forall (f :: * -> *) a. Alternative f => f a
empty,
      indirect :: p g s a
indirect= p g s a
ind,
      isAmbiguous :: Maybe (AmbiguityWitness a)
isAmbiguous= Maybe (AmbiguityWitness a)
forall a. Maybe a
Nothing,
      cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= ParserFunctor p g s a -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
ParserFunctor p g s a -> ParserFlags g
parserFlags (ParserFunctor p g s a -> ParserFlags g)
-> (g (Const (ParserFlags g)) -> ParserFunctor p g s a)
-> g (Const (ParserFlags g))
-> ParserFlags g
forall b c a. (b -> c) -> (a -> b) -> a -> c
. g (ParserFunctor p g s) -> ParserFunctor p g s a
f (g (ParserFunctor p g s) -> ParserFunctor p g s a)
-> (g (Const (ParserFlags g)) -> g (ParserFunctor p g s))
-> g (Const (ParserFlags g))
-> ParserFunctor p g s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Const (ParserFlags g) a -> ParserFunctor p g s a)
-> g (Const (ParserFlags g)) -> g (ParserFunctor p g s)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (ParserFlags g -> ParserFunctor p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
ParserFlags g -> ParserFunctor p g s a
ParserFlagsFunctor (ParserFlags g -> ParserFunctor p g s a)
-> (Const (ParserFlags g) a -> ParserFlags g)
-> Const (ParserFlags g) a
-> ParserFunctor p g s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const (ParserFlags g) a -> ParserFlags g
forall a k (b :: k). Const a b -> a
getConst) (g (Const (ParserFlags g)) -> g (ParserFunctor p g s))
-> (g (Const (ParserFlags g)) -> g (Const (ParserFlags g)))
-> g (Const (ParserFlags g))
-> g (ParserFunctor p g s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. g (Const (ParserFlags g)) -> g (Const (ParserFlags g))
addSelf}
      where ind :: p g s a
ind = (g (GrammarFunctor (p g s)) -> GrammarFunctor (p g s) a) -> p g s a
forall (m :: * -> *) (g :: (* -> *) -> *) a.
(GrammarParsing m, g ~ ParserGrammar m, GrammarConstraint m g) =>
(g (GrammarFunctor m) -> GrammarFunctor m a) -> m a
nonTerminal (ParserFunctor p g s a -> rl s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
ParserFunctor p g s a -> GrammarFunctor (p g s) a
parserResults (ParserFunctor p g s a -> rl s a)
-> (g (rl s) -> ParserFunctor p g s a) -> g (rl s) -> rl s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. g (ParserFunctor p g s) -> ParserFunctor p g s a
f (g (ParserFunctor p g s) -> ParserFunctor p g s a)
-> (g (rl s) -> g (ParserFunctor p g s))
-> g (rl s)
-> ParserFunctor p g s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. rl s a -> ParserFunctor p g s a)
-> g (rl s) -> g (ParserFunctor p g s)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap forall a. rl s a -> ParserFunctor p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
GrammarFunctor (p g s) a -> ParserFunctor p g s a
ParserResultsFunctor)
            addSelf :: g (Const (ParserFlags g)) -> g (Const (ParserFlags g))
addSelf g :: g (Const (ParserFlags g))
g = (forall a.
 Const (g (Const Bool)) a
 -> Const (ParserFlags g) a -> Const (ParserFlags g) a)
-> g (Const (g (Const Bool)))
-> g (Const (ParserFlags g))
-> g (Const (ParserFlags g))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a.
Const (g (Const Bool)) a
-> Const (ParserFlags g) a -> Const (ParserFlags g) a
adjust g (Const (g (Const Bool)))
forall (g :: (* -> *) -> *).
(Distributive g, Traversable g) =>
g (Const (g (Const Bool)))
bits g (Const (ParserFlags g))
g
            adjust :: forall b. Const (g (Const Bool)) b -> Const (ParserFlags g) b -> Const (ParserFlags g) b
            adjust :: Const (g (Const Bool)) b
-> Const (ParserFlags g) b -> Const (ParserFlags g) b
adjust (Const bit :: g (Const Bool)
bit) (Const (ParserFlags n :: Bool
n d :: g (Const Bool)
d)) =
               ParserFlags g -> Const (ParserFlags g) b
forall k a (b :: k). a -> Const a b
Const ParserFlags :: forall (g :: (* -> *) -> *).
Bool -> g (Const Bool) -> ParserFlags g
ParserFlags{
                  nullable :: Bool
nullable= Bool
n, 
                  dependsOn :: g (Const Bool)
dependsOn= (forall a. Const Bool a -> Const Bool a -> Const Bool a)
-> g (Const Bool) -> g (Const Bool) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. Const Bool a -> Const Bool a -> Const Bool a
union g (Const Bool)
bit g (Const Bool)
d}
   {-# INLINE nonTerminal #-}
   recursive :: Fixed p g s a -> Fixed p g s a
recursive = Fixed p g s a -> Fixed p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general

bits :: forall (g :: (* -> *) -> *). (Rank2.Distributive g, Rank2.Traversable g) => g (Const (g (Const Bool)))
bits :: g (Const (g (Const Bool)))
bits = g (Const Int)
start g (Const Int)
-> g (Const (g (Const Bool))) -> g (Const (g (Const Bool)))
forall a b. a -> b -> b
`seq` (forall a. Const Int a -> Const (g (Const Bool)) a)
-> g (Const Int) -> g (Const (g (Const Bool)))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap forall a. Const Int a -> Const (g (Const Bool)) a
oneBit g (Const Int)
start
   where start :: g (Const Int)
start = State Int (g (Const Int)) -> Int -> g (Const Int)
forall s a. State s a -> s -> a
evalState ((forall a. Maybe a -> StateT Int Identity (Const Int a))
-> g Maybe -> State Int (g (Const Int))
forall k (g :: (k -> *) -> *) (m :: * -> *) (p :: k -> *)
       (q :: k -> *).
(Traversable g, Applicative m) =>
(forall (a :: k). p a -> m (q a)) -> g p -> m (g q)
Rank2.traverse forall a. Maybe a -> StateT Int Identity (Const Int a)
forall (f :: * -> *) a. f a -> State Int (Const Int a)
next (Maybe (g Maybe) -> g Maybe
forall (g :: (* -> *) -> *) (f :: * -> *).
(Distributive g, Monad f) =>
f (g f) -> g f
Rank2.distributeJoin Maybe (g Maybe)
forall a. Maybe a
Nothing)) 0
         oneBit :: Const Int a -> Const (g (Const Bool)) a
         next :: f a -> State Int (Const Int a)
         oneBit :: Const Int a -> Const (g (Const Bool)) a
oneBit (Const i :: Int
i) = g (Const Bool) -> Const (g (Const Bool)) a
forall k a (b :: k). a -> Const a b
Const ((forall a. Const Int a -> Const Bool a)
-> g (Const Int) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (Bool -> Const Bool a
forall k a (b :: k). a -> Const a b
Const (Bool -> Const Bool a)
-> (Const Int a -> Bool) -> Const Int a -> Const Bool a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==) (Int -> Bool) -> (Const Int a -> Int) -> Const Int a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const Int a -> Int
forall a k (b :: k). Const a b -> a
getConst) g (Const Int)
start)
         next :: f a -> State Int (Const Int a)
next _ = do {Int
i <- StateT Int Identity Int
forall (m :: * -> *) s. Monad m => StateT s m s
get; let {i' :: Int
i' = Int -> Int
forall a. Enum a => a -> a
succ Int
i}; Int -> StateT Int Identity () -> StateT Int Identity ()
forall a b. a -> b -> b
seq Int
i' (Int -> StateT Int Identity ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put Int
i'); Const Int a -> State Int (Const Int a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Const Int a
forall k a (b :: k). a -> Const a b
Const Int
i)}

instance Functor (p g s) => Functor (Fixed p g s) where
   fmap :: (a -> b) -> Fixed p g s a -> Fixed p g s b
fmap f :: a -> b
f (PositiveDirectParser p :: p g s a
p) = p g s b -> Fixed p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser ((a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f p g s a
p)
   fmap f :: a -> b
f p :: Fixed p g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s b
complete= (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct0 :: p g s b
direct0= (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p),
      direct1 :: p g s b
direct1= (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p)}
   fmap f :: a -> b
f p :: Fixed p g s a
p@Parser{} = Fixed p g s a
p{
      complete :: p g s b
complete= (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct :: p g s b
direct= (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p),
      direct0 :: p g s b
direct0= (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p),
      direct1 :: p g s b
direct1= (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p),
      indirect :: p g s b
indirect= (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p),
      isAmbiguous :: Maybe (AmbiguityWitness b)
isAmbiguous= Maybe (AmbiguityWitness b)
forall a. Maybe a
Nothing}
   {-# INLINABLE fmap #-}

instance Alternative (p g s) => Applicative (Fixed p g s) where
   pure :: a -> Fixed p g s a
pure a :: a
a = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{complete :: p g s a
complete= a -> p g s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a,
                         direct0 :: p g s a
direct0= a -> p g s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a,
                         direct1 :: p g s a
direct1= p g s a
forall (f :: * -> *) a. Alternative f => f a
empty}
   p :: Fixed p g s (a -> b)
p@PositiveDirectParser{} <*> :: Fixed p g s (a -> b) -> Fixed p g s a -> Fixed p g s b
<*> q :: Fixed p g s a
q = PositiveDirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser{
      complete :: p g s b
complete= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s (a -> b)
p p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q}
   p :: Fixed p g s (a -> b)
p@DirectParser{} <*> q :: Fixed p g s a
q@PositiveDirectParser{} = PositiveDirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser{
      complete :: p g s b
complete= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s (a -> b)
p p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q}
   p :: Fixed p g s (a -> b)
p@DirectParser{} <*> q :: Fixed p g s a
q@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s b
complete= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s (a -> b)
p p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q,
      direct0 :: p g s b
direct0= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s (a -> b)
p p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
q,
      direct1 :: p g s b
direct1= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s (a -> b)
p p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
q p g s b -> p g s b -> p g s b
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s (a -> b)
p p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q}
   p :: Fixed p g s (a -> b)
p <*> q :: Fixed p g s a
q@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
      complete :: p g s b
complete= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q,
      direct :: p g s b
direct= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
q p g s b -> p g s b -> p g s b
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q,
      direct0 :: p g s b
direct0= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
q,
      direct1 :: p g s b
direct1= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
q p g s b -> p g s b -> p g s b
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q,
      indirect :: p g s b
indirect= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
q p g s b -> p g s b -> p g s b
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q,
      isAmbiguous :: Maybe (AmbiguityWitness b)
isAmbiguous= Maybe (AmbiguityWitness b)
forall a. Maybe a
Nothing,
      cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \deps :: g (Const (ParserFlags g))
deps-> let
           pcd :: ParserFlags g
pcd@(ParserFlags pn :: Bool
pn pd :: g (Const Bool)
pd) = Fixed p g s (a -> b) -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s (a -> b)
p' g (Const (ParserFlags g))
deps
           ParserFlags qn :: Bool
qn qd :: g (Const Bool)
qd = Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
q g (Const (ParserFlags g))
deps
        in if Bool
pn
           then Bool -> g (Const Bool) -> ParserFlags g
forall (g :: (* -> *) -> *).
Bool -> g (Const Bool) -> ParserFlags g
ParserFlags Bool
qn ((forall a. Const Bool a -> Const Bool a -> Const Bool a)
-> g (Const Bool) -> g (Const Bool) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. Const Bool a -> Const Bool a -> Const Bool a
union g (Const Bool)
pd g (Const Bool)
qd)
           else ParserFlags g
pcd}
      where p' :: Fixed p g s (a -> b)
p'@Parser{} = Fixed p g s (a -> b) -> Fixed p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general' Fixed p g s (a -> b)
p
   p :: Fixed p g s (a -> b)
p <*> q :: Fixed p g s a
q = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
      complete :: p g s b
complete= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q',
      direct :: p g s b
direct= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q',
      direct0 :: p g s b
direct0= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
q',
      direct1 :: p g s b
direct1= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
q' p g s b -> p g s b -> p g s b
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q',
      indirect :: p g s b
indirect= Fixed p g s (a -> b) -> p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s (a -> b)
p' p g s (a -> b) -> p g s a -> p g s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q',
      isAmbiguous :: Maybe (AmbiguityWitness b)
isAmbiguous= Maybe (AmbiguityWitness b)
forall a. Maybe a
Nothing,
      cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \deps :: g (Const (ParserFlags g))
deps-> let
           pcd :: ParserFlags g
pcd@(ParserFlags pn :: Bool
pn pd :: g (Const Bool)
pd) = Fixed p g s (a -> b) -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s (a -> b)
p' g (Const (ParserFlags g))
deps
           ParserFlags qn :: Bool
qn qd :: g (Const Bool)
qd = Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
q' g (Const (ParserFlags g))
deps
        in if Bool
pn
           then Bool -> g (Const Bool) -> ParserFlags g
forall (g :: (* -> *) -> *).
Bool -> g (Const Bool) -> ParserFlags g
ParserFlags Bool
qn ((forall a. Const Bool a -> Const Bool a -> Const Bool a)
-> g (Const Bool) -> g (Const Bool) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. Const Bool a -> Const Bool a -> Const Bool a
union g (Const Bool)
pd g (Const Bool)
qd)
           else ParserFlags g
pcd}
      where p' :: Fixed p g s (a -> b)
p'@Parser{} = Fixed p g s (a -> b) -> Fixed p g s (a -> b)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general' Fixed p g s (a -> b)
p
            q' :: Fixed p g s a
q'@Parser{} = Fixed p g s a -> Fixed p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general' Fixed p g s a
q
   {-# INLINABLE pure #-}
   {-# INLINABLE (<*>) #-}

instance Alternative (p g s) => Alternative (Fixed p g s) where
   empty :: Fixed p g s a
empty = PositiveDirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser{complete :: p g s a
complete= p g s a
forall (f :: * -> *) a. Alternative f => f a
empty}
   p :: Fixed p g s a
p@PositiveDirectParser{} <|> :: Fixed p g s a -> Fixed p g s a -> Fixed p g s a
<|> q :: Fixed p g s a
q@PositiveDirectParser{} = PositiveDirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser{complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q}
   p :: Fixed p g s a
p@PositiveDirectParser{} <|> q :: Fixed p g s a
q@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q,
      direct0 :: p g s a
direct0 = Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
q,
      direct1 :: p g s a
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
q}
   p :: Fixed p g s a
p@DirectParser{} <|> q :: Fixed p g s a
q@PositiveDirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q,
      direct0 :: p g s a
direct0 = Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p,
      direct1 :: p g s a
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q}
   p :: Fixed p g s a
p@DirectParser{} <|> q :: Fixed p g s a
q@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q,
      direct0 :: p g s a
direct0 = Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
q,
      direct1 :: p g s a
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
q}
   p :: Fixed p g s a
p <|> q :: Fixed p g s a
q = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p' p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q',
                    direct :: p g s a
direct= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p' p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
q',
                    direct0 :: p g s a
direct0= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p' p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
q',
                    direct1 :: p g s a
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p' p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
q',
                    indirect :: p g s a
indirect= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p' p g s a -> p g s a -> p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
q',
                    isAmbiguous :: Maybe (AmbiguityWitness a)
isAmbiguous= Maybe (AmbiguityWitness a)
forall a. Maybe a
Nothing,
                    cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \deps :: g (Const (ParserFlags g))
deps-> let
                         ParserFlags pn :: Bool
pn pd :: g (Const Bool)
pd = Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p' g (Const (ParserFlags g))
deps
                         ParserFlags qn :: Bool
qn qd :: g (Const Bool)
qd = Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
q' g (Const (ParserFlags g))
deps
                      in Bool -> g (Const Bool) -> ParserFlags g
forall (g :: (* -> *) -> *).
Bool -> g (Const Bool) -> ParserFlags g
ParserFlags (Bool
pn Bool -> Bool -> Bool
|| Bool
qn) ((forall a. Const Bool a -> Const Bool a -> Const Bool a)
-> g (Const Bool) -> g (Const Bool) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. Const Bool a -> Const Bool a -> Const Bool a
union g (Const Bool)
pd g (Const Bool)
qd)}
      where p' :: Fixed p g s a
p'@Parser{} = Fixed p g s a -> Fixed p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general Fixed p g s a
p
            q' :: Fixed p g s a
q'@Parser{} = Fixed p g s a -> Fixed p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general Fixed p g s a
q
   many :: Fixed p g s a -> Fixed p g s [a]
many (PositiveDirectParser p :: p g s a
p) = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s [a]
complete= p g s a -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many p g s a
p,
      direct0 :: p g s [a]
direct0= [a] -> p g s [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [],
      direct1 :: p g s [a]
direct1= p g s a -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some p g s a
p}
   many p :: Fixed p g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s [a]
complete= p g s a -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct0 :: p g s [a]
direct0= [a] -> p g s [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [] p g s [a] -> p g s [a] -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (a -> [a] -> [a]
forall a. a -> [a] -> [a]
:[]) (a -> [a]) -> p g s a -> p g s [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p,
      direct1 :: p g s [a]
direct1= (:) (a -> [a] -> [a]) -> p g s a -> p g s ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s ([a] -> [a]) -> p g s [a] -> p g s [a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> p g s a -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p)}
   many p :: Fixed p g s a
p@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
      complete :: p g s [a]
complete= p g s [a]
mcp,
      direct :: p g s [a]
direct= p g s [a]
d0 p g s [a] -> p g s [a] -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> p g s [a]
d1,
      direct0 :: p g s [a]
direct0= p g s [a]
d0,
      direct1 :: p g s [a]
direct1= p g s [a]
d1,
      indirect :: p g s [a]
indirect= (:) (a -> [a] -> [a]) -> p g s a -> p g s ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p p g s ([a] -> [a]) -> p g s [a] -> p g s [a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> p g s [a]
mcp,
      isAmbiguous :: Maybe (AmbiguityWitness [a])
isAmbiguous= Maybe (AmbiguityWitness [a])
forall a. Maybe a
Nothing,
      cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \deps :: g (Const (ParserFlags g))
deps-> (Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p g (Const (ParserFlags g))
deps){nullable :: Bool
nullable= Bool
True}}
      where d0 :: p g s [a]
d0 = [a] -> p g s [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [] p g s [a] -> p g s [a] -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (a -> [a] -> [a]
forall a. a -> [a] -> [a]
:[]) (a -> [a]) -> p g s a -> p g s [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p
            d1 :: p g s [a]
d1 = (:) (a -> [a] -> [a]) -> p g s a -> p g s ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s ([a] -> [a]) -> p g s [a] -> p g s [a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> p g s [a]
mcp
            mcp :: p g s [a]
mcp = p g s a -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p)
   some :: Fixed p g s a -> Fixed p g s [a]
some (PositiveDirectParser p :: p g s a
p) = PositiveDirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser{complete :: p g s [a]
complete= p g s a -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some p g s a
p}
   some p :: Fixed p g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s [a]
complete= p g s a -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct0 :: p g s [a]
direct0= (a -> [a] -> [a]
forall a. a -> [a] -> [a]
:[]) (a -> [a]) -> p g s a -> p g s [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p,
      direct1 :: p g s [a]
direct1= (:) (a -> [a] -> [a]) -> p g s a -> p g s ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s ([a] -> [a]) -> p g s [a] -> p g s [a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> p g s a -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p)}
   some p :: Fixed p g s a
p@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
      complete :: p g s [a]
complete= p g s a -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct :: p g s [a]
direct= p g s [a]
d0 p g s [a] -> p g s [a] -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> p g s [a]
d1,
      direct0 :: p g s [a]
direct0= p g s [a]
d0,
      direct1 :: p g s [a]
direct1= p g s [a]
d1,
      indirect :: p g s [a]
indirect= (:) (a -> [a] -> [a]) -> p g s a -> p g s ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p p g s ([a] -> [a]) -> p g s [a] -> p g s [a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> p g s a -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      isAmbiguous :: Maybe (AmbiguityWitness [a])
isAmbiguous= Maybe (AmbiguityWitness [a])
forall a. Maybe a
Nothing,
      cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p}
      where d0 :: p g s [a]
d0 = (a -> [a] -> [a]
forall a. a -> [a] -> [a]
:[]) (a -> [a]) -> p g s a -> p g s [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p
            d1 :: p g s [a]
d1= (:) (a -> [a] -> [a]) -> p g s a -> p g s ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s ([a] -> [a]) -> p g s [a] -> p g s [a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> p g s a -> p g s [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p)
   {-# INLINABLE (<|>) #-}
   {-# INLINABLE many #-}
   {-# INLINABLE some #-}

union :: Const Bool x -> Const Bool x -> Const Bool x
union :: Const Bool x -> Const Bool x -> Const Bool x
union (Const False) d :: Const Bool x
d = Const Bool x
d
union (Const True) _ = Bool -> Const Bool x
forall k a (b :: k). a -> Const a b
Const Bool
True

instance (Alternative (p g s), Monad (p g s)) => Monad (Fixed p g s) where
   return :: a -> Fixed p g s a
return = a -> Fixed p g s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
   >> :: Fixed p g s a -> Fixed p g s b -> Fixed p g s b
(>>) = Fixed p g s a -> Fixed p g s b -> Fixed p g s b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
   PositiveDirectParser p :: p g s a
p >>= :: Fixed p g s a -> (a -> Fixed p g s b) -> Fixed p g s b
>>= cont :: a -> Fixed p g s b
cont = p g s b -> Fixed p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser (p g s a
p p g s a -> (a -> p g s b) -> p g s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Fixed p g s b -> p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete (Fixed p g s b -> p g s b) -> (a -> Fixed p g s b) -> a -> p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Fixed p g s b
cont)
   p :: Fixed p g s a
p@DirectParser{} >>= cont :: a -> Fixed p g s b
cont = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
      complete :: p g s b
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p p g s a -> (a -> p g s b) -> p g s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Fixed p g s b -> p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete (Fixed p g s b -> p g s b) -> (a -> Fixed p g s b) -> a -> p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Fixed p g s b
cont,
      direct :: p g s b
direct= p g s b
d0 p g s b -> p g s b -> p g s b
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> p g s b
d1,
      direct0 :: p g s b
direct0= p g s b
d0,
      direct1 :: p g s b
direct1= p g s b
d1,
      indirect :: p g s b
indirect= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s a -> (a -> p g s b) -> p g s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Fixed p g s b -> p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect (Fixed p g s b -> p g s b) -> (a -> Fixed p g s b) -> a -> p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixed p g s b -> Fixed p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general' (Fixed p g s b -> Fixed p g s b)
-> (a -> Fixed p g s b) -> a -> Fixed p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Fixed p g s b
cont,
      isAmbiguous :: Maybe (AmbiguityWitness b)
isAmbiguous= Maybe (AmbiguityWitness b)
forall a. Maybe a
Nothing,
      cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \cd :: g (Const (ParserFlags g))
cd-> (Bool -> g (Const Bool) -> ParserFlags g
forall (g :: (* -> *) -> *).
Bool -> g (Const Bool) -> ParserFlags g
ParserFlags Bool
True (g (Const Bool) -> ParserFlags g)
-> g (Const Bool) -> ParserFlags g
forall a b. (a -> b) -> a -> b
$ (forall a. Const (ParserFlags g) a -> Const Bool a)
-> g (Const (ParserFlags g)) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (Const Bool a -> Const (ParserFlags g) a -> Const Bool a
forall a b. a -> b -> a
const (Const Bool a -> Const (ParserFlags g) a -> Const Bool a)
-> Const Bool a -> Const (ParserFlags g) a -> Const Bool a
forall a b. (a -> b) -> a -> b
$ Bool -> Const Bool a
forall k a (b :: k). a -> Const a b
Const Bool
True) g (Const (ParserFlags g))
cd)}
      where d0 :: p g s b
d0 = Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s a -> (a -> p g s b) -> p g s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Fixed p g s b -> p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 (Fixed p g s b -> p g s b) -> (a -> Fixed p g s b) -> a -> p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixed p g s b -> Fixed p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general' (Fixed p g s b -> Fixed p g s b)
-> (a -> Fixed p g s b) -> a -> Fixed p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Fixed p g s b
cont
            d1 :: p g s b
d1 = (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s a -> (a -> p g s b) -> p g s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Fixed p g s b -> p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 (Fixed p g s b -> p g s b) -> (a -> Fixed p g s b) -> a -> p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixed p g s b -> Fixed p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general' (Fixed p g s b -> Fixed p g s b)
-> (a -> Fixed p g s b) -> a -> Fixed p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Fixed p g s b
cont) p g s b -> p g s b -> p g s b
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s a -> (a -> p g s b) -> p g s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Fixed p g s b -> p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete (Fixed p g s b -> p g s b) -> (a -> Fixed p g s b) -> a -> p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Fixed p g s b
cont)
   p :: Fixed p g s a
p >>= cont :: a -> Fixed p g s b
cont = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
      complete :: p g s b
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p p g s a -> (a -> p g s b) -> p g s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Fixed p g s b -> p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete (Fixed p g s b -> p g s b) -> (a -> Fixed p g s b) -> a -> p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Fixed p g s b
cont,
      direct :: p g s b
direct= p g s b
d0 p g s b -> p g s b -> p g s b
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> p g s b
d1,
      direct0 :: p g s b
direct0= p g s b
d0,
      direct1 :: p g s b
direct1= p g s b
d1,
      indirect :: p g s b
indirect= (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p p g s a -> (a -> p g s b) -> p g s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Fixed p g s b -> p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete (Fixed p g s b -> p g s b) -> (a -> Fixed p g s b) -> a -> p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Fixed p g s b
cont) p g s b -> p g s b -> p g s b
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s a -> (a -> p g s b) -> p g s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Fixed p g s b -> p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect (Fixed p g s b -> p g s b) -> (a -> Fixed p g s b) -> a -> p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixed p g s b -> Fixed p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general' (Fixed p g s b -> Fixed p g s b)
-> (a -> Fixed p g s b) -> a -> Fixed p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Fixed p g s b
cont),
      isAmbiguous :: Maybe (AmbiguityWitness b)
isAmbiguous= Maybe (AmbiguityWitness b)
forall a. Maybe a
Nothing,
      cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \cd :: g (Const (ParserFlags g))
cd->
         let pcd :: ParserFlags g
pcd@(ParserFlags pn :: Bool
pn _) = Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p' g (Const (ParserFlags g))
cd
         in if Bool
pn
            then Bool -> g (Const Bool) -> ParserFlags g
forall (g :: (* -> *) -> *).
Bool -> g (Const Bool) -> ParserFlags g
ParserFlags Bool
True ((forall a. Const (ParserFlags g) a -> Const Bool a)
-> g (Const (ParserFlags g)) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (Const Bool a -> Const (ParserFlags g) a -> Const Bool a
forall a b. a -> b -> a
const (Const Bool a -> Const (ParserFlags g) a -> Const Bool a)
-> Const Bool a -> Const (ParserFlags g) a -> Const Bool a
forall a b. (a -> b) -> a -> b
$ Bool -> Const Bool a
forall k a (b :: k). a -> Const a b
Const Bool
True) g (Const (ParserFlags g))
cd)
            else ParserFlags g
pcd}
      where d0 :: p g s b
d0 = Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s a -> (a -> p g s b) -> p g s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Fixed p g s b -> p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 (Fixed p g s b -> p g s b) -> (a -> Fixed p g s b) -> a -> p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixed p g s b -> Fixed p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general' (Fixed p g s b -> Fixed p g s b)
-> (a -> Fixed p g s b) -> a -> Fixed p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Fixed p g s b
cont
            d1 :: p g s b
d1 = (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s a -> (a -> p g s b) -> p g s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Fixed p g s b -> p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 (Fixed p g s b -> p g s b) -> (a -> Fixed p g s b) -> a -> p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixed p g s b -> Fixed p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general' (Fixed p g s b -> Fixed p g s b)
-> (a -> Fixed p g s b) -> a -> Fixed p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Fixed p g s b
cont) p g s b -> p g s b -> p g s b
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s a -> (a -> p g s b) -> p g s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Fixed p g s b -> p g s b
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete (Fixed p g s b -> p g s b) -> (a -> Fixed p g s b) -> a -> p g s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Fixed p g s b
cont)
            p' :: Fixed p g s a
p'@Parser{} = Fixed p g s a -> Fixed p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general' Fixed p g s a
p

instance MonadPlus (p g s) => MonadPlus (Fixed p g s) where
   mzero :: Fixed p g s a
mzero = Fixed p g s a
forall (f :: * -> *) a. Alternative f => f a
empty
   mplus :: Fixed p g s a -> Fixed p g s a -> Fixed p g s a
mplus = Fixed p g s a -> Fixed p g s a -> Fixed p g s a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>)

instance (Alternative (p g s), Semigroup x) => Semigroup (Fixed p g s x) where
   <> :: Fixed p g s x -> Fixed p g s x -> Fixed p g s x
(<>) = (x -> x -> x) -> Fixed p g s x -> Fixed p g s x -> Fixed p g s x
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 x -> x -> x
forall a. Semigroup a => a -> a -> a
(<>)

instance (Alternative (p g s), Monoid x) => Monoid (Fixed p g s x) where
   mempty :: Fixed p g s x
mempty = x -> Fixed p g s x
forall (f :: * -> *) a. Applicative f => a -> f a
pure x
forall a. Monoid a => a
mempty
   mappend :: Fixed p g s x -> Fixed p g s x -> Fixed p g s x
mappend = (x -> x -> x) -> Fixed p g s x -> Fixed p g s x -> Fixed p g s x
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 x -> x -> x
forall a. Monoid a => a -> a -> a
mappend

primitive :: p g s a -> p g s a -> p g s a -> Fixed p g s a
primitive :: p g s a -> p g s a -> p g s a -> Fixed p g s a
primitive d0 :: p g s a
d0 d1 :: p g s a
d1 d :: p g s a
d = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{complete :: p g s a
complete= p g s a
d,
                                 direct0 :: p g s a
direct0= p g s a
d0,
                                 direct1 :: p g s a
direct1= p g s a
d1}
{-# INLINE primitive #-}

-- | Lifts a primitive positive parser (/i.e./, one that always consumes some input) into a left-recursive one
liftPositive :: p g s a -> Fixed p g s a
liftPositive :: p g s a -> Fixed p g s a
liftPositive p :: p g s a
p = PositiveDirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser{complete :: p g s a
complete= p g s a
p}
{-# INLINE liftPositive #-}

-- | Lifts a primitive pure parser (/i.e./, one that consumes no input) into a left-recursive one
liftPure :: Alternative (p g s) => p g s a -> Fixed p g s a
liftPure :: p g s a -> Fixed p g s a
liftPure p :: p g s a
p = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{complete :: p g s a
complete= p g s a
p,
                          direct0 :: p g s a
direct0= p g s a
p,
                          direct1 :: p g s a
direct1= p g s a
forall (f :: * -> *) a. Alternative f => f a
empty}
{-# INLINE liftPure #-}

instance (Parsing (p g s), InputParsing (Fixed p g s)) => Parsing (Fixed p g s) where
   eof :: Fixed p g s ()
eof = p g s () -> p g s () -> p g s () -> Fixed p g s ()
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
primitive p g s ()
forall (m :: * -> *). Parsing m => m ()
eof p g s ()
forall (f :: * -> *) a. Alternative f => f a
empty p g s ()
forall (m :: * -> *). Parsing m => m ()
eof
   try :: Fixed p g s a -> Fixed p g s a
try (PositiveDirectParser p :: p g s a
p) = p g s a -> Fixed p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser (p g s a -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> m a
try p g s a
p)
   try p :: Fixed p g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s a
complete= p g s a -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct0 :: p g s a
direct0= p g s a -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p),
      direct1 :: p g s a
direct1= p g s a -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p)}
   try p :: Fixed p g s a
p@Parser{} = Fixed p g s a
p{
      complete :: p g s a
complete= p g s a -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct :: p g s a
direct= p g s a -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p),
      direct0 :: p g s a
direct0= p g s a -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p),
      direct1 :: p g s a
direct1= p g s a -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p),
      indirect :: p g s a
indirect= p g s a -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p)}
   PositiveDirectParser p :: p g s a
p <?> :: Fixed p g s a -> String -> Fixed p g s a
<?> msg :: String
msg = p g s a -> Fixed p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser (p g s a
p p g s a -> String -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
msg)
   p :: Fixed p g s a
p@DirectParser{} <?> msg :: String
msg = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p p g s a -> String -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
msg,
      direct0 :: p g s a
direct0= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s a -> String -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
msg,
      direct1 :: p g s a
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s a -> String -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
msg}
   p :: Fixed p g s a
p@Parser{} <?> msg :: String
msg = Fixed p g s a
p{
      complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p p g s a -> String -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
msg,
      direct :: p g s a
direct= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p p g s a -> String -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
msg,
      direct0 :: p g s a
direct0= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s a -> String -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
msg,
      direct1 :: p g s a
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s a -> String -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
msg,
      indirect :: p g s a
indirect= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p p g s a -> String -> p g s a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
msg}
   notFollowedBy :: Fixed p g s a -> Fixed p g s ()
notFollowedBy p :: Fixed p g s a
p@PositiveDirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s ()
complete= p g s a -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct0 :: p g s ()
direct0= p g s a -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct1 :: p g s ()
direct1= p g s ()
forall (f :: * -> *) a. Alternative f => f a
empty}
   notFollowedBy p :: Fixed p g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s ()
complete= p g s a -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct0 :: p g s ()
direct0= p g s a -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct1 :: p g s ()
direct1= p g s ()
forall (f :: * -> *) a. Alternative f => f a
empty}
   notFollowedBy p :: Fixed p g s a
p@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
      complete :: p g s ()
complete= p g s a -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct :: p g s ()
direct= p g s a -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p),
      direct0 :: p g s ()
direct0= p g s a -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p),
      direct1 :: p g s ()
direct1= p g s ()
forall (f :: * -> *) a. Alternative f => f a
empty,
      isAmbiguous :: Maybe (AmbiguityWitness ())
isAmbiguous= Maybe (AmbiguityWitness ())
forall a. Maybe a
Nothing,
      indirect :: p g s ()
indirect= p g s a -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p),
      cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \deps :: g (Const (ParserFlags g))
deps-> (Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p g (Const (ParserFlags g))
deps){nullable :: Bool
nullable= Bool
True}}
   unexpected :: String -> Fixed p g s a
unexpected msg :: String
msg = p g s a -> Fixed p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
liftPositive (String -> p g s a
forall (m :: * -> *) a. Parsing m => String -> m a
unexpected String
msg)

instance (InputParsing (Fixed p g s), DeterministicParsing (p g s)) => DeterministicParsing (Fixed p g s) where
   p :: Fixed p g s a
p@DirectParser{} <<|> :: Fixed p g s a -> Fixed p g s a -> Fixed p g s a
<<|> q :: Fixed p g s a
q@PositiveDirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q,
      direct0 :: p g s a
direct0 = Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p,
      direct1 :: p g s a
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q}
   p :: Fixed p g s a
p@DirectParser{} <<|> q :: Fixed p g s a
q@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q,
      direct0 :: p g s a
direct0 = Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
q,
      direct1 :: p g s a
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s a -> p g s a -> p g s a
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
q}
   p :: Fixed p g s a
p <<|> q :: Fixed p g s a
q = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{complete :: p g s a
complete= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p' p g s a -> p g s a -> p g s a
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
q',
                    direct :: p g s a
direct= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p' p g s a -> p g s a -> p g s a
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
q',
                    direct0 :: p g s a
direct0= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p' p g s a -> p g s a -> p g s a
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
q',
                    direct1 :: p g s a
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p' p g s a -> p g s a -> p g s a
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
q',
                    indirect :: p g s a
indirect= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p' p g s a -> p g s a -> p g s a
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
q',
                    isAmbiguous :: Maybe (AmbiguityWitness a)
isAmbiguous= Maybe (AmbiguityWitness a)
forall a. Maybe a
Nothing,
                    cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \deps :: g (Const (ParserFlags g))
deps-> let
                            ParserFlags pn :: Bool
pn pd :: g (Const Bool)
pd = Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p' g (Const (ParserFlags g))
deps
                            ParserFlags qn :: Bool
qn qd :: g (Const Bool)
qd = Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
q' g (Const (ParserFlags g))
deps
                         in Bool -> g (Const Bool) -> ParserFlags g
forall (g :: (* -> *) -> *).
Bool -> g (Const Bool) -> ParserFlags g
ParserFlags (Bool
pn Bool -> Bool -> Bool
|| Bool
qn) ((forall a. Const Bool a -> Const Bool a -> Const Bool a)
-> g (Const Bool) -> g (Const Bool) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. Const Bool a -> Const Bool a -> Const Bool a
union g (Const Bool)
pd g (Const Bool)
qd)}
      where p' :: Fixed p g s a
p'@Parser{} = Fixed p g s a -> Fixed p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general Fixed p g s a
p
            q' :: Fixed p g s a
q'@Parser{} = Fixed p g s a -> Fixed p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general Fixed p g s a
q
   takeSome :: Fixed p g s a -> Fixed p g s [a]
takeSome p :: Fixed p g s a
p = (:) (a -> [a] -> [a]) -> Fixed p g s a -> Fixed p g s ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a
p Fixed p g s ([a] -> [a]) -> Fixed p g s [a] -> Fixed p g s [a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Fixed p g s a -> Fixed p g s [a]
forall (m :: * -> *) a. DeterministicParsing m => m a -> m [a]
takeMany Fixed p g s a
p
   takeMany :: Fixed p g s a -> Fixed p g s [a]
takeMany (PositiveDirectParser p :: p g s a
p) = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s [a]
complete = p g s a -> p g s [a]
forall (m :: * -> *) a. DeterministicParsing m => m a -> m [a]
takeMany p g s a
p,
      direct0 :: p g s [a]
direct0= [] [a] -> p g s () -> p g s [a]
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ p g s () -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (p g s a -> p g s ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void p g s a
p),
      direct1 :: p g s [a]
direct1= p g s a -> p g s [a]
forall (m :: * -> *) a. DeterministicParsing m => m a -> m [a]
takeSome p g s a
p}
   takeMany p :: Fixed p g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s [a]
complete = p g s a -> p g s [a]
forall (m :: * -> *) a. DeterministicParsing m => m a -> m [a]
takeMany (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct0 :: p g s [a]
direct0= (a -> [a] -> [a]
forall a. a -> [a] -> [a]
:[]) (a -> [a]) -> p g s a -> p g s [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s [a] -> p g s [a] -> p g s [a]
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> [] [a] -> p g s () -> p g s [a]
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ p g s () -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (p g s a -> p g s ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (p g s a -> p g s ()) -> p g s a -> p g s ()
forall a b. (a -> b) -> a -> b
$ Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct1 :: p g s [a]
direct1= (:) (a -> [a] -> [a]) -> p g s a -> p g s ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s ([a] -> [a]) -> p g s [a] -> p g s [a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> p g s a -> p g s [a]
forall (m :: * -> *) a. DeterministicParsing m => m a -> m [a]
takeMany (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p)}
   takeMany p :: Fixed p g s a
p@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
      complete :: p g s [a]
complete= p g s [a]
mcp,
      direct :: p g s [a]
direct= p g s [a]
d1 p g s [a] -> p g s [a] -> p g s [a]
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> p g s [a]
d0,
      direct0 :: p g s [a]
direct0= p g s [a]
d0,
      direct1 :: p g s [a]
direct1= p g s [a]
d1,
      indirect :: p g s [a]
indirect= (:) (a -> [a] -> [a]) -> p g s a -> p g s ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p p g s ([a] -> [a]) -> p g s [a] -> p g s [a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> p g s [a]
mcp,
      isAmbiguous :: Maybe (AmbiguityWitness [a])
isAmbiguous= Maybe (AmbiguityWitness [a])
forall a. Maybe a
Nothing,
      cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \deps :: g (Const (ParserFlags g))
deps-> (Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p g (Const (ParserFlags g))
deps){nullable :: Bool
nullable= Bool
True}}
      where d0 :: p g s [a]
d0 = (a -> [a] -> [a]
forall a. a -> [a] -> [a]
:[]) (a -> [a]) -> p g s a -> p g s [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s [a] -> p g s [a] -> p g s [a]
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> [] [a] -> p g s () -> p g s [a]
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ p g s () -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (p g s a -> p g s ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (p g s a -> p g s ()) -> p g s a -> p g s ()
forall a b. (a -> b) -> a -> b
$ Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p)
            d1 :: p g s [a]
d1 = (:) (a -> [a] -> [a]) -> p g s a -> p g s ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s ([a] -> [a]) -> p g s [a] -> p g s [a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> p g s [a]
mcp
            mcp :: p g s [a]
mcp = p g s a -> p g s [a]
forall (m :: * -> *) a. DeterministicParsing m => m a -> m [a]
takeMany (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p)
   skipAll :: Fixed p g s a -> Fixed p g s ()
skipAll (PositiveDirectParser p :: p g s a
p) = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s ()
complete = p g s a -> p g s ()
forall (m :: * -> *) a. DeterministicParsing m => m a -> m ()
skipAll p g s a
p,
      direct0 :: p g s ()
direct0= () () -> p g s () -> p g s ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ p g s () -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (p g s a -> p g s ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void p g s a
p),
      direct1 :: p g s ()
direct1= p g s a
p p g s a -> p g s () -> p g s ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> p g s a -> p g s ()
forall (m :: * -> *) a. DeterministicParsing m => m a -> m ()
skipAll p g s a
p}
   skipAll p :: Fixed p g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s ()
complete = p g s a -> p g s ()
forall (m :: * -> *) a. DeterministicParsing m => m a -> m ()
skipAll (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct0 :: p g s ()
direct0= p g s a -> p g s ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p) p g s () -> p g s () -> p g s ()
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> p g s () -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (p g s a -> p g s ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (p g s a -> p g s ()) -> p g s a -> p g s ()
forall a b. (a -> b) -> a -> b
$ Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct1 :: p g s ()
direct1= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s a -> p g s () -> p g s ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> p g s a -> p g s ()
forall (m :: * -> *) a. DeterministicParsing m => m a -> m ()
skipAll (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p)}
   skipAll p :: Fixed p g s a
p@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
      complete :: p g s ()
complete= p g s ()
mcp,
      direct :: p g s ()
direct= p g s ()
d1 p g s () -> p g s () -> p g s ()
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> p g s ()
d0,
      direct0 :: p g s ()
direct0= p g s ()
d0,
      direct1 :: p g s ()
direct1= p g s ()
d1,
      indirect :: p g s ()
indirect= Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p p g s a -> p g s () -> p g s ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> p g s ()
mcp,
      isAmbiguous :: Maybe (AmbiguityWitness ())
isAmbiguous= Maybe (AmbiguityWitness ())
forall a. Maybe a
Nothing,
      cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \deps :: g (Const (ParserFlags g))
deps-> (Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p g (Const (ParserFlags g))
deps){nullable :: Bool
nullable= Bool
True}}
      where d0 :: p g s ()
d0 = () () -> p g s a -> p g s ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p p g s () -> p g s () -> p g s ()
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> p g s () -> p g s ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (p g s a -> p g s ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (p g s a -> p g s ()) -> p g s a -> p g s ()
forall a b. (a -> b) -> a -> b
$ Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p)
            d1 :: p g s ()
d1 = Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p p g s a -> p g s () -> p g s ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> p g s ()
mcp
            mcp :: p g s ()
mcp = p g s a -> p g s ()
forall (m :: * -> *) a. DeterministicParsing m => m a -> m ()
skipAll (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p)

instance (LookAheadParsing (p g s), InputParsing (Fixed p g s)) => LookAheadParsing (Fixed p g s) where
   lookAhead :: Fixed p g s a -> Fixed p g s a
lookAhead p :: Fixed p g s a
p@PositiveDirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s a
complete= p g s a -> p g s a
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct0 :: p g s a
direct0= p g s a -> p g s a
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct1 :: p g s a
direct1= p g s a
forall (f :: * -> *) a. Alternative f => f a
empty}
   lookAhead p :: Fixed p g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s a
complete= p g s a -> p g s a
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct0 :: p g s a
direct0= p g s a -> p g s a
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct1 :: p g s a
direct1= p g s a
forall (f :: * -> *) a. Alternative f => f a
empty}
   lookAhead p :: Fixed p g s a
p@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
      complete :: p g s a
complete= p g s a -> p g s a
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct :: p g s a
direct= p g s a -> p g s a
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p),
      direct0 :: p g s a
direct0= p g s a -> p g s a
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p),
      direct1 :: p g s a
direct1= p g s a
forall (f :: * -> *) a. Alternative f => f a
empty,
      isAmbiguous :: Maybe (AmbiguityWitness a)
isAmbiguous= Fixed p g s a -> Maybe (AmbiguityWitness a)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> Maybe (AmbiguityWitness a)
isAmbiguous Fixed p g s a
p,
      indirect :: p g s a
indirect= p g s a -> p g s a
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p),
      cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= \deps :: g (Const (ParserFlags g))
deps-> (Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p g (Const (ParserFlags g))
deps){nullable :: Bool
nullable= Bool
True}}

instance (LeftReductive s, FactorialMonoid s, InputParsing (p g s), ParserInput (p g s) ~ s) =>
         InputParsing (Fixed p g s) where
   type ParserInput (Fixed p g s) = s
   getInput :: Fixed p g s (ParserInput (Fixed p g s))
getInput = p g s s -> p g s s -> p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
primitive p g s s
forall (m :: * -> *). InputParsing m => m (ParserInput m)
getInput p g s s
forall (f :: * -> *) a. Alternative f => f a
empty p g s s
forall (m :: * -> *). InputParsing m => m (ParserInput m)
getInput
   anyToken :: Fixed p g s (ParserInput (Fixed p g s))
anyToken = p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
liftPositive p g s s
forall (m :: * -> *). InputParsing m => m (ParserInput m)
anyToken
   satisfy :: (ParserInput (Fixed p g s) -> Bool)
-> Fixed p g s (ParserInput (Fixed p g s))
satisfy predicate :: ParserInput (Fixed p g s) -> Bool
predicate = p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
liftPositive ((ParserInput (p g s) -> Bool) -> p g s (ParserInput (p g s))
forall (m :: * -> *).
InputParsing m =>
(ParserInput m -> Bool) -> m (ParserInput m)
satisfy ParserInput (p g s) -> Bool
ParserInput (Fixed p g s) -> Bool
predicate)
   notSatisfy :: (ParserInput (Fixed p g s) -> Bool) -> Fixed p g s ()
notSatisfy predicate :: ParserInput (Fixed p g s) -> Bool
predicate = p g s () -> p g s () -> p g s () -> Fixed p g s ()
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
primitive ((ParserInput (p g s) -> Bool) -> p g s ()
forall (m :: * -> *).
InputParsing m =>
(ParserInput m -> Bool) -> m ()
notSatisfy ParserInput (p g s) -> Bool
ParserInput (Fixed p g s) -> Bool
predicate) p g s ()
forall (f :: * -> *) a. Alternative f => f a
empty ((ParserInput (p g s) -> Bool) -> p g s ()
forall (m :: * -> *).
InputParsing m =>
(ParserInput m -> Bool) -> m ()
notSatisfy ParserInput (p g s) -> Bool
ParserInput (Fixed p g s) -> Bool
predicate)
   scan :: state
-> (state -> ParserInput (Fixed p g s) -> Maybe state)
-> Fixed p g s (ParserInput (Fixed p g s))
scan s0 :: state
s0 f :: state -> ParserInput (Fixed p g s) -> Maybe state
f = p g s s -> p g s s -> p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
primitive (s
forall a. Monoid a => a
mempty s -> p g s () -> p g s s
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParserInput (p g s) -> Bool) -> p g s ()
forall (m :: * -> *).
InputParsing m =>
(ParserInput m -> Bool) -> m ()
notSatisfy s -> Bool
ParserInput (p g s) -> Bool
test) (p g s s -> p g s s
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead ((ParserInput (p g s) -> Bool) -> p g s (ParserInput (p g s))
forall (m :: * -> *).
InputParsing m =>
(ParserInput m -> Bool) -> m (ParserInput m)
satisfy s -> Bool
ParserInput (p g s) -> Bool
test) p g s s -> p g s s -> p g s s
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> p g s s
p g s (ParserInput (p g s))
p) p g s s
p g s (ParserInput (p g s))
p
      where p :: p g s (ParserInput (p g s))
p = state
-> (state -> ParserInput (p g s) -> Maybe state)
-> p g s (ParserInput (p g s))
forall (m :: * -> *) state.
InputParsing m =>
state
-> (state -> ParserInput m -> Maybe state) -> m (ParserInput m)
scan state
s0 state -> ParserInput (p g s) -> Maybe state
state -> ParserInput (Fixed p g s) -> Maybe state
f
            test :: s -> Bool
test = Maybe state -> Bool
forall a. Maybe a -> Bool
isJust (Maybe state -> Bool) -> (s -> Maybe state) -> s -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. state -> ParserInput (Fixed p g s) -> Maybe state
f state
s0
   string :: ParserInput (Fixed p g s)
-> Fixed p g s (ParserInput (Fixed p g s))
string s :: ParserInput (Fixed p g s)
s
      | s -> Bool
forall m. MonoidNull m => m -> Bool
null s
ParserInput (Fixed p g s)
s = p g s s -> p g s s -> p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
primitive (ParserInput (p g s) -> p g s (ParserInput (p g s))
forall (m :: * -> *).
InputParsing m =>
ParserInput m -> m (ParserInput m)
string ParserInput (p g s)
ParserInput (Fixed p g s)
s) p g s s
forall (f :: * -> *) a. Alternative f => f a
empty (ParserInput (p g s) -> p g s (ParserInput (p g s))
forall (m :: * -> *).
InputParsing m =>
ParserInput m -> m (ParserInput m)
string ParserInput (p g s)
ParserInput (Fixed p g s)
s)
      | Bool
otherwise = p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
liftPositive (ParserInput (p g s) -> p g s (ParserInput (p g s))
forall (m :: * -> *).
InputParsing m =>
ParserInput m -> m (ParserInput m)
string ParserInput (p g s)
ParserInput (Fixed p g s)
s)
   take :: Int -> Fixed p g s (ParserInput (Fixed p g s))
take 0 = Fixed p g s (ParserInput (Fixed p g s))
forall a. Monoid a => a
mempty
   take n :: Int
n = p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
liftPositive (Int -> p g s (ParserInput (p g s))
forall (m :: * -> *). InputParsing m => Int -> m (ParserInput m)
take Int
n)
   takeWhile :: (ParserInput (Fixed p g s) -> Bool)
-> Fixed p g s (ParserInput (Fixed p g s))
takeWhile predicate :: ParserInput (Fixed p g s) -> Bool
predicate = p g s s -> p g s s -> p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
primitive (s
forall a. Monoid a => a
mempty s -> p g s () -> p g s s
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParserInput (p g s) -> Bool) -> p g s ()
forall (m :: * -> *).
InputParsing m =>
(ParserInput m -> Bool) -> m ()
notSatisfy ParserInput (p g s) -> Bool
ParserInput (Fixed p g s) -> Bool
predicate)
                                               ((ParserInput (p g s) -> Bool) -> p g s (ParserInput (p g s))
forall (m :: * -> *).
InputParsing m =>
(ParserInput m -> Bool) -> m (ParserInput m)
takeWhile1 ParserInput (p g s) -> Bool
ParserInput (Fixed p g s) -> Bool
predicate) ((ParserInput (p g s) -> Bool) -> p g s (ParserInput (p g s))
forall (m :: * -> *).
InputParsing m =>
(ParserInput m -> Bool) -> m (ParserInput m)
takeWhile ParserInput (p g s) -> Bool
ParserInput (Fixed p g s) -> Bool
predicate)
   takeWhile1 :: (ParserInput (Fixed p g s) -> Bool)
-> Fixed p g s (ParserInput (Fixed p g s))
takeWhile1 predicate :: ParserInput (Fixed p g s) -> Bool
predicate = p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
liftPositive ((ParserInput (p g s) -> Bool) -> p g s (ParserInput (p g s))
forall (m :: * -> *).
InputParsing m =>
(ParserInput m -> Bool) -> m (ParserInput m)
takeWhile1 ParserInput (p g s) -> Bool
ParserInput (Fixed p g s) -> Bool
predicate)
   {-# INLINABLE string #-}

instance (LeftReductive s, FactorialMonoid s,
          ConsumedInputParsing (p g s), ParserInput (p g s) ~ s) => ConsumedInputParsing (Fixed p g s) where
   match :: Fixed p g s a -> Fixed p g s (ParserInput (Fixed p g s), a)
match (PositiveDirectParser p :: p g s a
p) = p g s (s, a) -> Fixed p g s (s, a)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser (p g s a -> p g s (ParserInput (p g s), a)
forall (m :: * -> *) a.
ConsumedInputParsing m =>
m a -> m (ParserInput m, a)
match p g s a
p)
   match p :: Fixed p g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{
      complete :: p g s (s, a)
complete= p g s a -> p g s (ParserInput (p g s), a)
forall (m :: * -> *) a.
ConsumedInputParsing m =>
m a -> m (ParserInput m, a)
match (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct0 :: p g s (s, a)
direct0 = p g s a -> p g s (ParserInput (p g s), a)
forall (m :: * -> *) a.
ConsumedInputParsing m =>
m a -> m (ParserInput m, a)
match (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p),
      direct1 :: p g s (s, a)
direct1 = p g s a -> p g s (ParserInput (p g s), a)
forall (m :: * -> *) a.
ConsumedInputParsing m =>
m a -> m (ParserInput m, a)
match (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p)}
   match p :: Fixed p g s a
p@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{
      complete :: p g s (s, a)
complete= p g s a -> p g s (ParserInput (p g s), a)
forall (m :: * -> *) a.
ConsumedInputParsing m =>
m a -> m (ParserInput m, a)
match (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
      direct :: p g s (s, a)
direct =  p g s a -> p g s (ParserInput (p g s), a)
forall (m :: * -> *) a.
ConsumedInputParsing m =>
m a -> m (ParserInput m, a)
match (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p),
      direct0 :: p g s (s, a)
direct0 = p g s a -> p g s (ParserInput (p g s), a)
forall (m :: * -> *) a.
ConsumedInputParsing m =>
m a -> m (ParserInput m, a)
match (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p),
      direct1 :: p g s (s, a)
direct1 = p g s a -> p g s (ParserInput (p g s), a)
forall (m :: * -> *) a.
ConsumedInputParsing m =>
m a -> m (ParserInput m, a)
match (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p),
      indirect :: p g s (s, a)
indirect= p g s a -> p g s (ParserInput (p g s), a)
forall (m :: * -> *) a.
ConsumedInputParsing m =>
m a -> m (ParserInput m, a)
match (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p),
      isAmbiguous :: Maybe (AmbiguityWitness (s, a))
isAmbiguous= Maybe (AmbiguityWitness (s, a))
forall a. Maybe a
Nothing,
      cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p}

instance (Show s, TextualMonoid s, InputCharParsing (p g s), ParserInput (p g s) ~ s) =>
         InputCharParsing (Fixed p g s) where
   satisfyCharInput :: (Char -> Bool) -> Fixed p g s (ParserInput (Fixed p g s))
satisfyCharInput predicate :: Char -> Bool
predicate = p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
liftPositive ((Char -> Bool) -> p g s (ParserInput (p g s))
forall (m :: * -> *).
InputCharParsing m =>
(Char -> Bool) -> m (ParserInput m)
satisfyCharInput Char -> Bool
predicate)
   notSatisfyChar :: (Char -> Bool) -> Fixed p g s ()
notSatisfyChar predicate :: Char -> Bool
predicate = p g s () -> p g s () -> p g s () -> Fixed p g s ()
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
primitive ((Char -> Bool) -> p g s ()
forall (m :: * -> *). InputCharParsing m => (Char -> Bool) -> m ()
notSatisfyChar Char -> Bool
predicate) p g s ()
forall (f :: * -> *) a. Alternative f => f a
empty ((Char -> Bool) -> p g s ()
forall (m :: * -> *). InputCharParsing m => (Char -> Bool) -> m ()
notSatisfyChar Char -> Bool
predicate)
   scanChars :: state
-> (state -> Char -> Maybe state)
-> Fixed p g s (ParserInput (Fixed p g s))
scanChars s0 :: state
s0 f :: state -> Char -> Maybe state
f = p g s s -> p g s s -> p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
primitive (s
forall a. Monoid a => a
mempty s -> p g s () -> p g s s
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (Char -> Bool) -> p g s ()
forall (m :: * -> *). InputCharParsing m => (Char -> Bool) -> m ()
notSatisfyChar Char -> Bool
test) (p g s Char -> p g s Char
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead ((Char -> Bool) -> p g s Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
Char.satisfy Char -> Bool
test) p g s Char -> p g s s -> p g s s
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> p g s s
p g s (ParserInput (p g s))
p) p g s s
p g s (ParserInput (p g s))
p
      where p :: p g s (ParserInput (p g s))
p = state
-> (state -> Char -> Maybe state) -> p g s (ParserInput (p g s))
forall (m :: * -> *) state.
InputCharParsing m =>
state -> (state -> Char -> Maybe state) -> m (ParserInput m)
scanChars state
s0 state -> Char -> Maybe state
f
            test :: Char -> Bool
test = Maybe state -> Bool
forall a. Maybe a -> Bool
isJust (Maybe state -> Bool) -> (Char -> Maybe state) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. state -> Char -> Maybe state
f state
s0
   takeCharsWhile :: (Char -> Bool) -> Fixed p g s (ParserInput (Fixed p g s))
takeCharsWhile predicate :: Char -> Bool
predicate = p g s s -> p g s s -> p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
primitive (s
forall a. Monoid a => a
mempty s -> p g s () -> p g s s
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (Char -> Bool) -> p g s ()
forall (m :: * -> *). InputCharParsing m => (Char -> Bool) -> m ()
notSatisfyChar Char -> Bool
predicate)
                                        ((Char -> Bool) -> p g s (ParserInput (p g s))
forall (m :: * -> *).
InputCharParsing m =>
(Char -> Bool) -> m (ParserInput m)
takeCharsWhile1 Char -> Bool
predicate) ((Char -> Bool) -> p g s (ParserInput (p g s))
forall (m :: * -> *).
InputCharParsing m =>
(Char -> Bool) -> m (ParserInput m)
takeCharsWhile Char -> Bool
predicate)
   takeCharsWhile1 :: (Char -> Bool) -> Fixed p g s (ParserInput (Fixed p g s))
takeCharsWhile1 predicate :: Char -> Bool
predicate = p g s s -> Fixed p g s s
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
liftPositive ((Char -> Bool) -> p g s (ParserInput (p g s))
forall (m :: * -> *).
InputCharParsing m =>
(Char -> Bool) -> m (ParserInput m)
takeCharsWhile1 Char -> Bool
predicate)

instance (CharParsing (p g s), InputCharParsing (Fixed p g s), TextualMonoid s,
          s ~ ParserInput (Fixed p g s), Show s) => CharParsing (Fixed p g s) where
   satisfy :: (Char -> Bool) -> Fixed p g s Char
satisfy predicate :: Char -> Bool
predicate = p g s Char -> Fixed p g s Char
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
liftPositive ((Char -> Bool) -> p g s Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
Char.satisfy Char -> Bool
predicate)
   string :: String -> Fixed p g s String
string s :: String
s = (s -> String) -> s -> String
forall t. TextualMonoid t => (t -> String) -> t -> String
Textual.toString (String -> s -> String
forall a. HasCallStack => String -> a
error "unexpected non-character") (s -> String) -> Fixed p g s s -> Fixed p g s String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserInput (Fixed p g s)
-> Fixed p g s (ParserInput (Fixed p g s))
forall (m :: * -> *).
InputParsing m =>
ParserInput m -> m (ParserInput m)
string (String -> s
forall a. IsString a => String -> a
fromString String
s)
   text :: Text -> Fixed p g s Text
text t :: Text
t = (String -> Text
forall a. IsString a => String -> a
fromString (String -> Text) -> (s -> String) -> s -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (s -> String) -> s -> String
forall t. TextualMonoid t => (t -> String) -> t -> String
Textual.toString (String -> s -> String
forall a. HasCallStack => String -> a
error "unexpected non-character")) (s -> Text) -> Fixed p g s s -> Fixed p g s Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserInput (Fixed p g s)
-> Fixed p g s (ParserInput (Fixed p g s))
forall (m :: * -> *).
InputParsing m =>
ParserInput m -> m (ParserInput m)
string (Text -> s
forall t. TextualMonoid t => Text -> t
Textual.fromText Text
t)

instance AmbiguousParsing (p g s) => AmbiguousParsing (Fixed p g s) where
   ambiguous :: Fixed p g s a -> Fixed p g s (Ambiguous a)
ambiguous (PositiveDirectParser p :: p g s a
p) = p g s (Ambiguous a) -> Fixed p g s (Ambiguous a)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser (p g s a -> p g s (Ambiguous a)
forall (m :: * -> *) a.
AmbiguousParsing m =>
m a -> m (Ambiguous a)
ambiguous p g s a
p)
   ambiguous p :: Fixed p g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{complete :: p g s (Ambiguous a)
complete= p g s a -> p g s (Ambiguous a)
forall (m :: * -> *) a.
AmbiguousParsing m =>
m a -> m (Ambiguous a)
ambiguous (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
                                             direct0 :: p g s (Ambiguous a)
direct0=  p g s a -> p g s (Ambiguous a)
forall (m :: * -> *) a.
AmbiguousParsing m =>
m a -> m (Ambiguous a)
ambiguous (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p),
                                             direct1 :: p g s (Ambiguous a)
direct1=  p g s a -> p g s (Ambiguous a)
forall (m :: * -> *) a.
AmbiguousParsing m =>
m a -> m (Ambiguous a)
ambiguous (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p)}
   ambiguous p :: Fixed p g s a
p@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{complete :: p g s (Ambiguous a)
complete= p g s a -> p g s (Ambiguous a)
forall (m :: * -> *) a.
AmbiguousParsing m =>
m a -> m (Ambiguous a)
ambiguous (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p),
                                 direct :: p g s (Ambiguous a)
direct=   p g s a -> p g s (Ambiguous a)
forall (m :: * -> *) a.
AmbiguousParsing m =>
m a -> m (Ambiguous a)
ambiguous (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p),
                                 direct0 :: p g s (Ambiguous a)
direct0=  p g s a -> p g s (Ambiguous a)
forall (m :: * -> *) a.
AmbiguousParsing m =>
m a -> m (Ambiguous a)
ambiguous (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed p g s a
p),
                                 direct1 :: p g s (Ambiguous a)
direct1=  p g s a -> p g s (Ambiguous a)
forall (m :: * -> *) a.
AmbiguousParsing m =>
m a -> m (Ambiguous a)
ambiguous (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed p g s a
p),
                                 indirect :: p g s (Ambiguous a)
indirect= p g s a -> p g s (Ambiguous a)
forall (m :: * -> *) a.
AmbiguousParsing m =>
m a -> m (Ambiguous a)
ambiguous (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p),
                                 isAmbiguous :: Maybe (AmbiguityWitness (Ambiguous a))
isAmbiguous= AmbiguityWitness (Ambiguous a)
-> Maybe (AmbiguityWitness (Ambiguous a))
forall a. a -> Maybe a
Just ((Ambiguous a :~: Ambiguous a) -> AmbiguityWitness (Ambiguous a)
forall a b. (a :~: Ambiguous b) -> AmbiguityWitness a
AmbiguityWitness Ambiguous a :~: Ambiguous a
forall k (a :: k). a :~: a
Refl),
                                 cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed p g s a
p}
   {-# INLINABLE ambiguous #-}

-- | Turns a context-free parser into a backtracking PEG parser that consumes the longest possible prefix of the list
-- of input tails, opposite of 'peg'
longest :: Fixed Memoizing.Parser g s a -> Fixed Backtrack.Parser g [(s, g (ResultList g s))] a
longest :: Fixed Parser g s a -> Fixed Parser g [(s, g (ResultList g s))] a
longest (PositiveDirectParser p :: Parser g s a
p) = Parser g [(s, g (ResultList g s))] a
-> Fixed Parser g [(s, g (ResultList g s))] a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser (Parser g s a -> Parser g [(s, g (ResultList g s))] a
forall (g :: (* -> *) -> *) s a.
Parser g s a -> Parser g [(s, g (ResultList g s))] a
Memoizing.longest Parser g s a
p)
longest p :: Fixed Parser g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{complete :: Parser g [(s, g (ResultList g s))] a
complete= Parser g s a -> Parser g [(s, g (ResultList g s))] a
forall (g :: (* -> *) -> *) s a.
Parser g s a -> Parser g [(s, g (ResultList g s))] a
Memoizing.longest (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed Parser g s a
p),
                                        direct0 :: Parser g [(s, g (ResultList g s))] a
direct0=  Parser g s a -> Parser g [(s, g (ResultList g s))] a
forall (g :: (* -> *) -> *) s a.
Parser g s a -> Parser g [(s, g (ResultList g s))] a
Memoizing.longest (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed Parser g s a
p),
                                        direct1 :: Parser g [(s, g (ResultList g s))] a
direct1=  Parser g s a -> Parser g [(s, g (ResultList g s))] a
forall (g :: (* -> *) -> *) s a.
Parser g s a -> Parser g [(s, g (ResultList g s))] a
Memoizing.longest (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed Parser g s a
p)}
longest p :: Fixed Parser g s a
p@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{complete :: Parser g [(s, g (ResultList g s))] a
complete= Parser g s a -> Parser g [(s, g (ResultList g s))] a
forall (g :: (* -> *) -> *) s a.
Parser g s a -> Parser g [(s, g (ResultList g s))] a
Memoizing.longest (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed Parser g s a
p),
                            direct :: Parser g [(s, g (ResultList g s))] a
direct=  Parser g s a -> Parser g [(s, g (ResultList g s))] a
forall (g :: (* -> *) -> *) s a.
Parser g s a -> Parser g [(s, g (ResultList g s))] a
Memoizing.longest (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed Parser g s a
p),
                            direct0 :: Parser g [(s, g (ResultList g s))] a
direct0=  Parser g s a -> Parser g [(s, g (ResultList g s))] a
forall (g :: (* -> *) -> *) s a.
Parser g s a -> Parser g [(s, g (ResultList g s))] a
Memoizing.longest (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed Parser g s a
p),
                            direct1 :: Parser g [(s, g (ResultList g s))] a
direct1=  Parser g s a -> Parser g [(s, g (ResultList g s))] a
forall (g :: (* -> *) -> *) s a.
Parser g s a -> Parser g [(s, g (ResultList g s))] a
Memoizing.longest (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed Parser g s a
p),
                            indirect :: Parser g [(s, g (ResultList g s))] a
indirect=  Parser g s a -> Parser g [(s, g (ResultList g s))] a
forall (g :: (* -> *) -> *) s a.
Parser g s a -> Parser g [(s, g (ResultList g s))] a
Memoizing.longest (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed Parser g s a
p),
                            isAmbiguous :: Maybe (AmbiguityWitness a)
isAmbiguous= Maybe (AmbiguityWitness a)
forall a. Maybe a
Nothing,
                            cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= Fixed Parser g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed Parser g s a
p}

-- | Turns a backtracking PEG parser of the list of input tails into a context-free parser, opposite of 'longest'
peg :: Fixed Backtrack.Parser g [(s, g (ResultList g s))] a -> Fixed Memoizing.Parser g s a
peg :: Fixed Parser g [(s, g (ResultList g s))] a -> Fixed Parser g s a
peg (PositiveDirectParser p :: Parser g [(s, g (ResultList g s))] a
p) = Parser g s a -> Fixed Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser (Parser g [(s, g (ResultList g s))] a -> Parser g s a
forall (g :: (* -> *) -> *) s a.
Parser g [(s, g (ResultList g s))] a -> Parser g s a
Memoizing.peg Parser g [(s, g (ResultList g s))] a
p)
peg p :: Fixed Parser g [(s, g (ResultList g s))] a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{complete :: Parser g s a
complete= Parser g [(s, g (ResultList g s))] a -> Parser g s a
forall (g :: (* -> *) -> *) s a.
Parser g [(s, g (ResultList g s))] a -> Parser g s a
Memoizing.peg (Fixed Parser g [(s, g (ResultList g s))] a
-> Parser g [(s, g (ResultList g s))] a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed Parser g [(s, g (ResultList g s))] a
p),
                                        direct0 :: Parser g s a
direct0=  Parser g [(s, g (ResultList g s))] a -> Parser g s a
forall (g :: (* -> *) -> *) s a.
Parser g [(s, g (ResultList g s))] a -> Parser g s a
Memoizing.peg (Fixed Parser g [(s, g (ResultList g s))] a
-> Parser g [(s, g (ResultList g s))] a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed Parser g [(s, g (ResultList g s))] a
p),
                                        direct1 :: Parser g s a
direct1=  Parser g [(s, g (ResultList g s))] a -> Parser g s a
forall (g :: (* -> *) -> *) s a.
Parser g [(s, g (ResultList g s))] a -> Parser g s a
Memoizing.peg (Fixed Parser g [(s, g (ResultList g s))] a
-> Parser g [(s, g (ResultList g s))] a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed Parser g [(s, g (ResultList g s))] a
p)}
peg p :: Fixed Parser g [(s, g (ResultList g s))] a
p@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{complete :: Parser g s a
complete= Parser g [(s, g (ResultList g s))] a -> Parser g s a
forall (g :: (* -> *) -> *) s a.
Parser g [(s, g (ResultList g s))] a -> Parser g s a
Memoizing.peg (Fixed Parser g [(s, g (ResultList g s))] a
-> Parser g [(s, g (ResultList g s))] a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed Parser g [(s, g (ResultList g s))] a
p),
                        direct :: Parser g s a
direct=  Parser g [(s, g (ResultList g s))] a -> Parser g s a
forall (g :: (* -> *) -> *) s a.
Parser g [(s, g (ResultList g s))] a -> Parser g s a
Memoizing.peg (Fixed Parser g [(s, g (ResultList g s))] a
-> Parser g [(s, g (ResultList g s))] a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed Parser g [(s, g (ResultList g s))] a
p),
                        direct0 :: Parser g s a
direct0=  Parser g [(s, g (ResultList g s))] a -> Parser g s a
forall (g :: (* -> *) -> *) s a.
Parser g [(s, g (ResultList g s))] a -> Parser g s a
Memoizing.peg (Fixed Parser g [(s, g (ResultList g s))] a
-> Parser g [(s, g (ResultList g s))] a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed Parser g [(s, g (ResultList g s))] a
p),
                        direct1 :: Parser g s a
direct1=  Parser g [(s, g (ResultList g s))] a -> Parser g s a
forall (g :: (* -> *) -> *) s a.
Parser g [(s, g (ResultList g s))] a -> Parser g s a
Memoizing.peg (Fixed Parser g [(s, g (ResultList g s))] a
-> Parser g [(s, g (ResultList g s))] a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed Parser g [(s, g (ResultList g s))] a
p),
                        indirect :: Parser g s a
indirect=  Parser g [(s, g (ResultList g s))] a -> Parser g s a
forall (g :: (* -> *) -> *) s a.
Parser g [(s, g (ResultList g s))] a -> Parser g s a
Memoizing.peg (Fixed Parser g [(s, g (ResultList g s))] a
-> Parser g [(s, g (ResultList g s))] a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed Parser g [(s, g (ResultList g s))] a
p),
                        isAmbiguous :: Maybe (AmbiguityWitness a)
isAmbiguous= Maybe (AmbiguityWitness a)
forall a. Maybe a
Nothing,
                        cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= Fixed Parser g [(s, g (ResultList g s))] a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed Parser g [(s, g (ResultList g s))] a
p}

-- | Turns a backtracking PEG parser into a context-free parser
terminalPEG :: Monoid s => Fixed Backtrack.Parser g s a -> Fixed Memoizing.Parser g s a
terminalPEG :: Fixed Parser g s a -> Fixed Parser g s a
terminalPEG (PositiveDirectParser p :: Parser g s a
p) = Parser g s a -> Fixed Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> Fixed p g s a
PositiveDirectParser (Parser g s a -> Parser g s a
forall s (g :: (* -> *) -> *) a.
Monoid s =>
Parser g s a -> Parser g s a
Memoizing.terminalPEG Parser g s a
p)
terminalPEG p :: Fixed Parser g s a
p@DirectParser{} = DirectParser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> p g s a -> p g s a -> Fixed p g s a
DirectParser{complete :: Parser g s a
complete= Parser g s a -> Parser g s a
forall s (g :: (* -> *) -> *) a.
Monoid s =>
Parser g s a -> Parser g s a
Memoizing.terminalPEG (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed Parser g s a
p),
                                            direct0 :: Parser g s a
direct0=  Parser g s a -> Parser g s a
forall s (g :: (* -> *) -> *) a.
Monoid s =>
Parser g s a -> Parser g s a
Memoizing.terminalPEG (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed Parser g s a
p),
                                            direct1 :: Parser g s a
direct1=  Parser g s a -> Parser g s a
forall s (g :: (* -> *) -> *) a.
Monoid s =>
Parser g s a -> Parser g s a
Memoizing.terminalPEG (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed Parser g s a
p)}
terminalPEG p :: Fixed Parser g s a
p@Parser{} = Parser :: forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> p g s a
-> p g s a
-> p g s a
-> Maybe (AmbiguityWitness a)
-> (Apply g => g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
Parser{complete :: Parser g s a
complete= Parser g s a -> Parser g s a
forall s (g :: (* -> *) -> *) a.
Monoid s =>
Parser g s a -> Parser g s a
Memoizing.terminalPEG (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed Parser g s a
p),
                                direct :: Parser g s a
direct=  Parser g s a -> Parser g s a
forall s (g :: (* -> *) -> *) a.
Monoid s =>
Parser g s a -> Parser g s a
Memoizing.terminalPEG (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed Parser g s a
p),
                                direct0 :: Parser g s a
direct0=  Parser g s a -> Parser g s a
forall s (g :: (* -> *) -> *) a.
Monoid s =>
Parser g s a -> Parser g s a
Memoizing.terminalPEG (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct0 Fixed Parser g s a
p),
                                direct1 :: Parser g s a
direct1=  Parser g s a -> Parser g s a
forall s (g :: (* -> *) -> *) a.
Monoid s =>
Parser g s a -> Parser g s a
Memoizing.terminalPEG (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct1 Fixed Parser g s a
p),
                                indirect :: Parser g s a
indirect=  Parser g s a -> Parser g s a
forall s (g :: (* -> *) -> *) a.
Monoid s =>
Parser g s a -> Parser g s a
Memoizing.terminalPEG (Fixed Parser g s a -> Parser g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed Parser g s a
p),
                                isAmbiguous :: Maybe (AmbiguityWitness a)
isAmbiguous= Maybe (AmbiguityWitness a)
forall a. Maybe a
Nothing,
                                cyclicDescendants :: Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants= Fixed Parser g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants Fixed Parser g s a
p}

parseRecursive :: forall p g s rl. (Rank2.Apply g, Rank2.Distributive g, Rank2.Traversable g,
                                    Eq s, FactorialMonoid s, LeftReductive s, Alternative (p g s),
                                    TailsParsing (p g s), GrammarConstraint (p g s) g,
                                    s ~ ParserInput (p g s), GrammarFunctor (p g s) ~ rl s, FallibleWithExpectations rl,
                                    AmbiguousAlternative (GrammarFunctor (p g s))) =>
                  g (Fixed p g s) -> s -> [(s, g (GrammarFunctor (p g s)))]
parseRecursive :: g (Fixed p g s) -> s -> [(s, g (GrammarFunctor (p g s)))]
parseRecursive = g (SeparatedParser p g s) -> s -> [(s, g (rl s))]
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *)
       (rl :: * -> * -> *) s.
(Apply g, Foldable g, Eq s, FactorialMonoid s, LeftReductive s,
 TailsParsing (p g s), GrammarConstraint (p g s) g,
 GrammarFunctor (p g s) ~ rl s, FallibleWithExpectations rl,
 s ~ ParserInput (p g s)) =>
g (SeparatedParser p g s) -> s -> [(s, g (GrammarFunctor (p g s)))]
parseSeparated (g (SeparatedParser p g s) -> s -> [(s, g (rl s))])
-> (g (Fixed p g s) -> g (SeparatedParser p g s))
-> g (Fixed p g s)
-> s
-> [(s, g (rl s))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. g (Fixed p g s) -> g (SeparatedParser p g s)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *)
       s.
(Alternative (p g s), Apply g, Distributive g, Traversable g,
 AmbiguousAlternative (GrammarFunctor (p g s))) =>
g (Fixed p g s) -> g (SeparatedParser p g s)
separated
{-# INLINE parseRecursive #-}

separated :: forall p g s. (Alternative (p g s), Rank2.Apply g, Rank2.Distributive g, Rank2.Traversable g,
                            AmbiguousAlternative (GrammarFunctor (p g s))) =>
             g (Fixed p g s) -> g (SeparatedParser p g s)
separated :: g (Fixed p g s) -> g (SeparatedParser p g s)
separated g :: g (Fixed p g s)
g = (forall a.
 Const Bool a
 -> Const Bool a
 -> Const (g (Const Bool)) a
 -> Fixed p g s a
 -> SeparatedParser p g s a)
-> g (Const Bool)
-> g (Const Bool)
-> g (Const (g (Const Bool)))
-> g (Fixed p g s)
-> g (SeparatedParser p g s)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *) (s :: k -> *) (t :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a -> s a -> t a)
-> g p -> g q -> g r -> g s -> g t
Rank2.liftA4 forall a.
Const Bool a
-> Const Bool a
-> Const (g (Const Bool)) a
-> Fixed p g s a
-> SeparatedParser p g s a
reseparate g (Const Bool)
circulars g (Const Bool)
cycleFollowers g (Const (g (Const Bool)))
descendants g (Fixed p g s)
g
   where descendants :: g (Const (g (Const Bool)))
         cycleFollowers, circulars :: g (Const Bool)
         cyclicDescendantses :: g (Const (ParserFlags g))
         appendResults :: forall a. Maybe (AmbiguityWitness a)
                       -> GrammarFunctor (p g s) a -> GrammarFunctor (p g s) a -> GrammarFunctor (p g s) a
         leftRecursive :: forall a. Const (g (Const Bool)) a -> Const (ParserFlags g) a -> Const Bool a
         leftRecursiveDeps :: forall a. Const Bool a -> Const (ParserFlags g) a -> Const (g (Const Bool)) a
         reseparate :: forall a. Const Bool a -> Const Bool a -> Const (g (Const Bool)) a -> Fixed p g s a
                    -> SeparatedParser p g s a
         reseparate :: Const Bool a
-> Const Bool a
-> Const (g (Const Bool)) a
-> Fixed p g s a
-> SeparatedParser p g s a
reseparate (Const circular :: Bool
circular) (Const follower :: Bool
follower) (Const deps :: g (Const Bool)
deps) p :: Fixed p g s a
p
            | Bool
circular Bool -> Bool -> Bool
|| Bool
leader Bool -> Bool -> Bool
&& Bool
follower =
              p g s a
-> p g s a
-> ResultAppend p g s a
-> g (Const Bool)
-> SeparatedParser p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a
-> p g s a
-> ResultAppend p g s a
-> g (Const Bool)
-> SeparatedParser p g s a
CycleParser (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
indirect Fixed p g s a
p) (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
direct Fixed p g s a
p) ((GrammarFunctor (p g s) a
 -> Arrow (GrammarFunctor (p g s)) (GrammarFunctor (p g s)) a)
-> ResultAppend p g s a
forall k (p :: k -> *) (q :: k -> *) (a :: k).
(p a -> q a) -> Arrow p q a
Rank2.Arrow ((GrammarFunctor (p g s) a -> GrammarFunctor (p g s) a)
-> Arrow (GrammarFunctor (p g s)) (GrammarFunctor (p g s)) a
forall k (p :: k -> *) (q :: k -> *) (a :: k).
(p a -> q a) -> Arrow p q a
Rank2.Arrow ((GrammarFunctor (p g s) a -> GrammarFunctor (p g s) a)
 -> Arrow (GrammarFunctor (p g s)) (GrammarFunctor (p g s)) a)
-> (GrammarFunctor (p g s) a
    -> GrammarFunctor (p g s) a -> GrammarFunctor (p g s) a)
-> GrammarFunctor (p g s) a
-> Arrow (GrammarFunctor (p g s)) (GrammarFunctor (p g s)) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (AmbiguityWitness a)
-> GrammarFunctor (p g s) a
-> GrammarFunctor (p g s) a
-> GrammarFunctor (p g s) a
forall a.
Maybe (AmbiguityWitness a)
-> GrammarFunctor (p g s) a
-> GrammarFunctor (p g s) a
-> GrammarFunctor (p g s) a
appendResults (Fixed p g s a -> Maybe (AmbiguityWitness a)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> Maybe (AmbiguityWitness a)
isAmbiguous Fixed p g s a
p))) g (Const Bool)
deps
            | Bool
follower = p g s a -> SeparatedParser p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> SeparatedParser p g s a
BackParser (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p)
            | Bool
otherwise = p g s a -> SeparatedParser p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
p g s a -> SeparatedParser p g s a
FrontParser (Fixed p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a -> p g s a
complete Fixed p g s a
p)
            where leader :: Bool
leader = Any -> Bool
getAny ((forall a. Const Bool a -> Any) -> g (Const Bool) -> Any
forall k (g :: (k -> *) -> *) m (p :: k -> *).
(Foldable g, Monoid m) =>
(forall (a :: k). p a -> m) -> g p -> m
Rank2.foldMap (Bool -> Any
Any (Bool -> Any) -> (Const Bool a -> Bool) -> Const Bool a -> Any
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const Bool a -> Bool
forall a k (b :: k). Const a b -> a
getConst) (g (Const Bool) -> Any) -> g (Const Bool) -> Any
forall a b. (a -> b) -> a -> b
$ (forall a. Const Bool a -> Const Bool a -> Const Bool a)
-> g (Const Bool) -> g (Const Bool) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. Const Bool a -> Const Bool a -> Const Bool a
forall b b b. Const Bool b -> Const Bool b -> Const Bool b
intersection g (Const Bool)
circulars g (Const Bool)
deps)
         appendResults :: Maybe (AmbiguityWitness a)
-> GrammarFunctor (p g s) a
-> GrammarFunctor (p g s) a
-> GrammarFunctor (p g s) a
appendResults (Just (AmbiguityWitness Refl)) = GrammarFunctor (p g s) a
-> GrammarFunctor (p g s) a -> GrammarFunctor (p g s) a
forall (f :: * -> *) a.
AmbiguousAlternative f =>
f (Ambiguous a) -> f (Ambiguous a) -> f (Ambiguous a)
ambiguousOr
         appendResults Nothing = GrammarFunctor (p g s) a
-> GrammarFunctor (p g s) a -> GrammarFunctor (p g s) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>)
         descendants :: g (Const (g (Const Bool)))
descendants = (forall a. Const (ParserFlags g) a -> Const (g (Const Bool)) a)
-> g (Const (ParserFlags g)) -> g (Const (g (Const Bool)))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (g (Const Bool) -> Const (g (Const Bool)) a
forall k a (b :: k). a -> Const a b
Const (g (Const Bool) -> Const (g (Const Bool)) a)
-> (Const (ParserFlags g) a -> g (Const Bool))
-> Const (ParserFlags g) a
-> Const (g (Const Bool)) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserFlags g -> g (Const Bool)
forall (g :: (* -> *) -> *). ParserFlags g -> g (Const Bool)
dependsOn (ParserFlags g -> g (Const Bool))
-> (Const (ParserFlags g) a -> ParserFlags g)
-> Const (ParserFlags g) a
-> g (Const Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const (ParserFlags g) a -> ParserFlags g
forall a k (b :: k). Const a b -> a
getConst) g (Const (ParserFlags g))
cyclicDescendantses
         cyclicDescendantses :: g (Const (ParserFlags g))
cyclicDescendantses = g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
-> g (Const (ParserFlags g))
forall (g :: (* -> *) -> *).
(Apply g, Traversable g) =>
g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
-> g (Const (ParserFlags g))
fixDescendants ((forall a.
 Fixed p g s a
 -> Const (g (Const (ParserFlags g)) -> ParserFlags g) a)
-> g (Fixed p g s)
-> g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap ((g (Const (ParserFlags g)) -> ParserFlags g)
-> Const (g (Const (ParserFlags g)) -> ParserFlags g) a
forall k a (b :: k). a -> Const a b
Const ((g (Const (ParserFlags g)) -> ParserFlags g)
 -> Const (g (Const (ParserFlags g)) -> ParserFlags g) a)
-> (Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g)
-> Fixed p g s a
-> Const (g (Const (ParserFlags g)) -> ParserFlags g) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Fixed p g s a
-> Apply g => g (Const (ParserFlags g)) -> ParserFlags g
cyclicDescendants (Fixed p g s a -> g (Const (ParserFlags g)) -> ParserFlags g)
-> (Fixed p g s a -> Fixed p g s a)
-> Fixed p g s a
-> g (Const (ParserFlags g))
-> ParserFlags g
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixed p g s a -> Fixed p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
Fixed p g s a -> Fixed p g s a
general) g (Fixed p g s)
g)
         circulars :: g (Const Bool)
circulars = (forall a.
 Const (g (Const Bool)) a
 -> Const (ParserFlags g) a -> Const Bool a)
-> g (Const (g (Const Bool)))
-> g (Const (ParserFlags g))
-> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a.
Const (g (Const Bool)) a -> Const (ParserFlags g) a -> Const Bool a
leftRecursive g (Const (g (Const Bool)))
forall (g :: (* -> *) -> *).
(Distributive g, Traversable g) =>
g (Const (g (Const Bool)))
bits g (Const (ParserFlags g))
cyclicDescendantses
         cycleFollowers :: g (Const Bool)
cycleFollowers = Union g -> g (Const Bool)
forall (g :: (* -> *) -> *). Union g -> g (Const Bool)
getUnion ((forall a. Const (g (Const Bool)) a -> Union g)
-> g (Const (g (Const Bool))) -> Union g
forall k (g :: (k -> *) -> *) m (p :: k -> *).
(Foldable g, Monoid m) =>
(forall (a :: k). p a -> m) -> g p -> m
Rank2.foldMap (g (Const Bool) -> Union g
forall (g :: (* -> *) -> *). g (Const Bool) -> Union g
Union (g (Const Bool) -> Union g)
-> (Const (g (Const Bool)) a -> g (Const Bool))
-> Const (g (Const Bool)) a
-> Union g
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const (g (Const Bool)) a -> g (Const Bool)
forall a k (b :: k). Const a b -> a
getConst) (g (Const (g (Const Bool))) -> Union g)
-> g (Const (g (Const Bool))) -> Union g
forall a b. (a -> b) -> a -> b
$
                                    (forall a.
 Const Bool a
 -> Const (ParserFlags g) a -> Const (g (Const Bool)) a)
-> g (Const Bool)
-> g (Const (ParserFlags g))
-> g (Const (g (Const Bool)))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a.
Const Bool a -> Const (ParserFlags g) a -> Const (g (Const Bool)) a
leftRecursiveDeps g (Const Bool)
circulars g (Const (ParserFlags g))
cyclicDescendantses)
         leftRecursive :: Const (g (Const Bool)) a -> Const (ParserFlags g) a -> Const Bool a
leftRecursive (Const bit :: g (Const Bool)
bit) (Const flags :: ParserFlags g
flags) =
            Bool -> Const Bool a
forall k a (b :: k). a -> Const a b
Const (Any -> Bool
getAny (Any -> Bool) -> Any -> Bool
forall a b. (a -> b) -> a -> b
$ (forall a. Const Bool a -> Any) -> g (Const Bool) -> Any
forall k (g :: (k -> *) -> *) m (p :: k -> *).
(Foldable g, Monoid m) =>
(forall (a :: k). p a -> m) -> g p -> m
Rank2.foldMap (Bool -> Any
Any (Bool -> Any) -> (Const Bool a -> Bool) -> Const Bool a -> Any
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const Bool a -> Bool
forall a k (b :: k). Const a b -> a
getConst) (g (Const Bool) -> Any) -> g (Const Bool) -> Any
forall a b. (a -> b) -> a -> b
$ (forall a. Const Bool a -> Const Bool a -> Const Bool a)
-> g (Const Bool) -> g (Const Bool) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. Const Bool a -> Const Bool a -> Const Bool a
forall b b b. Const Bool b -> Const Bool b -> Const Bool b
intersection g (Const Bool)
bit (g (Const Bool) -> g (Const Bool))
-> g (Const Bool) -> g (Const Bool)
forall a b. (a -> b) -> a -> b
$ ParserFlags g -> g (Const Bool)
forall (g :: (* -> *) -> *). ParserFlags g -> g (Const Bool)
dependsOn ParserFlags g
flags)
         leftRecursiveDeps :: Const Bool a -> Const (ParserFlags g) a -> Const (g (Const Bool)) a
leftRecursiveDeps (Const True) (Const flags :: ParserFlags g
flags) = g (Const Bool) -> Const (g (Const Bool)) a
forall k a (b :: k). a -> Const a b
Const (ParserFlags g -> g (Const Bool)
forall (g :: (* -> *) -> *). ParserFlags g -> g (Const Bool)
dependsOn ParserFlags g
flags)
         leftRecursiveDeps (Const False) (Const flags :: ParserFlags g
flags) = g (Const Bool) -> Const (g (Const Bool)) a
forall k a (b :: k). a -> Const a b
Const ((forall a. Const Bool a -> Const Bool a)
-> g (Const Bool) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (Const Bool a -> Const Bool a -> Const Bool a
forall a b. a -> b -> a
const (Const Bool a -> Const Bool a -> Const Bool a)
-> Const Bool a -> Const Bool a -> Const Bool a
forall a b. (a -> b) -> a -> b
$ Bool -> Const Bool a
forall k a (b :: k). a -> Const a b
Const Bool
False) (ParserFlags g -> g (Const Bool)
forall (g :: (* -> *) -> *). ParserFlags g -> g (Const Bool)
dependsOn ParserFlags g
flags))
         intersection :: Const Bool b -> Const Bool b -> Const Bool b
intersection (Const a :: Bool
a) (Const b :: Bool
b) = Bool -> Const Bool b
forall k a (b :: k). a -> Const a b
Const (Bool
a Bool -> Bool -> Bool
&& Bool
b)
{-# INLINABLE separated #-}

fixDescendants :: forall g. (Rank2.Apply g, Rank2.Traversable g)
                     => g (Const (g (Const (ParserFlags g)) -> (ParserFlags g))) -> g (Const (ParserFlags g))
fixDescendants :: g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
-> g (Const (ParserFlags g))
fixDescendants gf :: g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
gf = g (Const (ParserFlags g)) -> g (Const (ParserFlags g))
go g (Const (ParserFlags g))
initial
   where go :: g (Const (ParserFlags g)) -> g (Const (ParserFlags g))
         go :: g (Const (ParserFlags g)) -> g (Const (ParserFlags g))
go cd :: g (Const (ParserFlags g))
cd
            | All -> Bool
getAll ((forall a. Const Bool a -> All) -> g (Const Bool) -> All
forall k (g :: (k -> *) -> *) m (p :: k -> *).
(Foldable g, Monoid m) =>
(forall (a :: k). p a -> m) -> g p -> m
Rank2.foldMap (Bool -> All
All (Bool -> All) -> (Const Bool a -> Bool) -> Const Bool a -> All
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const Bool a -> Bool
forall a k (b :: k). Const a b -> a
getConst) (g (Const Bool) -> All) -> g (Const Bool) -> All
forall a b. (a -> b) -> a -> b
$ (forall a.
 Const (ParserFlags g) a -> Const (ParserFlags g) a -> Const Bool a)
-> g (Const (ParserFlags g))
-> g (Const (ParserFlags g))
-> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a.
Const (ParserFlags g) a -> Const (ParserFlags g) a -> Const Bool a
forall (g :: (* -> *) -> *) b b b.
(Foldable g, Apply g) =>
Const (ParserFlags g) b -> Const (ParserFlags g) b -> Const Bool b
agree g (Const (ParserFlags g))
cd g (Const (ParserFlags g))
cd') = g (Const (ParserFlags g))
cd
            | Bool
otherwise = g (Const (ParserFlags g)) -> g (Const (ParserFlags g))
go g (Const (ParserFlags g))
cd'
            where cd' :: g (Const (ParserFlags g))
cd' = (forall a.
 Const (ParserFlags g) a
 -> Const (ParserFlags g) a -> Const (ParserFlags g) a)
-> g (Const (ParserFlags g))
-> g (Const (ParserFlags g))
-> g (Const (ParserFlags g))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a.
Const (ParserFlags g) a
-> Const (ParserFlags g) a -> Const (ParserFlags g) a
forall (g :: (* -> *) -> *) b b b.
Apply g =>
Const (ParserFlags g) b
-> Const (ParserFlags g) b -> Const (ParserFlags g) b
depsUnion g (Const (ParserFlags g))
cd ((forall a.
 Const (g (Const (ParserFlags g)) -> ParserFlags g) a
 -> Const (ParserFlags g) a)
-> g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
-> g (Const (ParserFlags g))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (\(Const f)-> ParserFlags g -> Const (ParserFlags g) a
forall k a (b :: k). a -> Const a b
Const (g (Const (ParserFlags g)) -> ParserFlags g
f g (Const (ParserFlags g))
cd)) g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
gf)
         agree :: Const (ParserFlags g) b -> Const (ParserFlags g) b -> Const Bool b
agree (Const (ParserFlags _xn :: Bool
_xn xd :: g (Const Bool)
xd)) (Const (ParserFlags _yn :: Bool
_yn yd :: g (Const Bool)
yd)) =
            Bool -> Const Bool b
forall k a (b :: k). a -> Const a b
Const (All -> Bool
getAll ((forall a. Const Bool a -> All) -> g (Const Bool) -> All
forall k (g :: (k -> *) -> *) m (p :: k -> *).
(Foldable g, Monoid m) =>
(forall (a :: k). p a -> m) -> g p -> m
Rank2.foldMap (Bool -> All
All (Bool -> All) -> (Const Bool a -> Bool) -> Const Bool a -> All
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const Bool a -> Bool
forall a k (b :: k). Const a b -> a
getConst) ((forall a. Const Bool a -> Const Bool a -> Const Bool a)
-> g (Const Bool) -> g (Const Bool) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. Const Bool a -> Const Bool a -> Const Bool a
forall a b b b. Eq a => Const a b -> Const a b -> Const Bool b
agree' g (Const Bool)
xd g (Const Bool)
yd)))
         agree' :: Const a b -> Const a b -> Const Bool b
agree' (Const x :: a
x) (Const y :: a
y) = Bool -> Const Bool b
forall k a (b :: k). a -> Const a b
Const (a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y)
         depsUnion :: Const (ParserFlags g) b
-> Const (ParserFlags g) b -> Const (ParserFlags g) b
depsUnion (Const ParserFlags{dependsOn :: forall (g :: (* -> *) -> *). ParserFlags g -> g (Const Bool)
dependsOn= g (Const Bool)
old}) (Const (ParserFlags n :: Bool
n new :: g (Const Bool)
new)) = 
            ParserFlags g -> Const (ParserFlags g) b
forall k a (b :: k). a -> Const a b
Const (Bool -> g (Const Bool) -> ParserFlags g
forall (g :: (* -> *) -> *).
Bool -> g (Const Bool) -> ParserFlags g
ParserFlags Bool
n (g (Const Bool) -> ParserFlags g)
-> g (Const Bool) -> ParserFlags g
forall a b. (a -> b) -> a -> b
$ (forall a. Const Bool a -> Const Bool a -> Const Bool a)
-> g (Const Bool) -> g (Const Bool) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. Const Bool a -> Const Bool a -> Const Bool a
union g (Const Bool)
old g (Const Bool)
new)
         initial :: g (Const (ParserFlags g))
initial = (forall a.
 Const (g (Const (ParserFlags g)) -> ParserFlags g) a
 -> Const Bool a -> Const (ParserFlags g) a)
-> g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
-> g (Const Bool)
-> g (Const (ParserFlags g))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 (\_ (Const n)-> ParserFlags g -> Const (ParserFlags g) a
forall k a (b :: k). a -> Const a b
Const (Bool -> g (Const Bool) -> ParserFlags g
forall (g :: (* -> *) -> *).
Bool -> g (Const Bool) -> ParserFlags g
ParserFlags Bool
n (Const Bool a
-> Const (g (Const (ParserFlags g)) -> ParserFlags g) a
-> Const Bool a
forall a b. a -> b -> a
const (Bool -> Const Bool a
forall k a (b :: k). a -> Const a b
Const Bool
False) (forall a.
 Const (g (Const (ParserFlags g)) -> ParserFlags g) a
 -> Const Bool a)
-> g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
-> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.<$> g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
gf))) g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
gf g (Const Bool)
nullabilities
         nullabilities :: g (Const Bool)
nullabilities = g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
-> g (Const Bool)
forall (g :: (* -> *) -> *).
(Apply g, Traversable g) =>
g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
-> g (Const Bool)
fixNullabilities g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
gf
{-# INLINABLE fixDescendants #-}

fixNullabilities :: forall g. (Rank2.Apply g, Rank2.Traversable g)
                    => g (Const (g (Const (ParserFlags g)) -> (ParserFlags g))) -> g (Const Bool)
fixNullabilities :: g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
-> g (Const Bool)
fixNullabilities gf :: g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
gf = (forall a. Const (ParserFlags g) a -> Const Bool a)
-> g (Const (ParserFlags g)) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (Bool -> Const Bool a
forall k a (b :: k). a -> Const a b
Const (Bool -> Const Bool a)
-> (Const (ParserFlags g) a -> Bool)
-> Const (ParserFlags g) a
-> Const Bool a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserFlags g -> Bool
forall (g :: (* -> *) -> *). ParserFlags g -> Bool
nullable (ParserFlags g -> Bool)
-> (Const (ParserFlags g) a -> ParserFlags g)
-> Const (ParserFlags g) a
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const (ParserFlags g) a -> ParserFlags g
forall a k (b :: k). Const a b -> a
getConst) (g (Const (ParserFlags g)) -> g (Const (ParserFlags g))
go g (Const (ParserFlags g))
initial)
   where go :: g (Const (ParserFlags g)) -> g (Const (ParserFlags g))
         go :: g (Const (ParserFlags g)) -> g (Const (ParserFlags g))
go cd :: g (Const (ParserFlags g))
cd
            | All -> Bool
getAll ((forall a. Const Bool a -> All) -> g (Const Bool) -> All
forall k (g :: (k -> *) -> *) m (p :: k -> *).
(Foldable g, Monoid m) =>
(forall (a :: k). p a -> m) -> g p -> m
Rank2.foldMap (Bool -> All
All (Bool -> All) -> (Const Bool a -> Bool) -> Const Bool a -> All
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const Bool a -> Bool
forall a k (b :: k). Const a b -> a
getConst) (g (Const Bool) -> All) -> g (Const Bool) -> All
forall a b. (a -> b) -> a -> b
$ (forall a.
 Const (ParserFlags g) a -> Const (ParserFlags g) a -> Const Bool a)
-> g (Const (ParserFlags g))
-> g (Const (ParserFlags g))
-> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a.
Const (ParserFlags g) a -> Const (ParserFlags g) a -> Const Bool a
forall (g :: (* -> *) -> *) b (g :: (* -> *) -> *) b b.
Const (ParserFlags g) b -> Const (ParserFlags g) b -> Const Bool b
agree g (Const (ParserFlags g))
cd g (Const (ParserFlags g))
cd') = g (Const (ParserFlags g))
cd
            | Bool
otherwise = g (Const (ParserFlags g)) -> g (Const (ParserFlags g))
go g (Const (ParserFlags g))
cd'
            where cd' :: g (Const (ParserFlags g))
cd' = (forall a.
 Const (g (Const (ParserFlags g)) -> ParserFlags g) a
 -> Const (ParserFlags g) a)
-> g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
-> g (Const (ParserFlags g))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (\(Const f)-> ParserFlags g -> Const (ParserFlags g) a
forall k a (b :: k). a -> Const a b
Const (g (Const (ParserFlags g)) -> ParserFlags g
f g (Const (ParserFlags g))
cd)) g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
gf
         agree :: Const (ParserFlags g) b -> Const (ParserFlags g) b -> Const Bool b
agree (Const flags1 :: ParserFlags g
flags1) (Const flags2 :: ParserFlags g
flags2) = Bool -> Const Bool b
forall k a (b :: k). a -> Const a b
Const (ParserFlags g -> Bool
forall (g :: (* -> *) -> *). ParserFlags g -> Bool
nullable ParserFlags g
flags1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== ParserFlags g -> Bool
forall (g :: (* -> *) -> *). ParserFlags g -> Bool
nullable ParserFlags g
flags2)
         initial :: g (Const (ParserFlags g))
initial = Const (ParserFlags g) a
-> Const (g (Const (ParserFlags g)) -> ParserFlags g) a
-> Const (ParserFlags g) a
forall a b. a -> b -> a
const (ParserFlags g -> Const (ParserFlags g) a
forall k a (b :: k). a -> Const a b
Const (Bool -> g (Const Bool) -> ParserFlags g
forall (g :: (* -> *) -> *).
Bool -> g (Const Bool) -> ParserFlags g
ParserFlags Bool
True (Const Bool a
-> Const (g (Const (ParserFlags g)) -> ParserFlags g) a
-> Const Bool a
forall a b. a -> b -> a
const (Bool -> Const Bool a
forall k a (b :: k). a -> Const a b
Const Bool
False) (forall a.
 Const (g (Const (ParserFlags g)) -> ParserFlags g) a
 -> Const Bool a)
-> g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
-> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.<$> g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
gf))) (forall a.
 Const (g (Const (ParserFlags g)) -> ParserFlags g) a
 -> Const (ParserFlags g) a)
-> g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
-> g (Const (ParserFlags g))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.<$> g (Const (g (Const (ParserFlags g)) -> ParserFlags g))
gf
{-# INLINABLE fixNullabilities #-}

-- | Parse the given input using a context-free grammar separated into two parts: the first specifying all the
-- left-recursive productions, the second all others. The first function argument specifies the left-recursive
-- dependencies among the grammar productions.
parseSeparated :: forall p g rl s. (Rank2.Apply g, Rank2.Foldable g, Eq s, FactorialMonoid s, LeftReductive s,
                                    TailsParsing (p g s), GrammarConstraint (p g s) g,
                                    GrammarFunctor (p g s) ~ rl s, FallibleWithExpectations rl,
                                    s ~ ParserInput (p g s)) =>
                  g (SeparatedParser p g s) -> s -> [(s, g (GrammarFunctor (p g s)))]
parseSeparated :: g (SeparatedParser p g s) -> s -> [(s, g (GrammarFunctor (p g s)))]
parseSeparated parsers :: g (SeparatedParser p g s)
parsers input :: s
input = (s -> [(s, g (rl s))] -> [(s, g (rl s))])
-> [(s, g (rl s))] -> [s] -> [(s, g (rl s))]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr s -> [(s, g (rl s))] -> [(s, g (rl s))]
parseTail [] (s -> [s]
forall m. FactorialMonoid m => m -> [m]
Factorial.tails s
input)
   where parseTail :: s -> [(s, g (rl s))] -> [(s, g (rl s))]
parseTail s :: s
s parsedTail :: [(s, g (rl s))]
parsedTail = [(s, g (rl s))]
parsed
            where parsed :: [(s, g (rl s))]
parsed = (s
s,g (rl s)
d'')(s, g (rl s)) -> [(s, g (rl s))] -> [(s, g (rl s))]
forall a. a -> [a] -> [a]
:[(s, g (rl s))]
parsedTail
                  d :: g (rl s)
d      = (forall a. p g s a -> rl s a) -> g (p g s) -> g (rl s)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap ((([(s, g (rl s))] -> rl s a) -> [(s, g (rl s))] -> rl s a
forall a b. (a -> b) -> a -> b
$ (s
s,g (rl s)
d)(s, g (rl s)) -> [(s, g (rl s))] -> [(s, g (rl s))]
forall a. a -> [a] -> [a]
:[(s, g (rl s))]
parsedTail) (([(s, g (rl s))] -> rl s a) -> rl s a)
-> (p g s a -> [(s, g (rl s))] -> rl s a) -> p g s a -> rl s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p g s a -> [(s, g (rl s))] -> rl s a
forall (m :: * -> *) (g :: (* -> *) -> *) r.
(TailsParsing m, GrammarConstraint m g) =>
m r
-> [(ParserInput m, g (GrammarFunctor m))] -> GrammarFunctor m r
parseTails) g (p g s)
directs
                  d' :: g (GrammarFunctor (p g s))
d'     = s
-> [(s, g (GrammarFunctor (p g s)))]
-> g (GrammarFunctor (p g s))
-> g (GrammarFunctor (p g s))
fixRecursive s
s [(s, g (rl s))]
[(s, g (GrammarFunctor (p g s)))]
parsedTail g (rl s)
g (GrammarFunctor (p g s))
d
                  d'' :: g (rl s)
d''    = (forall a. SeparatedParser p g s a -> rl s a -> rl s a)
-> g (SeparatedParser p g s) -> g (rl s) -> g (rl s)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. SeparatedParser p g s a -> rl s a -> rl s a
forall a.
SeparatedParser p g s a
-> GrammarFunctor (p g s) a -> GrammarFunctor (p g s) a
f g (SeparatedParser p g s)
parsers g (rl s)
g (GrammarFunctor (p g s))
d'
                  f :: forall a. SeparatedParser p g s a -> GrammarFunctor (p g s) a -> GrammarFunctor (p g s) a
                  f :: SeparatedParser p g s a
-> GrammarFunctor (p g s) a -> GrammarFunctor (p g s) a
f (FrontParser p :: p g s a
p) _ = p g s a
-> [(ParserInput (p g s), g (GrammarFunctor (p g s)))]
-> GrammarFunctor (p g s) a
forall (m :: * -> *) (g :: (* -> *) -> *) r.
(TailsParsing m, GrammarConstraint m g) =>
m r
-> [(ParserInput m, g (GrammarFunctor m))] -> GrammarFunctor m r
parseTails p g s a
p ((s
s,g (rl s)
d'')(s, g (rl s)) -> [(s, g (rl s))] -> [(s, g (rl s))]
forall a. a -> [a] -> [a]
:[(s, g (rl s))]
parsedTail)
                  f _ result :: GrammarFunctor (p g s) a
result = GrammarFunctor (p g s) a
result
         fixRecursive :: s -> [(s, g (GrammarFunctor (p g s)))] -> g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s))
         whileAnyContinues :: (g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s)))
                           -> (g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s)))
                           -> g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s))
         recurseTotal :: s -> g (GrammarFunctor (p g s) Rank2.~> GrammarFunctor (p g s)) -> [(s, g (GrammarFunctor (p g s)))]
                      -> g (GrammarFunctor (p g s))
                      -> g (GrammarFunctor (p g s))
         recurseMarginal :: s -> [(s, g (GrammarFunctor (p g s)))]
                      -> g (GrammarFunctor (p g s))
                      -> g (GrammarFunctor (p g s))
         maybeDependencies :: g (Const (Maybe (g (Const Bool))))
         maybeDependency :: SeparatedParser p g s r -> Const (Maybe (g (Const Bool))) r
         appends :: g (ResultAppend p g s)
         parserAppend :: SeparatedParser p g s r -> ResultAppend p g s r

         directs :: g (p g s)
directs = (forall a. SeparatedParser p g s a -> p g s a)
-> g (SeparatedParser p g s) -> g (p g s)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap forall a. SeparatedParser p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
SeparatedParser p g s a -> p g s a
backParser g (SeparatedParser p g s)
parsers
         indirects :: g (p g s)
indirects = (forall a. SeparatedParser p g s a -> p g s a)
-> g (SeparatedParser p g s) -> g (p g s)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap (\p :: SeparatedParser p g s a
p-> case SeparatedParser p g s a
p of {CycleParser{}-> SeparatedParser p g s a -> p g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
SeparatedParser p g s a -> p g s a
cycleParser SeparatedParser p g s a
p; _ -> p g s a
forall (f :: * -> *) a. Alternative f => f a
empty}) g (SeparatedParser p g s)
parsers
         appends :: g (ResultAppend p g s)
appends = (forall a. SeparatedParser p g s a -> (~>) (rl s) (rl s ~> rl s) a)
-> g (SeparatedParser p g s) -> g (rl s ~> (rl s ~> rl s))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap forall a. SeparatedParser p g s a -> (~>) (rl s) (rl s ~> rl s) a
forall r. SeparatedParser p g s r -> ResultAppend p g s r
parserAppend g (SeparatedParser p g s)
parsers
         parserAppend :: SeparatedParser p g s r -> ResultAppend p g s r
parserAppend p :: SeparatedParser p g s r
p@CycleParser{} = SeparatedParser p g s r -> ResultAppend p g s r
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
SeparatedParser p g s a -> ResultAppend p g s a
appendResultsArrow SeparatedParser p g s r
p
         parserAppend _ = (rl s r -> Arrow (rl s) (rl s) r) -> Arrow (rl s) (rl s ~> rl s) r
forall k (p :: k -> *) (q :: k -> *) (a :: k).
(p a -> q a) -> Arrow p q a
Rank2.Arrow ((rl s r -> rl s r) -> Arrow (rl s) (rl s) r
forall k (p :: k -> *) (q :: k -> *) (a :: k).
(p a -> q a) -> Arrow p q a
Rank2.Arrow ((rl s r -> rl s r) -> Arrow (rl s) (rl s) r)
-> (rl s r -> rl s r -> rl s r) -> rl s r -> Arrow (rl s) (rl s) r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. rl s r -> rl s r -> rl s r
forall a b. a -> b -> a
const)
         maybeDependencies :: g (Const (Maybe (g (Const Bool))))
maybeDependencies = (forall a.
 SeparatedParser p g s a -> Const (Maybe (g (Const Bool))) a)
-> g (SeparatedParser p g s) -> g (Const (Maybe (g (Const Bool))))
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.fmap forall a.
SeparatedParser p g s a -> Const (Maybe (g (Const Bool))) a
maybeDependency g (SeparatedParser p g s)
parsers
         maybeDependency :: SeparatedParser p g s r -> Const (Maybe (g (Const Bool))) r
maybeDependency p :: SeparatedParser p g s r
p@CycleParser{} = Maybe (g (Const Bool)) -> Const (Maybe (g (Const Bool))) r
forall k a (b :: k). a -> Const a b
Const (g (Const Bool) -> Maybe (g (Const Bool))
forall a. a -> Maybe a
Just (g (Const Bool) -> Maybe (g (Const Bool)))
-> g (Const Bool) -> Maybe (g (Const Bool))
forall a b. (a -> b) -> a -> b
$ SeparatedParser p g s r -> g (Const Bool)
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
SeparatedParser p g s a -> g (Const Bool)
dependencies SeparatedParser p g s r
p)
         maybeDependency _ = Maybe (g (Const Bool)) -> Const (Maybe (g (Const Bool))) r
forall k a (b :: k). a -> Const a b
Const Maybe (g (Const Bool))
forall a. Maybe a
Nothing

         fixRecursive :: s
-> [(s, g (GrammarFunctor (p g s)))]
-> g (GrammarFunctor (p g s))
-> g (GrammarFunctor (p g s))
fixRecursive s :: s
s parsedTail :: [(s, g (GrammarFunctor (p g s)))]
parsedTail initial :: g (GrammarFunctor (p g s))
initial =
            (g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s)))
-> (g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s)))
-> g (GrammarFunctor (p g s))
-> g (GrammarFunctor (p g s))
-> g (GrammarFunctor (p g s))
whileAnyContinues (s
-> g (GrammarFunctor (p g s) ~> GrammarFunctor (p g s))
-> [(s, g (GrammarFunctor (p g s)))]
-> g (GrammarFunctor (p g s))
-> g (GrammarFunctor (p g s))
recurseTotal s
s (g (rl s ~> (rl s ~> rl s))
g (ResultAppend p g s)
appends g (rl s ~> (rl s ~> rl s)) -> g (rl s) -> g (rl s ~> rl s)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Apply g =>
g (p ~> q) -> g p -> g q
Rank2.<*> g (rl s)
g (GrammarFunctor (p g s))
initial) [(s, g (GrammarFunctor (p g s)))]
parsedTail)
                              (s
-> [(s, g (GrammarFunctor (p g s)))]
-> g (GrammarFunctor (p g s))
-> g (GrammarFunctor (p g s))
recurseMarginal s
s [(s, g (GrammarFunctor (p g s)))]
parsedTail)
                              g (GrammarFunctor (p g s))
initial g (GrammarFunctor (p g s))
initial

         whileAnyContinues :: (g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s)))
-> (g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s)))
-> g (GrammarFunctor (p g s))
-> g (GrammarFunctor (p g s))
-> g (GrammarFunctor (p g s))
whileAnyContinues ft :: g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s))
ft fm :: g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s))
fm total :: g (GrammarFunctor (p g s))
total marginal :: g (GrammarFunctor (p g s))
marginal =
            (forall a.
 Const (Maybe (g (Const Bool))) a -> rl s a -> rl s a -> rl s a)
-> g (Const (Maybe (g (Const Bool))))
-> g (rl s)
-> g (rl s)
-> g (rl s)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *) (s :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a -> s a)
-> g p -> g q -> g r -> g s
Rank2.liftA3 forall a.
Const (Maybe (g (Const Bool))) a -> rl s a -> rl s a -> rl s a
forall x.
Const (Maybe (g (Const Bool))) x
-> GrammarFunctor (p g s) x
-> GrammarFunctor (p g s) x
-> GrammarFunctor (p g s) x
choiceWhile g (Const (Maybe (g (Const Bool))))
maybeDependencies g (rl s)
g (GrammarFunctor (p g s))
total ((g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s)))
-> (g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s)))
-> g (GrammarFunctor (p g s))
-> g (GrammarFunctor (p g s))
-> g (GrammarFunctor (p g s))
whileAnyContinues g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s))
ft g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s))
fm (g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s))
ft g (GrammarFunctor (p g s))
total) (g (GrammarFunctor (p g s)) -> g (GrammarFunctor (p g s))
fm g (GrammarFunctor (p g s))
marginal))
            where choiceWhile :: Const (Maybe (g (Const Bool))) x
                              -> GrammarFunctor (p g s) x -> GrammarFunctor (p g s) x
                              -> GrammarFunctor (p g s) x
                  choiceWhile :: Const (Maybe (g (Const Bool))) x
-> GrammarFunctor (p g s) x
-> GrammarFunctor (p g s) x
-> GrammarFunctor (p g s) x
choiceWhile (Const Nothing) t :: GrammarFunctor (p g s) x
t _ = GrammarFunctor (p g s) x
t
                  choiceWhile (Const (Just deps :: g (Const Bool)
deps)) t :: GrammarFunctor (p g s) x
t t' :: GrammarFunctor (p g s) x
t'
                     | Any -> Bool
getAny ((forall a. Const Bool a -> Any) -> g (Const Bool) -> Any
forall k (g :: (k -> *) -> *) m (p :: k -> *).
(Foldable g, Monoid m) =>
(forall (a :: k). p a -> m) -> g p -> m
Rank2.foldMap (Bool -> Any
Any (Bool -> Any) -> (Const Bool a -> Bool) -> Const Bool a -> Any
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const Bool a -> Bool
forall a k (b :: k). Const a b -> a
getConst) ((forall a. Const Bool a -> rl s a -> Const Bool a)
-> g (Const Bool) -> g (rl s) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. Const Bool a -> rl s a -> Const Bool a
forall x. Const Bool x -> GrammarFunctor (p g s) x -> Const Bool x
combine g (Const Bool)
deps g (rl s)
g (GrammarFunctor (p g s))
marginal)) = GrammarFunctor (p g s) x
t'
                     | rl s x -> Bool
forall (f :: * -> * -> *) s a.
FallibleWithExpectations f =>
f s a -> Bool
hasSuccess rl s x
GrammarFunctor (p g s) x
t = GrammarFunctor (p g s) x
t
                     | Bool
otherwise =
                        let expected :: [Expected s]
expected = rl s x -> [Expected s]
forall (f :: * -> * -> *) s a.
FallibleWithExpectations f =>
f s a -> [Expected s]
expectations rl s x
GrammarFunctor (p g s) x
t
                            FailureInfo pos :: Int
pos expected' :: [Expected s]
expected' =
                               rl s x -> FailureInfo s
forall (f :: * -> * -> *) s a.
FallibleWithExpectations f =>
f s a -> FailureInfo s
failureOf (if Any -> Bool
getAny ((forall a. Const Bool a -> Any) -> g (Const Bool) -> Any
forall k (g :: (k -> *) -> *) m (p :: k -> *).
(Foldable g, Monoid m) =>
(forall (a :: k). p a -> m) -> g p -> m
Rank2.foldMap (Bool -> Any
Any (Bool -> Any) -> (Const Bool a -> Bool) -> Const Bool a -> Any
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const Bool a -> Bool
forall a k (b :: k). Const a b -> a
getConst) (g (Const Bool) -> Any) -> g (Const Bool) -> Any
forall a b. (a -> b) -> a -> b
$
                                                     (forall a. Const Bool a -> rl s a -> Const Bool a)
-> g (Const Bool) -> g (rl s) -> g (Const Bool)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 ([Expected s]
-> Const Bool a -> GrammarFunctor (p g s) a -> Const Bool a
forall x.
[Expected s]
-> Const Bool x -> GrammarFunctor (p g s) x -> Const Bool x
combineFailures [Expected s]
expected) g (Const Bool)
deps g (rl s)
g (GrammarFunctor (p g s))
marginal)
                                          then rl s x
GrammarFunctor (p g s) x
t' else rl s x
GrammarFunctor (p g s) x
t)
                        in FailureInfo s -> rl s x
forall (f :: * -> * -> *) s a.
FallibleWithExpectations f =>
FailureInfo s -> f s a
failWith (Int -> [Expected s] -> FailureInfo s
forall s. Int -> [Expected s] -> FailureInfo s
FailureInfo Int
pos [Expected s]
expected')
                     where combine :: Const Bool x -> GrammarFunctor (p g s) x -> Const Bool x
                           combineFailures :: [Expected s] -> Const Bool x -> GrammarFunctor (p g s) x -> Const Bool x
                           combine :: Const Bool x -> GrammarFunctor (p g s) x -> Const Bool x
combine (Const False) _ = Bool -> Const Bool x
forall k a (b :: k). a -> Const a b
Const Bool
False
                           combine (Const True) results :: GrammarFunctor (p g s) x
results = Bool -> Const Bool x
forall k a (b :: k). a -> Const a b
Const (rl s x -> Bool
forall (f :: * -> * -> *) s a.
FallibleWithExpectations f =>
f s a -> Bool
hasSuccess rl s x
GrammarFunctor (p g s) x
results)
                           combineFailures :: [Expected s]
-> Const Bool x -> GrammarFunctor (p g s) x -> Const Bool x
combineFailures _ (Const False) _ = Bool -> Const Bool x
forall k a (b :: k). a -> Const a b
Const Bool
False
                           combineFailures expected :: [Expected s]
expected (Const True) rl :: GrammarFunctor (p g s) x
rl = Bool -> Const Bool x
forall k a (b :: k). a -> Const a b
Const ((Expected s -> Bool) -> [Expected s] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Expected s -> [Expected s] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Expected s]
expected) ([Expected s] -> Bool) -> [Expected s] -> Bool
forall a b. (a -> b) -> a -> b
$ rl s x -> [Expected s]
forall (f :: * -> * -> *) s a.
FallibleWithExpectations f =>
f s a -> [Expected s]
expectations rl s x
GrammarFunctor (p g s) x
rl)

         recurseTotal :: s
-> g (GrammarFunctor (p g s) ~> GrammarFunctor (p g s))
-> [(s, g (GrammarFunctor (p g s)))]
-> g (GrammarFunctor (p g s))
-> g (GrammarFunctor (p g s))
recurseTotal s :: s
s initialAppends :: g (GrammarFunctor (p g s) ~> GrammarFunctor (p g s))
initialAppends parsedTail :: [(s, g (GrammarFunctor (p g s)))]
parsedTail total :: g (GrammarFunctor (p g s))
total = (forall a. (~>) (rl s) (rl s) a -> p g s a -> rl s a)
-> g (rl s ~> rl s) -> g (p g s) -> g (rl s)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *)
       (r :: k -> *).
Apply g =>
(forall (a :: k). p a -> q a -> r a) -> g p -> g q -> g r
Rank2.liftA2 forall a. (~>) (rl s) (rl s) a -> p g s a -> rl s a
forall a.
(~>) (GrammarFunctor (p g s)) (GrammarFunctor (p g s)) a
-> p g s a -> GrammarFunctor (p g s) a
reparse g (rl s ~> rl s)
g (GrammarFunctor (p g s) ~> GrammarFunctor (p g s))
initialAppends g (p g s)
indirects
            where reparse :: (GrammarFunctor (p g s) Rank2.~> GrammarFunctor (p g s)) a -> p g s a -> GrammarFunctor (p g s) a
                  reparse :: (~>) (GrammarFunctor (p g s)) (GrammarFunctor (p g s)) a
-> p g s a -> GrammarFunctor (p g s) a
reparse append :: (~>) (GrammarFunctor (p g s)) (GrammarFunctor (p g s)) a
append p :: p g s a
p = Arrow (rl s) (rl s) a -> rl s a -> rl s a
forall k (p :: k -> *) (q :: k -> *) (a :: k).
Arrow p q a -> p a -> q a
Rank2.apply Arrow (rl s) (rl s) a
(~>) (GrammarFunctor (p g s)) (GrammarFunctor (p g s)) a
append (p g s a
-> [(ParserInput (p g s), g (GrammarFunctor (p g s)))]
-> GrammarFunctor (p g s) a
forall (m :: * -> *) (g :: (* -> *) -> *) r.
(TailsParsing m, GrammarConstraint m g) =>
m r
-> [(ParserInput m, g (GrammarFunctor m))] -> GrammarFunctor m r
parseTails p g s a
p ([(ParserInput (p g s), g (GrammarFunctor (p g s)))] -> rl s a)
-> [(ParserInput (p g s), g (GrammarFunctor (p g s)))] -> rl s a
forall a b. (a -> b) -> a -> b
$ (s
s, g (rl s)
g (GrammarFunctor (p g s))
total) (s, g (rl s)) -> [(s, g (rl s))] -> [(s, g (rl s))]
forall a. a -> [a] -> [a]
: [(s, g (rl s))]
[(s, g (GrammarFunctor (p g s)))]
parsedTail)
         recurseMarginal :: s
-> [(s, g (GrammarFunctor (p g s)))]
-> g (GrammarFunctor (p g s))
-> g (GrammarFunctor (p g s))
recurseMarginal s :: s
s parsedTail :: [(s, g (GrammarFunctor (p g s)))]
parsedTail marginal :: g (GrammarFunctor (p g s))
marginal =
            (p g s a -> [(s, g (GrammarFunctor (p g s)))] -> rl s a)
-> [(s, g (GrammarFunctor (p g s)))] -> p g s a -> rl s a
forall a b c. (a -> b -> c) -> b -> a -> c
flip p g s a -> [(s, g (GrammarFunctor (p g s)))] -> rl s a
forall (m :: * -> *) (g :: (* -> *) -> *) r.
(TailsParsing m, GrammarConstraint m g) =>
m r
-> [(ParserInput m, g (GrammarFunctor m))] -> GrammarFunctor m r
parseTails ((s
s, g (GrammarFunctor (p g s))
marginal) (s, g (GrammarFunctor (p g s)))
-> [(s, g (GrammarFunctor (p g s)))]
-> [(s, g (GrammarFunctor (p g s)))]
forall a. a -> [a] -> [a]
: [(s, g (GrammarFunctor (p g s)))]
parsedTail) (forall a. p g s a -> rl s a) -> g (p g s) -> g (rl s)
forall k (g :: (k -> *) -> *) (p :: k -> *) (q :: k -> *).
Functor g =>
(forall (a :: k). p a -> q a) -> g p -> g q
Rank2.<$> g (p g s)
indirects
{-# NOINLINE parseSeparated #-}

class FallibleWithExpectations f where
   hasSuccess   :: f s a -> Bool
   failureOf    :: f s a -> FailureInfo s
   failWith     :: FailureInfo s -> f s a
   expectations :: f s a -> [Expected s]

instance FallibleWithExpectations (ResultList g) where
   hasSuccess :: ResultList g s a -> Bool
hasSuccess (ResultList [] _) = Bool
False
   hasSuccess _ = Bool
True
   failureOf :: ResultList g s a -> FailureInfo s
failureOf (ResultList _ failure :: FailureInfo s
failure) = FailureInfo s
failure
   failWith :: FailureInfo s -> ResultList g s a
failWith = [ResultsOfLength g s a] -> FailureInfo s -> ResultList g s a
forall (g :: (* -> *) -> *) s r.
[ResultsOfLength g s r] -> FailureInfo s -> ResultList g s r
ResultList []
   expectations :: ResultList g s a -> [Expected s]
expectations (ResultList _ (FailureInfo _ expected :: [Expected s]
expected)) = [Expected s]
expected