{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}

-- |
-- Module      : Text.EDE.Internal.Parser
-- Copyright   : (c) 2013-2022 Brendan Hay <brendan.g.hay@gmail.com>
-- License     : This Source Code Form is subject to the terms of
--               the Mozilla Public License, v. 2.0.
--               A copy of the MPL can be found in the LICENSE file or
--               you can obtain it at http://mozilla.org/MPL/2.0/.
-- Maintainer  : Brendan Hay <brendan.g.hay@gmail.com>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)
--
-- /Warning/: this is an internal module, and does not have a stable
-- API or name. Functions in this module may not check or enforce
-- preconditions expected by public modules. Use at your own risk!
module Text.EDE.Internal.Parser where

import Control.Applicative (Alternative ((<|>)))
import qualified Control.Comonad as Comonad
import Control.Comonad.Cofree (Cofree ((:<)))
import Control.Lens ((%=))
import qualified Control.Lens as Lens
import Control.Monad (MonadPlus, unless, void)
import Control.Monad.State.Strict (MonadState, StateT)
import qualified Control.Monad.State.Strict as State
import Control.Monad.Trans (lift)
import Data.Aeson.Types (Value (..))
import Data.ByteString (ByteString)
import qualified Data.Char as Char
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.List.NonEmpty as NonEmpty
import Data.Scientific (Scientific)
import qualified Data.Scientific as Scientific
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text.Encoding
import Data.Vector (Vector)
import qualified Data.Vector as Vector
import Text.EDE.Internal.AST
import Text.EDE.Internal.Compat
import Text.EDE.Internal.Syntax
import Text.EDE.Internal.Types
import qualified Text.Parser.Expression as Expression
import Text.Parser.LookAhead (lookAhead)
import qualified Text.Parser.LookAhead as LookAhead
import Text.Parser.Token.Style (buildSomeSpaceParser)
import Text.Trifecta (DeltaParsing, TokenParsing)
import qualified Text.Trifecta as Trifecta
import Text.Trifecta.Delta (Delta)
import qualified Text.Trifecta.Delta as Trifecta.Delta

data Env = Env
  { Env -> Syntax
_settings :: !Syntax,
    Env -> HashMap Text (NonEmpty Delta)
_includes :: HashMap Text (NonEmpty Delta),
    Env -> HashMap Text (NonEmpty Delta)
_extends :: HashMap Text (NonEmpty Delta),
    Env -> HashMap Text (Exp Delta)
_blocks :: HashMap Text (Exp Delta)
  }

$(Lens.makeLenses ''Env)

instance HasSyntax Env where
  syntax :: Lens' Env Syntax
syntax = (Syntax -> f Syntax) -> Env -> f Env
Lens' Env Syntax
settings

type Parser m =
  ( Monad m,
    MonadFail m,
    MonadState Env m,
    Trifecta.TokenParsing m,
    Trifecta.DeltaParsing m,
    LookAhead.LookAheadParsing m,
    Trifecta.Errable m
  )

newtype EDE a = EDE {forall a. EDE a -> Parser a
runEDE :: Trifecta.Parser a}
  deriving
    ( (forall a b. (a -> b) -> EDE a -> EDE b)
-> (forall a b. a -> EDE b -> EDE a) -> Functor EDE
forall a b. a -> EDE b -> EDE a
forall a b. (a -> b) -> EDE a -> EDE b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> EDE a -> EDE b
fmap :: forall a b. (a -> b) -> EDE a -> EDE b
$c<$ :: forall a b. a -> EDE b -> EDE a
<$ :: forall a b. a -> EDE b -> EDE a
Functor,
      Functor EDE
Functor EDE =>
(forall a. a -> EDE a)
-> (forall a b. EDE (a -> b) -> EDE a -> EDE b)
-> (forall a b c. (a -> b -> c) -> EDE a -> EDE b -> EDE c)
-> (forall a b. EDE a -> EDE b -> EDE b)
-> (forall a b. EDE a -> EDE b -> EDE a)
-> Applicative EDE
forall a. a -> EDE a
forall a b. EDE a -> EDE b -> EDE a
forall a b. EDE a -> EDE b -> EDE b
forall a b. EDE (a -> b) -> EDE a -> EDE b
forall a b c. (a -> b -> c) -> EDE a -> EDE b -> EDE c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall a. a -> EDE a
pure :: forall a. a -> EDE a
$c<*> :: forall a b. EDE (a -> b) -> EDE a -> EDE b
<*> :: forall a b. EDE (a -> b) -> EDE a -> EDE b
$cliftA2 :: forall a b c. (a -> b -> c) -> EDE a -> EDE b -> EDE c
liftA2 :: forall a b c. (a -> b -> c) -> EDE a -> EDE b -> EDE c
$c*> :: forall a b. EDE a -> EDE b -> EDE b
*> :: forall a b. EDE a -> EDE b -> EDE b
$c<* :: forall a b. EDE a -> EDE b -> EDE a
<* :: forall a b. EDE a -> EDE b -> EDE a
Applicative,
      Applicative EDE
Applicative EDE =>
(forall a. EDE a)
-> (forall a. EDE a -> EDE a -> EDE a)
-> (forall a. EDE a -> EDE [a])
-> (forall a. EDE a -> EDE [a])
-> Alternative EDE
forall a. EDE a
forall a. EDE a -> EDE [a]
forall a. EDE a -> EDE a -> EDE a
forall (f :: * -> *).
Applicative f =>
(forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
$cempty :: forall a. EDE a
empty :: forall a. EDE a
$c<|> :: forall a. EDE a -> EDE a -> EDE a
<|> :: forall a. EDE a -> EDE a -> EDE a
$csome :: forall a. EDE a -> EDE [a]
some :: forall a. EDE a -> EDE [a]
$cmany :: forall a. EDE a -> EDE [a]
many :: forall a. EDE a -> EDE [a]
Alternative,
      Applicative EDE
Applicative EDE =>
(forall a b. EDE a -> (a -> EDE b) -> EDE b)
-> (forall a b. EDE a -> EDE b -> EDE b)
-> (forall a. a -> EDE a)
-> Monad EDE
forall a. a -> EDE a
forall a b. EDE a -> EDE b -> EDE b
forall a b. EDE a -> (a -> EDE b) -> EDE b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall a b. EDE a -> (a -> EDE b) -> EDE b
>>= :: forall a b. EDE a -> (a -> EDE b) -> EDE b
$c>> :: forall a b. EDE a -> EDE b -> EDE b
>> :: forall a b. EDE a -> EDE b -> EDE b
$creturn :: forall a. a -> EDE a
return :: forall a. a -> EDE a
Monad,
      Monad EDE
Monad EDE => (forall a. String -> EDE a) -> MonadFail EDE
forall a. String -> EDE a
forall (m :: * -> *).
Monad m =>
(forall a. String -> m a) -> MonadFail m
$cfail :: forall a. String -> EDE a
fail :: forall a. String -> EDE a
MonadFail,
      Monad EDE
Alternative EDE
(Alternative EDE, Monad EDE) =>
(forall a. EDE a)
-> (forall a. EDE a -> EDE a -> EDE a) -> MonadPlus EDE
forall a. EDE a
forall a. EDE a -> EDE a -> EDE a
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
$cmzero :: forall a. EDE a
mzero :: forall a. EDE a
$cmplus :: forall a. EDE a -> EDE a -> EDE a
mplus :: forall a. EDE a -> EDE a -> EDE a
MonadPlus,
      Alternative EDE
EDE ()
Alternative EDE =>
(forall a. EDE a -> EDE a)
-> (forall a. EDE a -> String -> EDE a)
-> (forall a. EDE a -> EDE ())
-> (forall a. EDE a -> EDE ())
-> (forall a. String -> EDE a)
-> EDE ()
-> (forall a. Show a => EDE a -> EDE ())
-> Parsing EDE
forall a. Show a => EDE a -> EDE ()
forall a. String -> EDE a
forall a. EDE a -> EDE a
forall a. EDE a -> EDE ()
forall a. EDE a -> String -> EDE a
forall (m :: * -> *).
Alternative m =>
(forall a. m a -> m a)
-> (forall a. m a -> String -> m a)
-> (forall a. m a -> m ())
-> (forall a. m a -> m ())
-> (forall a. String -> m a)
-> m ()
-> (forall a. Show a => m a -> m ())
-> Parsing m
$ctry :: forall a. EDE a -> EDE a
try :: forall a. EDE a -> EDE a
$c<?> :: forall a. EDE a -> String -> EDE a
<?> :: forall a. EDE a -> String -> EDE a
$cskipMany :: forall a. EDE a -> EDE ()
skipMany :: forall a. EDE a -> EDE ()
$cskipSome :: forall a. EDE a -> EDE ()
skipSome :: forall a. EDE a -> EDE ()
$cunexpected :: forall a. String -> EDE a
unexpected :: forall a. String -> EDE a
$ceof :: EDE ()
eof :: EDE ()
$cnotFollowedBy :: forall a. Show a => EDE a -> EDE ()
notFollowedBy :: forall a. Show a => EDE a -> EDE ()
Trifecta.Parsing,
      Parsing EDE
EDE Char
Char -> EDE Char
String -> EDE String
Text -> EDE Text
Parsing EDE =>
((Char -> Bool) -> EDE Char)
-> (Char -> EDE Char)
-> (Char -> EDE Char)
-> EDE Char
-> (String -> EDE String)
-> (Text -> EDE Text)
-> CharParsing EDE
(Char -> Bool) -> EDE Char
forall (m :: * -> *).
Parsing m =>
((Char -> Bool) -> m Char)
-> (Char -> m Char)
-> (Char -> m Char)
-> m Char
-> (String -> m String)
-> (Text -> m Text)
-> CharParsing m
$csatisfy :: (Char -> Bool) -> EDE Char
satisfy :: (Char -> Bool) -> EDE Char
$cchar :: Char -> EDE Char
char :: Char -> EDE Char
$cnotChar :: Char -> EDE Char
notChar :: Char -> EDE Char
$canyChar :: EDE Char
anyChar :: EDE Char
$cstring :: String -> EDE String
string :: String -> EDE String
$ctext :: Text -> EDE Text
text :: Text -> EDE Text
Trifecta.CharParsing,
      MonadPlus EDE
TokenParsing EDE
EDE ByteString
EDE Delta
EDE Rendering
(MonadPlus EDE, TokenParsing EDE) =>
EDE ByteString
-> EDE Delta
-> (forall a r. (a -> ByteString -> r) -> EDE a -> EDE r)
-> EDE Rendering
-> EDE ByteString
-> DeltaParsing EDE
forall a r. (a -> ByteString -> r) -> EDE a -> EDE r
forall (m :: * -> *).
(MonadPlus m, TokenParsing m) =>
m ByteString
-> m Delta
-> (forall a r. (a -> ByteString -> r) -> m a -> m r)
-> m Rendering
-> m ByteString
-> DeltaParsing m
$cline :: EDE ByteString
line :: EDE ByteString
$cposition :: EDE Delta
position :: EDE Delta
$cslicedWith :: forall a r. (a -> ByteString -> r) -> EDE a -> EDE r
slicedWith :: forall a r. (a -> ByteString -> r) -> EDE a -> EDE r
$crend :: EDE Rendering
rend :: EDE Rendering
$crestOfLine :: EDE ByteString
restOfLine :: EDE ByteString
Trifecta.DeltaParsing,
      Parsing EDE
Parsing EDE => (forall a. EDE a -> EDE a) -> LookAheadParsing EDE
forall a. EDE a -> EDE a
forall (m :: * -> *).
Parsing m =>
(forall a. m a -> m a) -> LookAheadParsing m
$clookAhead :: forall a. EDE a -> EDE a
lookAhead :: forall a. EDE a -> EDE a
LookAhead.LookAheadParsing,
      (forall a. Err -> EDE a) -> Errable EDE
forall a. Err -> EDE a
forall (m :: * -> *). (forall a. Err -> m a) -> Errable m
$craiseErr :: forall a. Err -> EDE a
raiseErr :: forall a. Err -> EDE a
Trifecta.Errable
    )

instance TokenParsing EDE where
  nesting :: forall a. EDE a -> EDE a
nesting (EDE Parser a
m) =
    Parser a -> EDE a
forall a. Parser a -> EDE a
EDE (Parser a -> EDE a) -> Parser a -> EDE a
forall a b. (a -> b) -> a -> b
$ Parser a -> Parser a
forall a. Parser a -> Parser a
forall (m :: * -> *) a. TokenParsing m => m a -> m a
Trifecta.nesting Parser a
m
  {-# INLINE nesting #-}

  someSpace :: EDE ()
someSpace =
    Parser () -> EDE ()
forall a. Parser a -> EDE a
EDE (Parser () -> EDE ()) -> Parser () -> EDE ()
forall a b. (a -> b) -> a -> b
$ Parser Char -> Parser ()
forall a. Parser a -> Parser ()
forall (m :: * -> *) a. Parsing m => m a -> m ()
Trifecta.skipMany ((Char -> Bool) -> Parser Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
Trifecta.satisfy ((Char -> Bool) -> Parser Char) -> (Char -> Bool) -> Parser Char
forall a b. (a -> b) -> a -> b
$ \Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\n' Bool -> Bool -> Bool
&& Char -> Bool
Char.isSpace Char
c)
  {-# INLINE someSpace #-}

  semi :: EDE Char
semi =
    Parser Char -> EDE Char
forall a. Parser a -> EDE a
EDE Parser Char
forall (m :: * -> *). TokenParsing m => m Char
Trifecta.semi
  {-# INLINE semi #-}

  highlight :: forall a. Highlight -> EDE a -> EDE a
highlight Highlight
h (EDE Parser a
m) = Parser a -> EDE a
forall a. Parser a -> EDE a
EDE (Highlight -> Parser a -> Parser a
forall a. Highlight -> Parser a -> Parser a
forall (m :: * -> *) a. TokenParsing m => Highlight -> m a -> m a
Trifecta.highlight Highlight
h Parser a
m)
  {-# INLINE highlight #-}

instance Trifecta.Errable (StateT Env EDE) where
  raiseErr :: forall a. Err -> StateT Env EDE a
raiseErr = EDE a -> StateT Env EDE a
forall (m :: * -> *) a. Monad m => m a -> StateT Env m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (EDE a -> StateT Env EDE a)
-> (Err -> EDE a) -> Err -> StateT Env EDE a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Err -> EDE a
forall a. Err -> EDE a
forall (m :: * -> *) a. Errable m => Err -> m a
Trifecta.raiseErr

runParser ::
  Syntax ->
  Text ->
  ByteString ->
  Result (Exp Delta, HashMap Text (NonEmpty Delta), HashMap Text (NonEmpty Delta), HashMap Text (Exp Delta))
runParser :: Syntax
-> Text
-> ByteString
-> Result
     (Exp Delta, HashMap Text (NonEmpty Delta),
      HashMap Text (NonEmpty Delta), HashMap Text (Exp Delta))
runParser Syntax
o Text
n = Result (Exp Delta, Env)
-> Result
     (Exp Delta, HashMap Text (NonEmpty Delta),
      HashMap Text (NonEmpty Delta), HashMap Text (Exp Delta))
res (Result (Exp Delta, Env)
 -> Result
      (Exp Delta, HashMap Text (NonEmpty Delta),
       HashMap Text (NonEmpty Delta), HashMap Text (Exp Delta)))
-> (ByteString -> Result (Exp Delta, Env))
-> ByteString
-> Result
     (Exp Delta, HashMap Text (NonEmpty Delta),
      HashMap Text (NonEmpty Delta), HashMap Text (Exp Delta))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser (Exp Delta, Env)
-> Delta -> ByteString -> Result (Exp Delta, Env)
forall a. Parser a -> Delta -> ByteString -> Result a
Trifecta.parseByteString (EDE (Exp Delta, Env) -> Parser (Exp Delta, Env)
forall a. EDE a -> Parser a
runEDE EDE (Exp Delta, Env)
run) Delta
pos
  where
    run :: EDE (Exp Delta, Env)
run = StateT Env EDE (Exp Delta) -> Env -> EDE (Exp Delta, Env)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
State.runStateT (StateT Env EDE ()
forall (m :: * -> *). Parser m => m ()
pragma StateT Env EDE ()
-> StateT Env EDE (Exp Delta) -> StateT Env EDE (Exp Delta)
forall a b.
StateT Env EDE a -> StateT Env EDE b -> StateT Env EDE b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> StateT Env EDE (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
document StateT Env EDE (Exp Delta)
-> StateT Env EDE () -> StateT Env EDE (Exp Delta)
forall a b.
StateT Env EDE a -> StateT Env EDE b -> StateT Env EDE a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* StateT Env EDE ()
forall (m :: * -> *). Parsing m => m ()
Trifecta.eof) (Syntax
-> HashMap Text (NonEmpty Delta)
-> HashMap Text (NonEmpty Delta)
-> HashMap Text (Exp Delta)
-> Env
Env Syntax
o HashMap Text (NonEmpty Delta)
forall a. Monoid a => a
mempty HashMap Text (NonEmpty Delta)
forall a. Monoid a => a
mempty HashMap Text (Exp Delta)
forall a. Monoid a => a
mempty)

    pos :: Delta
pos = ByteString -> Int64 -> Int64 -> Int64 -> Int64 -> Delta
Trifecta.Delta.Directed (Text -> ByteString
Text.Encoding.encodeUtf8 Text
n) Int64
0 Int64
0 Int64
0 Int64
0

    res :: Result (Exp Delta, Env)
-> Result
     (Exp Delta, HashMap Text (NonEmpty Delta),
      HashMap Text (NonEmpty Delta), HashMap Text (Exp Delta))
res = \case
      Trifecta.Success (Exp Delta
x, Env
env) ->
        if HashMap Text (NonEmpty Delta) -> Bool
forall a. HashMap Text a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Env -> HashMap Text (NonEmpty Delta)
_extends Env
env) then
          (Exp Delta, HashMap Text (NonEmpty Delta),
 HashMap Text (NonEmpty Delta), HashMap Text (Exp Delta))
-> Result
     (Exp Delta, HashMap Text (NonEmpty Delta),
      HashMap Text (NonEmpty Delta), HashMap Text (Exp Delta))
forall a. a -> Result a
Success (Exp Delta
x, Env -> HashMap Text (NonEmpty Delta)
_includes Env
env, Env -> HashMap Text (NonEmpty Delta)
_extends Env
env, Env -> HashMap Text (Exp Delta)
_blocks Env
env)
        else
          -- In case the template extends another template we arrange the contained
          -- blocks in a way that make it easy to evaluate the "inheritance" mechanism.
          let
            x' :: Exp Delta
x' =
              (Text -> Exp Delta -> Exp Delta -> Exp Delta)
-> Exp Delta -> HashMap Text (Exp Delta) -> Exp Delta
forall k v a. (k -> v -> a -> a) -> a -> HashMap k v -> a
HashMap.foldrWithKey Text -> Exp Delta -> Exp Delta -> Exp Delta
forall a. Text -> Exp a -> Exp a -> Exp a
eOverrideBlock Exp Delta
x (Env -> HashMap Text (Exp Delta)
_blocks Env
env)
          in
            (Exp Delta, HashMap Text (NonEmpty Delta),
 HashMap Text (NonEmpty Delta), HashMap Text (Exp Delta))
-> Result
     (Exp Delta, HashMap Text (NonEmpty Delta),
      HashMap Text (NonEmpty Delta), HashMap Text (Exp Delta))
forall a. a -> Result a
Success (Exp Delta
x', Env -> HashMap Text (NonEmpty Delta)
_includes Env
env, Env -> HashMap Text (NonEmpty Delta)
_extends Env
env, Env -> HashMap Text (Exp Delta)
_blocks Env
env)
      Trifecta.Failure ErrInfo
e -> AnsiDoc
-> Result
     (Exp Delta, HashMap Text (NonEmpty Delta),
      HashMap Text (NonEmpty Delta), HashMap Text (Exp Delta))
forall a. AnsiDoc -> Result a
Failure (ErrInfo -> AnsiDoc
Trifecta._errDoc ErrInfo
e)

pragma :: Parser m => m ()
pragma :: forall (m :: * -> *). Parser m => m ()
pragma =
  m [()] -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m [()] -> m ()) -> (m () -> m [()]) -> m () -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m () -> m [()]
forall a. m a -> m [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
Trifecta.many (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    ![((Delim -> Identity Delim) -> Env -> Identity Env, Delim)]
xs <-
      m String
forall (m :: * -> *). Parser m => m String
pragmal
        m String -> m String -> m String
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> String -> m String
forall (m :: * -> *). TokenParsing m => String -> m String
Trifecta.symbol String
"EDE_SYNTAX"
        m String
-> m [((Delim -> Identity Delim) -> Env -> Identity Env, Delim)]
-> m [((Delim -> Identity Delim) -> Env -> Identity Env, Delim)]
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m ((Delim -> Identity Delim) -> Env -> Identity Env, Delim)
-> m ()
-> m [((Delim -> Identity Delim) -> Env -> Identity Env, Delim)]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
Trifecta.sepBy m ((Delim -> Identity Delim) -> Env -> Identity Env, Delim)
field m ()
forall (m :: * -> *). (Monad m, TokenParsing m) => m ()
spaces
        m [((Delim -> Identity Delim) -> Env -> Identity Env, Delim)]
-> m String
-> m [((Delim -> Identity Delim) -> Env -> Identity Env, Delim)]
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m String -> m String
forall (m :: * -> *) a. Parser m => m a -> m a
trimr m String
forall (m :: * -> *). Parser m => m String
pragmar

    (((Delim -> Identity Delim) -> Env -> Identity Env, Delim) -> m ())
-> [((Delim -> Identity Delim) -> Env -> Identity Env, Delim)]
-> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ((((Delim -> Identity Delim) -> Env -> Identity Env)
 -> Delim -> m ())
-> ((Delim -> Identity Delim) -> Env -> Identity Env, Delim)
-> m ()
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((Delim -> Identity Delim) -> Env -> Identity Env) -> Delim -> m ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
Lens.assign) [((Delim -> Identity Delim) -> Env -> Identity Env, Delim)]
xs
  where
    field :: m ((Delim -> Identity Delim) -> Env -> Identity Env, Delim)
field =
      (,)
        (((Delim -> Identity Delim) -> Env -> Identity Env)
 -> Delim
 -> ((Delim -> Identity Delim) -> Env -> Identity Env, Delim))
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m (Delim
      -> ((Delim -> Identity Delim) -> Env -> Identity Env, Delim))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m ((Delim -> Identity Delim) -> Env -> Identity Env)
setter m (Delim
   -> ((Delim -> Identity Delim) -> Env -> Identity Env, Delim))
-> m String
-> m (Delim
      -> ((Delim -> Identity Delim) -> Env -> Identity Env, Delim))
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> m String
forall (m :: * -> *). TokenParsing m => String -> m String
Trifecta.symbol String
"="
        m (Delim
   -> ((Delim -> Identity Delim) -> Env -> Identity Env, Delim))
-> m Delim
-> m ((Delim -> Identity Delim) -> Env -> Identity Env, Delim)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Delim -> m Delim
forall (m :: * -> *) a. TokenParsing m => m a -> m a
Trifecta.parens m Delim
delim

    delim :: m Delim
delim =
      (,)
        (String -> String -> Delim) -> m String -> m (String -> Delim)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m String
forall (m :: * -> *) s. (TokenParsing m, IsString s) => m s
Trifecta.stringLiteral m (String -> Delim) -> m String -> m (String -> Delim)
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> m String
forall (m :: * -> *). TokenParsing m => String -> m String
Trifecta.symbol String
","
        m (String -> Delim) -> m String -> m Delim
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m String
forall (m :: * -> *) s. (TokenParsing m, IsString s) => m s
Trifecta.stringLiteral

    setter :: m ((Delim -> Identity Delim) -> Env -> Identity Env)
setter =
      String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
pragmak String
"pragma" m ()
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Delim -> Identity Delim) -> Env -> Identity Env
forall c. HasSyntax c => Lens' c Delim
Lens' Env Delim
delimPragma
        m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
pragmak String
"inline" m ()
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Delim -> Identity Delim) -> Env -> Identity Env
forall c. HasSyntax c => Lens' c Delim
Lens' Env Delim
delimInline
        m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
pragmak String
"comment" m ()
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Delim -> Identity Delim) -> Env -> Identity Env
forall c. HasSyntax c => Lens' c Delim
Lens' Env Delim
delimComment
        m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
pragmak String
"block" m ()
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Delim -> Identity Delim) -> Env -> Identity Env
forall c. HasSyntax c => Lens' c Delim
Lens' Env Delim
delimBlock

document :: Parser m => m (Exp Delta)
document :: forall (m :: * -> *). Parser m => m (Exp Delta)
document =
  Delta -> [Exp Delta] -> Exp Delta
forall a. a -> [Exp a] -> Exp a
eapp
    (Delta -> [Exp Delta] -> Exp Delta)
-> m Delta -> m ([Exp Delta] -> Exp Delta)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Delta
forall (m :: * -> *). DeltaParsing m => m Delta
Trifecta.position
    m ([Exp Delta] -> Exp Delta) -> m [Exp Delta] -> m (Exp Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Exp Delta) -> m [Exp Delta]
forall a. m a -> m [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
Trifecta.many (m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
blankLine m (Exp Delta) -> m (Exp Delta) -> m (Exp Delta)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
statement m (Exp Delta) -> m (Exp Delta) -> m (Exp Delta)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
inline m (Exp Delta) -> m (Exp Delta) -> m (Exp Delta)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
fragment)

inline :: Parser m => m (Exp Delta)
inline :: forall (m :: * -> *). Parser m => m (Exp Delta)
inline = m String -> m String -> m (Exp Delta) -> m (Exp Delta)
forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
Trifecta.between m String
forall (m :: * -> *). Parser m => m String
inlinel m String
forall (m :: * -> *). Parser m => m String
inliner m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
term

fragment :: Parser m => m (Exp Delta)
fragment :: forall (m :: * -> *). Parser m => m (Exp Delta)
fragment =
  m (ExpF (Fix ExpF)) -> m (Exp Delta)
forall (m :: * -> *) (f :: * -> *).
(DeltaParsing m, Functor f) =>
m (f (Fix f)) -> m (Cofree f Delta)
ann (Value -> ExpF (Fix ExpF)
forall a. Value -> ExpF a
ELit (Value -> ExpF (Fix ExpF)) -> m Value -> m (ExpF (Fix ExpF))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m String -> m Value
forall (f :: * -> *). Functor f => f String -> f Value
pack (m () -> m ()
forall a. Show a => m a -> m ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
Trifecta.notFollowedBy m ()
end0 m () -> m String -> m String
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> m String -> m String
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
Trifecta.try m String
line0 m String -> m String -> m String
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m String
line1))
  where
    line0 :: m String
line0 = m Char -> m () -> m String
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
manyTill1 (String -> m Char
forall (m :: * -> *). CharParsing m => String -> m Char
Trifecta.noneOf String
"\n") (m () -> m ()
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
Trifecta.try (m () -> m ()
forall a. m a -> m a
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead m ()
end0) m () -> m () -> m ()
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m ()
forall (m :: * -> *). Parsing m => m ()
Trifecta.eof)
    line1 :: m String
line1 = m Char -> m Char -> m String
forall (m :: * -> *) a. Alternative m => m a -> m a -> m [a]
manyEndBy1 m Char
forall (m :: * -> *). CharParsing m => m Char
Trifecta.anyChar m Char
forall (m :: * -> *). CharParsing m => m Char
Trifecta.newline

    end0 :: m ()
end0 = m String -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m String
forall (m :: * -> *). Parser m => m String
inlinel m String -> m String -> m String
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m String
forall (m :: * -> *). Parser m => m String
blockl m String -> m String -> m String
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m String -> m String
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
Trifecta.try m String
end1)
    end1 :: m String
end1 = m () -> m String -> m String
forall (m :: * -> *) b a. Parser m => m b -> m a -> m a
multiLine (() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) (m Char -> m String -> m String
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
manyTill1 m Char
forall (m :: * -> *). CharParsing m => m Char
Trifecta.anyChar (m String -> m String
forall a. m a -> m a
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead m String
forall (m :: * -> *). Parser m => m String
blockr))

statement :: Parser m => m (Exp Delta)
statement :: forall (m :: * -> *). Parser m => m (Exp Delta)
statement =
  [m (Exp Delta)] -> m (Exp Delta)
forall (m :: * -> *) a. Alternative m => [m a] -> m a
Trifecta.choice
    [ m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
ifelif,
      m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
cases,
      m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
loop,
      m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
include,
      m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
set,
      m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
block',
      m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
extends',
      m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
binding,
      m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
raw,
      m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
comment
    ]

block :: Parser m => String -> m a -> m a
block :: forall (m :: * -> *) a. Parser m => String -> m a -> m a
block String
k m a
p =
  m a -> m a
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
Trifecta.try (m Delta -> m a -> m a
forall (m :: * -> *) b a. Parser m => m b -> m a -> m a
multiLine (String -> m Delta
forall (m :: * -> *). Parser m => String -> m Delta
keyword String
k) m a
p)
    m a -> m a -> m a
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m Delta -> m a -> m a
forall (m :: * -> *) b a. Parser m => m b -> m a -> m a
singleLine (String -> m Delta
forall (m :: * -> *). Parser m => String -> m Delta
keyword String
k) m a
p

multiLine :: Parser m => m b -> m a -> m a
multiLine :: forall (m :: * -> *) b a. Parser m => m b -> m a -> m a
multiLine m b
s =
  m b -> m String -> m a -> m a
forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
Trifecta.between (m b -> m b
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
Trifecta.try (m String -> m String
forall (m :: * -> *) a. Parser m => m a -> m a
triml m String
forall (m :: * -> *). Parser m => m String
blockl m String -> m b -> m b
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m b
s)) (m String -> m String
forall (m :: * -> *) a. Parser m => m a -> m a
trimr m String
forall (m :: * -> *). Parser m => m String
blockr)

singleLine :: Parser m => m b -> m a -> m a
singleLine :: forall (m :: * -> *) b a. Parser m => m b -> m a -> m a
singleLine m b
s =
  m b -> m String -> m a -> m a
forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
Trifecta.between (m b -> m b
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
Trifecta.try (m String
forall (m :: * -> *). Parser m => m String
blockl m String -> m b -> m b
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m b
s)) m String
forall (m :: * -> *). Parser m => m String
blockr

blankLine :: Parser m => m (Exp Delta)
blankLine :: forall (m :: * -> *). Parser m => m (Exp Delta)
blankLine = do
  Int64
c <- Delta -> Int64
forall t. HasDelta t => t -> Int64
Trifecta.Delta.column (Delta -> Int64) -> m Delta -> m Int64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Delta
forall (m :: * -> *). DeltaParsing m => m Delta
Trifecta.position

  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Int64
c Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== Int64
0) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
    String -> m ()
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"expected blank line"

  m (ExpF (Fix ExpF)) -> m (Exp Delta)
forall (m :: * -> *) (f :: * -> *).
(DeltaParsing m, Functor f) =>
m (f (Fix f)) -> m (Cofree f Delta)
ann (Value -> ExpF (Fix ExpF)
forall a. Value -> ExpF a
ELit (Value -> ExpF (Fix ExpF))
-> (Char -> Value) -> Char -> ExpF (Fix ExpF)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Value
String (Text -> Value) -> (Char -> Text) -> Char -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
Text.singleton (Char -> ExpF (Fix ExpF)) -> m Char -> m (ExpF (Fix ExpF))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char
forall (m :: * -> *). CharParsing m => m Char
Trifecta.newline)

ifelif :: Parser m => m (Exp Delta)
ifelif :: forall (m :: * -> *). Parser m => m (Exp Delta)
ifelif =
  (Exp Delta, Exp Delta)
-> [(Exp Delta, Exp Delta)] -> Maybe (Exp Delta) -> Exp Delta
forall a.
(Exp a, Exp a) -> [(Exp a, Exp a)] -> Maybe (Exp a) -> Exp a
eif
    ((Exp Delta, Exp Delta)
 -> [(Exp Delta, Exp Delta)] -> Maybe (Exp Delta) -> Exp Delta)
-> m (Exp Delta, Exp Delta)
-> m ([(Exp Delta, Exp Delta)] -> Maybe (Exp Delta) -> Exp Delta)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Exp Delta, Exp Delta)
forall {f :: * -> *}.
(MonadFail f, MonadState Env f, DeltaParsing f, LookAheadParsing f,
 Errable f) =>
String -> f (Exp Delta, Exp Delta)
branch String
"if"
    m ([(Exp Delta, Exp Delta)] -> Maybe (Exp Delta) -> Exp Delta)
-> m [(Exp Delta, Exp Delta)] -> m (Maybe (Exp Delta) -> Exp Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Exp Delta, Exp Delta) -> m [(Exp Delta, Exp Delta)]
forall a. m a -> m [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
Trifecta.many (String -> m (Exp Delta, Exp Delta)
forall {f :: * -> *}.
(MonadFail f, MonadState Env f, DeltaParsing f, LookAheadParsing f,
 Errable f) =>
String -> f (Exp Delta, Exp Delta)
branch String
"elif")
    m (Maybe (Exp Delta) -> Exp Delta)
-> m (Maybe (Exp Delta)) -> m (Exp Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Maybe (Exp Delta))
forall (m :: * -> *). Parser m => m (Maybe (Exp Delta))
else'
    m (Exp Delta) -> m () -> m (Exp Delta)
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
exit String
"endif"
  where
    branch :: String -> f (Exp Delta, Exp Delta)
branch String
k = (,) (Exp Delta -> Exp Delta -> (Exp Delta, Exp Delta))
-> f (Exp Delta) -> f (Exp Delta -> (Exp Delta, Exp Delta))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> f (Exp Delta) -> f (Exp Delta)
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block String
k f (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
term f (Exp Delta -> (Exp Delta, Exp Delta))
-> f (Exp Delta) -> f (Exp Delta, Exp Delta)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
document

cases :: Parser m => m (Exp Delta)
cases :: forall (m :: * -> *). Parser m => m (Exp Delta)
cases =
  Exp Delta -> [Alt (Exp Delta)] -> Maybe (Exp Delta) -> Exp Delta
forall a. Exp a -> [Alt (Exp a)] -> Maybe (Exp a) -> Exp a
ecase
    (Exp Delta -> [Alt (Exp Delta)] -> Maybe (Exp Delta) -> Exp Delta)
-> m (Exp Delta)
-> m ([Alt (Exp Delta)] -> Maybe (Exp Delta) -> Exp Delta)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Exp Delta) -> m (Exp Delta)
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block String
"case" m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
term
    m ([Alt (Exp Delta)] -> Maybe (Exp Delta) -> Exp Delta)
-> m [Alt (Exp Delta)] -> m (Maybe (Exp Delta) -> Exp Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Alt (Exp Delta)) -> m [Alt (Exp Delta)]
forall a. m a -> m [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
Trifecta.many
      ( (,) (Pat -> Exp Delta -> Alt (Exp Delta))
-> m Pat -> m (Exp Delta -> Alt (Exp Delta))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m Pat -> m Pat
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block String
"when" m Pat
forall (m :: * -> *). Parser m => m Pat
pattern
          m (Exp Delta -> Alt (Exp Delta))
-> m (Exp Delta) -> m (Alt (Exp Delta))
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
document
      )
    m (Maybe (Exp Delta) -> Exp Delta)
-> m (Maybe (Exp Delta)) -> m (Exp Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Maybe (Exp Delta))
forall (m :: * -> *). Parser m => m (Maybe (Exp Delta))
else'
    m (Exp Delta) -> m () -> m (Exp Delta)
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
exit String
"endcase"

loop :: Parser m => m (Exp Delta)
loop :: forall (m :: * -> *). Parser m => m (Exp Delta)
loop = do
  (Text
i, Exp Delta
v) <-
    String -> m (Text, Exp Delta) -> m (Text, Exp Delta)
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block
      String
"for"
      ( (,) (Text -> Exp Delta -> (Text, Exp Delta))
-> m Text -> m (Exp Delta -> (Text, Exp Delta))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Text
forall (m :: * -> *). (Monad m, TokenParsing m) => m Text
identifier
          m (Exp Delta -> (Text, Exp Delta))
-> m (Exp Delta) -> m (Text, Exp Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (String -> m Delta
forall (m :: * -> *). Parser m => String -> m Delta
keyword String
"in" m Delta -> m (Exp Delta) -> m (Exp Delta)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
collection)
      )
  Exp Delta
d <- m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
document
  Exp Delta -> Exp Delta -> Maybe (Exp Delta) -> Exp Delta
forall a. Exp a -> Exp a -> Maybe (Exp a) -> Exp a
eempty Exp Delta
v (Exp Delta -> Delta
forall a. Cofree ExpF a -> a
forall (w :: * -> *) a. Comonad w => w a -> a
Comonad.extract Exp Delta
v Delta -> ExpF (Exp Delta) -> Exp Delta
forall (f :: * -> *) a. a -> f (Cofree f a) -> Cofree f a
:< Text -> Exp Delta -> Exp Delta -> ExpF (Exp Delta)
forall a. Text -> a -> a -> ExpF a
ELoop Text
i Exp Delta
v Exp Delta
d)
    (Maybe (Exp Delta) -> Exp Delta)
-> m (Maybe (Exp Delta)) -> m (Exp Delta)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Maybe (Exp Delta))
forall (m :: * -> *). Parser m => m (Maybe (Exp Delta))
else'
    m (Exp Delta) -> m () -> m (Exp Delta)
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
exit String
"endfor"

include :: Parser m => m (Exp Delta)
include :: forall (m :: * -> *). Parser m => m (Exp Delta)
include = String -> m (Exp Delta) -> m (Exp Delta)
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block String
"include" (m (Exp Delta) -> m (Exp Delta)) -> m (Exp Delta) -> m (Exp Delta)
forall a b. (a -> b) -> a -> b
$ do
  Delta
d <- m Delta
forall (m :: * -> *). DeltaParsing m => m Delta
Trifecta.position
  Text
k <- m Text
forall (m :: * -> *) s. (TokenParsing m, IsString s) => m s
Trifecta.stringLiteral
  (HashMap Text (NonEmpty Delta)
 -> Identity (HashMap Text (NonEmpty Delta)))
-> Env -> Identity Env
Lens' Env (HashMap Text (NonEmpty Delta))
includes ((HashMap Text (NonEmpty Delta)
  -> Identity (HashMap Text (NonEmpty Delta)))
 -> Env -> Identity Env)
-> (HashMap Text (NonEmpty Delta) -> HashMap Text (NonEmpty Delta))
-> m ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (NonEmpty Delta -> NonEmpty Delta -> NonEmpty Delta)
-> Text
-> NonEmpty Delta
-> HashMap Text (NonEmpty Delta)
-> HashMap Text (NonEmpty Delta)
forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
HashMap.insertWith NonEmpty Delta -> NonEmpty Delta -> NonEmpty Delta
forall a. Semigroup a => a -> a -> a
(<>) Text
k (Delta
d Delta -> [Delta] -> NonEmpty Delta
forall a. a -> [a] -> NonEmpty a
:| [])
  Maybe (Text, Exp Delta) -> Exp Delta -> Exp Delta
forall a. Maybe (Text, Exp a) -> Exp a -> Exp a
elet (Maybe (Text, Exp Delta) -> Exp Delta -> Exp Delta)
-> m (Maybe (Text, Exp Delta)) -> m (Exp Delta -> Exp Delta)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Maybe (Text, Exp Delta))
scope m (Exp Delta -> Exp Delta) -> m (Exp Delta) -> m (Exp Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Exp Delta -> m (Exp Delta)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Delta
d Delta -> ExpF (Exp Delta) -> Exp Delta
forall (f :: * -> *) a. a -> f (Cofree f a) -> Cofree f a
:< Text -> ExpF (Exp Delta)
forall a. Text -> ExpF a
EIncl Text
k)
  where
    scope :: m (Maybe (Text, Exp Delta))
scope =
      m (Text, Exp Delta) -> m (Maybe (Text, Exp Delta))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
Trifecta.optional (m (Text, Exp Delta) -> m (Maybe (Text, Exp Delta)))
-> m (Text, Exp Delta) -> m (Maybe (Text, Exp Delta))
forall a b. (a -> b) -> a -> b
$
        (,) (Text -> Exp Delta -> (Text, Exp Delta))
-> m Text -> m (Exp Delta -> (Text, Exp Delta))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> m Delta
forall (m :: * -> *). Parser m => String -> m Delta
keyword String
"with" m Delta -> m Text -> m Text
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m Text
forall (m :: * -> *). (Monad m, TokenParsing m) => m Text
identifier)
          m (Exp Delta -> (Text, Exp Delta))
-> m (Exp Delta) -> m (Text, Exp Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (String -> m String
forall (m :: * -> *). TokenParsing m => String -> m String
Trifecta.symbol String
"=" m String -> m (Exp Delta) -> m (Exp Delta)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
term)

extends' :: Parser m => m (Exp Delta)
extends' :: forall (m :: * -> *). Parser m => m (Exp Delta)
extends' = String -> m (Exp Delta) -> m (Exp Delta)
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block String
"extends" (m (Exp Delta) -> m (Exp Delta)) -> m (Exp Delta) -> m (Exp Delta)
forall a b. (a -> b) -> a -> b
$ do
  Delta
d <- m Delta
forall (m :: * -> *). DeltaParsing m => m Delta
Trifecta.position
  Text
k <- m Text
forall (m :: * -> *) s. (TokenParsing m, IsString s) => m s
Trifecta.stringLiteral
  (HashMap Text (NonEmpty Delta)
 -> Identity (HashMap Text (NonEmpty Delta)))
-> Env -> Identity Env
Lens' Env (HashMap Text (NonEmpty Delta))
extends ((HashMap Text (NonEmpty Delta)
  -> Identity (HashMap Text (NonEmpty Delta)))
 -> Env -> Identity Env)
-> (HashMap Text (NonEmpty Delta) -> HashMap Text (NonEmpty Delta))
-> m ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (NonEmpty Delta -> NonEmpty Delta -> NonEmpty Delta)
-> Text
-> NonEmpty Delta
-> HashMap Text (NonEmpty Delta)
-> HashMap Text (NonEmpty Delta)
forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
HashMap.insertWith NonEmpty Delta -> NonEmpty Delta -> NonEmpty Delta
forall a. Semigroup a => a -> a -> a
(<>) Text
k (Delta
d Delta -> [Delta] -> NonEmpty Delta
forall a. a -> [a] -> NonEmpty a
:| [])
  Exp Delta -> m (Exp Delta)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Delta
d Delta -> ExpF (Exp Delta) -> Exp Delta
forall (f :: * -> *) a. a -> f (Cofree f a) -> Cofree f a
:< Text -> ExpF (Exp Delta)
forall a. Text -> ExpF a
EExt Text
k)

binding :: Parser m => m (Exp Delta)
binding :: forall (m :: * -> *). Parser m => m (Exp Delta)
binding =
  Maybe (Text, Exp Delta) -> Exp Delta -> Exp Delta
forall a. Maybe (Text, Exp a) -> Exp a -> Exp a
elet (Maybe (Text, Exp Delta) -> Exp Delta -> Exp Delta)
-> ((Text, Exp Delta) -> Maybe (Text, Exp Delta))
-> (Text, Exp Delta)
-> Exp Delta
-> Exp Delta
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text, Exp Delta) -> Maybe (Text, Exp Delta)
forall a. a -> Maybe a
Just
    ((Text, Exp Delta) -> Exp Delta -> Exp Delta)
-> m (Text, Exp Delta) -> m (Exp Delta -> Exp Delta)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Text, Exp Delta) -> m (Text, Exp Delta)
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block
      String
"let"
      ( (,) (Text -> Exp Delta -> (Text, Exp Delta))
-> m Text -> m (Exp Delta -> (Text, Exp Delta))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Text
forall (m :: * -> *). (Monad m, TokenParsing m) => m Text
identifier
          m (Exp Delta -> (Text, Exp Delta))
-> m (Exp Delta) -> m (Text, Exp Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (String -> m String
forall (m :: * -> *). TokenParsing m => String -> m String
Trifecta.symbol String
"=" m String -> m (Exp Delta) -> m (Exp Delta)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
term)
      )
    m (Exp Delta -> Exp Delta) -> m (Exp Delta) -> m (Exp Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
document
    m (Exp Delta) -> m () -> m (Exp Delta)
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
exit String
"endlet"

set :: Parser m => m (Exp Delta)
set :: forall (m :: * -> *). Parser m => m (Exp Delta)
set =
  Text -> Exp Delta -> Exp Delta -> Exp Delta
forall a. Text -> Exp a -> Exp a -> Exp a
eset
  (Text -> Exp Delta -> Exp Delta -> Exp Delta)
-> m Text -> m (Exp Delta -> Exp Delta -> Exp Delta)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m Text -> m Text
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block String
"set" m Text
forall (m :: * -> *). (Monad m, TokenParsing m) => m Text
identifier
  m (Exp Delta -> Exp Delta -> Exp Delta)
-> m (Exp Delta) -> m (Exp Delta -> Exp Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
document
  m (Exp Delta -> Exp Delta) -> m () -> m (Exp Delta -> Exp Delta)
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
exit String
"endset"
  m (Exp Delta -> Exp Delta) -> m (Exp Delta) -> m (Exp Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
document

block' :: Parser m => m (Exp Delta)
block' :: forall (m :: * -> *). Parser m => m (Exp Delta)
block' = do
  Text
k <- String -> m Text -> m Text
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block String
"block" m Text
forall (m :: * -> *). (Monad m, TokenParsing m) => m Text
identifier
  Exp Delta
e <- m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
document
  ()
_ <- String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
exit String
"endblock"
  (HashMap Text (Exp Delta) -> Identity (HashMap Text (Exp Delta)))
-> Env -> Identity Env
Lens' Env (HashMap Text (Exp Delta))
blocks ((HashMap Text (Exp Delta) -> Identity (HashMap Text (Exp Delta)))
 -> Env -> Identity Env)
-> (HashMap Text (Exp Delta) -> HashMap Text (Exp Delta)) -> m ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Text
-> Exp Delta
-> HashMap Text (Exp Delta)
-> HashMap Text (Exp Delta)
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HashMap.insert Text
k Exp Delta
e
  Exp Delta -> m (Exp Delta)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Exp Delta -> Exp Delta
forall a. Text -> Exp a -> Exp a
eblock Text
k Exp Delta
e)

raw :: Parser m => m (Exp Delta)
raw :: forall (m :: * -> *). Parser m => m (Exp Delta)
raw = m (ExpF (Fix ExpF)) -> m (Exp Delta)
forall (m :: * -> *) (f :: * -> *).
(DeltaParsing m, Functor f) =>
m (f (Fix f)) -> m (Cofree f Delta)
ann (Value -> ExpF (Fix ExpF)
forall a. Value -> ExpF a
ELit (Value -> ExpF (Fix ExpF)) -> m Value -> m (ExpF (Fix ExpF))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Value
body)
  where
    body :: m Value
body = m ()
start m () -> m Value -> m Value
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m String -> m Value
forall (f :: * -> *). Functor f => f String -> f Value
pack (m Char -> m () -> m String
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
Trifecta.manyTill m Char
forall (m :: * -> *). CharParsing m => m Char
Trifecta.anyChar (m () -> m ()
forall a. m a -> m a
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead m ()
end)) m Value -> m () -> m Value
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m ()
end
    start :: m ()
start = String -> m () -> m ()
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block String
"raw" (() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
    end :: m ()
end = String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
exit String
"endraw"

-- FIXME: this is due to the whitespace sensitive nature of the parser making
-- it difficult to do what most applicative parsers do by skipping comments
-- as part of the whitespace.
comment :: Parser m => m (Exp Delta)
comment :: forall (m :: * -> *). Parser m => m (Exp Delta)
comment = m (ExpF (Fix ExpF)) -> m (Exp Delta)
forall (m :: * -> *) (f :: * -> *).
(DeltaParsing m, Functor f) =>
m (f (Fix f)) -> m (Cofree f Delta)
ann (Value -> ExpF (Fix ExpF)
forall a. Value -> ExpF a
ELit (Value -> ExpF (Fix ExpF)) -> m Value -> m (ExpF (Fix ExpF))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> m Value
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Value
String Text
forall a. Monoid a => a
mempty) m (ExpF (Fix ExpF)) -> m () -> m (ExpF (Fix ExpF))
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (m () -> m ()
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
Trifecta.try (m () -> m ()
forall (m :: * -> *) a. Parser m => m a -> m a
triml (m () -> m ()
forall (m :: * -> *) a. Parser m => m a -> m a
trimr m ()
go)) m () -> m () -> m ()
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m ()
go))
  where
    go :: m ()
go =
      (String -> String -> CommentStyle
commentStyle (String -> String -> CommentStyle)
-> m String -> m (String -> CommentStyle)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m String
forall (m :: * -> *). MonadState Env m => m String
commentl m (String -> CommentStyle) -> m String -> m CommentStyle
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m String
forall (m :: * -> *). MonadState Env m => m String
commentr)
        m CommentStyle -> (CommentStyle -> m ()) -> m ()
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= m () -> CommentStyle -> m ()
forall (m :: * -> *). CharParsing m => m () -> CommentStyle -> m ()
buildSomeSpaceParser (String -> m ()
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"whitespace significant")

else' :: Parser m => m (Maybe (Exp Delta))
else' :: forall (m :: * -> *). Parser m => m (Maybe (Exp Delta))
else' = m (Exp Delta) -> m (Maybe (Exp Delta))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
Trifecta.optional (String -> m () -> m ()
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block String
"else" (() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) m () -> m (Exp Delta) -> m (Exp Delta)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
document)

exit :: Parser m => String -> m ()
exit :: forall (m :: * -> *). Parser m => String -> m ()
exit String
k = String -> m () -> m ()
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block String
k (() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())

pattern :: Parser m => m Pat
pattern :: forall (m :: * -> *). Parser m => m Pat
pattern =
  Pat
PWild Pat -> m Char -> m Pat
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
Trifecta.char Char
'_'
    m Pat -> m Pat -> m Pat
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Var -> Pat
PVar (Var -> Pat) -> m Var -> m Pat
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Var
forall (m :: * -> *). (Monad m, TokenParsing m) => m Var
variable
    m Pat -> m Pat -> m Pat
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Value -> Pat
PLit (Value -> Pat) -> m Value -> m Pat
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Value
forall (m :: * -> *). Parser m => m Value
literal

term :: Parser m => m (Exp Delta)
term :: forall (m :: * -> *). Parser m => m (Exp Delta)
term =
  m (Exp Delta)
-> m (Text, [Exp Delta])
-> m (Exp Delta -> (Text, [Exp Delta]) -> Exp Delta)
-> m (Exp Delta)
forall (m :: * -> *) a b.
Alternative m =>
m a -> m b -> m (a -> b -> a) -> m a
chainl1' m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
term0 (m (Text, [Exp Delta]) -> m (Text, [Exp Delta])
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
Trifecta.try m (Text, [Exp Delta])
forall (m :: * -> *). Parser m => m (Text, [Exp Delta])
filter') (String -> m String
forall (m :: * -> *). TokenParsing m => String -> m String
Trifecta.symbol String
"|" m String
-> m (Exp Delta -> (Text, [Exp Delta]) -> Exp Delta)
-> m (Exp Delta -> (Text, [Exp Delta]) -> Exp Delta)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Exp Delta -> (Text, [Exp Delta]) -> Exp Delta)
-> m (Exp Delta -> (Text, [Exp Delta]) -> Exp Delta)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Exp Delta -> (Text, [Exp Delta]) -> Exp Delta
forall a. Exp a -> (Text, [Exp a]) -> Exp a
efilter)
    m (Exp Delta) -> m (Exp Delta) -> m (Exp Delta)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
term0

term0 :: Parser m => m (Exp Delta)
term0 :: forall (m :: * -> *). Parser m => m (Exp Delta)
term0 = OperatorTable m (Exp Delta) -> m (Exp Delta) -> m (Exp Delta)
forall (m :: * -> *) a.
(Parsing m, Applicative m) =>
OperatorTable m a -> m a -> m a
Expression.buildExpressionParser OperatorTable m (Exp Delta)
table m (Exp Delta)
expr
  where
    table :: OperatorTable m (Exp Delta)
table =
      [ [Text -> Operator m (Exp Delta)
forall {m :: * -> *} {a}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp a)
prefix Text
"!"],
        [Text -> Operator m (Exp Delta)
forall {m :: * -> *}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp Delta)
infix' Text
"*", Text -> Operator m (Exp Delta)
forall {m :: * -> *}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp Delta)
infix' Text
"/"],
        [Text -> Operator m (Exp Delta)
forall {m :: * -> *}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp Delta)
infix' Text
"-", Text -> Operator m (Exp Delta)
forall {m :: * -> *}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp Delta)
infix' Text
"+"],
        [Text -> Operator m (Exp Delta)
forall {m :: * -> *}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp Delta)
infix' Text
"==", Text -> Operator m (Exp Delta)
forall {m :: * -> *}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp Delta)
infix' Text
"!=", Text -> Operator m (Exp Delta)
forall {m :: * -> *}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp Delta)
infix' Text
">", Text -> Operator m (Exp Delta)
forall {m :: * -> *}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp Delta)
infix' Text
">=", Text -> Operator m (Exp Delta)
forall {m :: * -> *}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp Delta)
infix' Text
"<", Text -> Operator m (Exp Delta)
forall {m :: * -> *}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp Delta)
infix' Text
"<="],
        [Text -> Operator m (Exp Delta)
forall {m :: * -> *}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp Delta)
infix' Text
"&&"],
        [Text -> Operator m (Exp Delta)
forall {m :: * -> *}.
(MonadFail m, MonadState Env m, DeltaParsing m, LookAheadParsing m,
 Errable m) =>
Text -> Operator m (Exp Delta)
infix' Text
"||"]
      ]

    prefix :: Text -> Operator m (Exp a)
prefix Text
n = m (Exp a -> Exp a) -> Operator m (Exp a)
forall (m :: * -> *) a. m (a -> a) -> Operator m a
Expression.Prefix (Text -> Exp a -> Exp a
forall a. Text -> Exp a -> Exp a
efun (Text -> Exp a -> Exp a) -> m Delta -> m (Text -> Exp a -> Exp a)
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> m Delta
forall (m :: * -> *). Parser m => Text -> m Delta
operator Text
n m (Text -> Exp a -> Exp a) -> m Text -> m (Exp a -> Exp a)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> m Text
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
n)

    infix' :: Text -> Operator m (Exp Delta)
infix' Text
n =
      m (Exp Delta -> Exp Delta -> Exp Delta)
-> Assoc -> Operator m (Exp Delta)
forall (m :: * -> *) a. m (a -> a -> a) -> Assoc -> Operator m a
Expression.Infix
        ( do
            Delta
d <- Text -> m Delta
forall (m :: * -> *). Parser m => Text -> m Delta
operator Text
n
            (Exp Delta -> Exp Delta -> Exp Delta)
-> m (Exp Delta -> Exp Delta -> Exp Delta)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((Exp Delta -> Exp Delta -> Exp Delta)
 -> m (Exp Delta -> Exp Delta -> Exp Delta))
-> (Exp Delta -> Exp Delta -> Exp Delta)
-> m (Exp Delta -> Exp Delta -> Exp Delta)
forall a b. (a -> b) -> a -> b
$ \Exp Delta
l Exp Delta
r ->
              Delta
d Delta -> ExpF (Exp Delta) -> Exp Delta
forall (f :: * -> *) a. a -> f (Cofree f a) -> Cofree f a
:< Exp Delta -> Exp Delta -> ExpF (Exp Delta)
forall a. a -> a -> ExpF a
EApp (Text -> Exp Delta -> Exp Delta
forall a. Text -> Exp a -> Exp a
efun Text
n Exp Delta
l) Exp Delta
r
        )
        Assoc
Expression.AssocLeft

    expr :: m (Exp Delta)
expr =
      m (Exp Delta) -> m (Exp Delta)
forall (m :: * -> *) a. TokenParsing m => m a -> m a
Trifecta.parens m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
term
        m (Exp Delta) -> m (Exp Delta) -> m (Exp Delta)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (ExpF (Fix ExpF)) -> m (Exp Delta)
forall (m :: * -> *) (f :: * -> *).
(DeltaParsing m, Functor f) =>
m (f (Fix f)) -> m (Cofree f Delta)
ann (Var -> ExpF (Fix ExpF)
forall a. Var -> ExpF a
EVar (Var -> ExpF (Fix ExpF)) -> m Var -> m (ExpF (Fix ExpF))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Var
forall (m :: * -> *). (Monad m, TokenParsing m) => m Var
variable)
        m (Exp Delta) -> m (Exp Delta) -> m (Exp Delta)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (ExpF (Fix ExpF)) -> m (Exp Delta)
forall (m :: * -> *) (f :: * -> *).
(DeltaParsing m, Functor f) =>
m (f (Fix f)) -> m (Cofree f Delta)
ann (Value -> ExpF (Fix ExpF)
forall a. Value -> ExpF a
ELit (Value -> ExpF (Fix ExpF)) -> m Value -> m (ExpF (Fix ExpF))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Value
forall (m :: * -> *). Parser m => m Value
literal)

filter' :: Parser m => m (Id, [Exp Delta])
filter' :: forall (m :: * -> *). Parser m => m (Text, [Exp Delta])
filter' =
  (,)
    (Text -> [Exp Delta] -> (Text, [Exp Delta]))
-> m Text -> m ([Exp Delta] -> (Text, [Exp Delta]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Text
forall (m :: * -> *). (Monad m, TokenParsing m) => m Text
identifier
    m ([Exp Delta] -> (Text, [Exp Delta]))
-> m [Exp Delta] -> m (Text, [Exp Delta])
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (m [Exp Delta] -> m [Exp Delta]
forall (m :: * -> *) a. TokenParsing m => m a -> m a
Trifecta.parens (m (Exp Delta) -> m [Exp Delta]
forall (m :: * -> *) a. TokenParsing m => m a -> m [a]
Trifecta.commaSep1 m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
term) m [Exp Delta] -> m [Exp Delta] -> m [Exp Delta]
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Exp Delta] -> m [Exp Delta]
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [])

collection :: Parser m => m (Exp Delta)
collection :: forall (m :: * -> *). Parser m => m (Exp Delta)
collection = m (ExpF (Fix ExpF)) -> m (Exp Delta)
forall (m :: * -> *) (f :: * -> *).
(DeltaParsing m, Functor f) =>
m (f (Fix f)) -> m (Cofree f Delta)
ann (Var -> ExpF (Fix ExpF)
forall a. Var -> ExpF a
EVar (Var -> ExpF (Fix ExpF)) -> m Var -> m (ExpF (Fix ExpF))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Var
forall (m :: * -> *). (Monad m, TokenParsing m) => m Var
variable m (ExpF (Fix ExpF)) -> m (ExpF (Fix ExpF)) -> m (ExpF (Fix ExpF))
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Value -> ExpF (Fix ExpF)
forall a. Value -> ExpF a
ELit (Value -> ExpF (Fix ExpF)) -> m Value -> m (ExpF (Fix ExpF))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Value
col)
  where
    col :: m Value
col =
      (Object -> Value
Object (Object -> Value)
-> (HashMap Text Value -> Object) -> HashMap Text Value -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap Text Value -> Object
forall v. HashMap Text v -> KeyMap v
fromHashMapText) (HashMap Text Value -> Value) -> m (HashMap Text Value) -> m Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (HashMap Text Value)
forall (m :: * -> *). Parser m => m (HashMap Text Value)
object
        m Value -> m Value -> m Value
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Array -> Value
Array (Array -> Value) -> m Array -> m Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Array
forall (m :: * -> *). Parser m => m Array
array
        m Value -> m Value -> m Value
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Value
String (Text -> Value) -> m Text -> m Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Text
forall (m :: * -> *) s. (TokenParsing m, IsString s) => m s
Trifecta.stringLiteral

literal :: Parser m => m Value
literal :: forall (m :: * -> *). Parser m => m Value
literal =
  Bool -> Value
Bool (Bool -> Value) -> m Bool -> m Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Bool
forall (m :: * -> *). Parser m => m Bool
bool
    m Value -> m Value -> m Value
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Scientific -> Value
Number (Scientific -> Value) -> m Scientific -> m Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Scientific
forall (m :: * -> *). Parser m => m Scientific
number
    m Value -> m Value -> m Value
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Value
String (Text -> Value) -> m Text -> m Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Text
forall (m :: * -> *) s. (TokenParsing m, IsString s) => m s
Trifecta.stringLiteral
    m Value -> m Value -> m Value
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Object -> Value
Object (Object -> Value)
-> (HashMap Text Value -> Object) -> HashMap Text Value -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap Text Value -> Object
forall v. HashMap Text v -> KeyMap v
fromHashMapText) (HashMap Text Value -> Value) -> m (HashMap Text Value) -> m Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (HashMap Text Value)
forall (m :: * -> *). Parser m => m (HashMap Text Value)
object
    m Value -> m Value -> m Value
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Array -> Value
Array (Array -> Value) -> m Array -> m Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Array
forall (m :: * -> *). Parser m => m Array
array

number :: Parser m => m Scientific
number :: forall (m :: * -> *). Parser m => m Scientific
number =
  (Integer -> Scientific)
-> (Double -> Scientific) -> Either Integer Double -> Scientific
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Integer -> Scientific
forall a b. (Integral a, Num b) => a -> b
fromIntegral Double -> Scientific
forall a. RealFloat a => a -> Scientific
Scientific.fromFloatDigits
    (Either Integer Double -> Scientific)
-> m (Either Integer Double) -> m Scientific
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Either Integer Double)
forall (m :: * -> *). TokenParsing m => m (Either Integer Double)
Trifecta.integerOrDouble

bool :: Parser m => m Bool
bool :: forall (m :: * -> *). Parser m => m Bool
bool =
  String -> m String
forall (m :: * -> *). TokenParsing m => String -> m String
Trifecta.symbol String
"true" m String -> m Bool -> m Bool
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m Bool
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
    m Bool -> m Bool -> m Bool
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> m String
forall (m :: * -> *). TokenParsing m => String -> m String
Trifecta.symbol String
"false" m String -> m Bool -> m Bool
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m Bool
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False

object :: Parser m => m (HashMap Text Value)
object :: forall (m :: * -> *). Parser m => m (HashMap Text Value)
object = [(Text, Value)] -> HashMap Text Value
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(Text, Value)] -> HashMap Text Value)
-> m [(Text, Value)] -> m (HashMap Text Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m [(Text, Value)] -> m [(Text, Value)]
forall (m :: * -> *) a. TokenParsing m => m a -> m a
Trifecta.braces (m (Text, Value) -> m [(Text, Value)]
forall (m :: * -> *) a. TokenParsing m => m a -> m [a]
Trifecta.commaSep m (Text, Value)
pair)
  where
    pair :: m (Text, Value)
pair =
      (,)
        (Text -> Value -> (Text, Value))
-> m Text -> m (Value -> (Text, Value))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (m Text
forall (m :: * -> *) s. (TokenParsing m, IsString s) => m s
Trifecta.stringLiteral m Text -> m () -> m Text
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m ()
forall (m :: * -> *). CharParsing m => m ()
Trifecta.spaces)
        m (Value -> (Text, Value)) -> m Value -> m (Text, Value)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
Trifecta.char Char
':' m Char -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m ()
forall (m :: * -> *). CharParsing m => m ()
Trifecta.spaces m () -> m Value -> m Value
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m Value
forall (m :: * -> *). Parser m => m Value
literal)

array :: Parser m => m (Vector Value)
array :: forall (m :: * -> *). Parser m => m Array
array = [Value] -> Array
forall a. [a] -> Vector a
Vector.fromList ([Value] -> Array) -> m [Value] -> m Array
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m [Value] -> m [Value]
forall (m :: * -> *) a. TokenParsing m => m a -> m a
Trifecta.brackets (m Value -> m [Value]
forall (m :: * -> *) a. TokenParsing m => m a -> m [a]
Trifecta.commaSep m Value
forall (m :: * -> *). Parser m => m Value
literal)

operator :: Parser m => Text -> m Delta
operator :: forall (m :: * -> *). Parser m => Text -> m Delta
operator Text
n = m Delta
forall (m :: * -> *). DeltaParsing m => m Delta
Trifecta.position m Delta -> m () -> m Delta
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* IdentifierStyle m -> Text -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> Text -> m ()
Trifecta.reserveText IdentifierStyle m
forall (m :: * -> *). TokenParsing m => IdentifierStyle m
operatorStyle Text
n

keyword :: Parser m => String -> m Delta
keyword :: forall (m :: * -> *). Parser m => String -> m Delta
keyword String
k = m Delta
forall (m :: * -> *). DeltaParsing m => m Delta
Trifecta.position m Delta -> m () -> m Delta
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m () -> m ()
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
Trifecta.try (IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
Trifecta.reserve IdentifierStyle m
forall (m :: * -> *). TokenParsing m => IdentifierStyle m
keywordStyle String
k)

variable :: (Monad m, TokenParsing m) => m Var
variable :: forall (m :: * -> *). (Monad m, TokenParsing m) => m Var
variable =
  NonEmpty Text -> Var
Var (NonEmpty Text -> Var) -> m (NonEmpty Text) -> m Var
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Text] -> NonEmpty Text
forall a. HasCallStack => [a] -> NonEmpty a
NonEmpty.fromList ([Text] -> NonEmpty Text) -> m [Text] -> m (NonEmpty Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Text -> m Char -> m [Text]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
Trifecta.sepBy1 m Text
forall (m :: * -> *). (Monad m, TokenParsing m) => m Text
identifier (Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
Trifecta.char Char
'.'))

identifier :: (Monad m, TokenParsing m) => m Id
identifier :: forall (m :: * -> *). (Monad m, TokenParsing m) => m Text
identifier = IdentifierStyle m -> m Text
forall (m :: * -> *) s.
(TokenParsing m, Monad m, IsString s) =>
IdentifierStyle m -> m s
Trifecta.ident IdentifierStyle m
forall (m :: * -> *). TokenParsing m => IdentifierStyle m
variableStyle

spaces :: (Monad m, TokenParsing m) => m ()
spaces :: forall (m :: * -> *). (Monad m, TokenParsing m) => m ()
spaces = m Char -> m ()
forall a. m a -> m ()
forall (m :: * -> *) a. Parsing m => m a -> m ()
Trifecta.skipMany (String -> m Char
forall (m :: * -> *). CharParsing m => String -> m Char
Trifecta.oneOf String
"\t ")

manyTill1 :: Alternative m => m a -> m b -> m [a]
manyTill1 :: forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
manyTill1 m a
p m b
end = (:) (a -> [a] -> [a]) -> m a -> m ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
p m ([a] -> [a]) -> m [a] -> m [a]
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m a -> m b -> m [a]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
Trifecta.manyTill m a
p m b
end

manyEndBy1 :: Alternative m => m a -> m a -> m [a]
manyEndBy1 :: forall (m :: * -> *) a. Alternative m => m a -> m a -> m [a]
manyEndBy1 m a
p m a
end = m [a]
go
  where
    go :: m [a]
go = (a -> [a] -> [a]
forall a. a -> [a] -> [a]
: []) (a -> [a]) -> m a -> m [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
end m [a] -> m [a] -> m [a]
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (:) (a -> [a] -> [a]) -> m a -> m ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
p m ([a] -> [a]) -> m [a] -> m [a]
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m [a]
go

chainl1' :: Alternative m => m a -> m b -> m (a -> b -> a) -> m a
chainl1' :: forall (m :: * -> *) a b.
Alternative m =>
m a -> m b -> m (a -> b -> a) -> m a
chainl1' m a
l m b
r m (a -> b -> a)
op = m a
scan
  where
    scan :: m a
scan = ((a -> a) -> a -> a) -> a -> (a -> a) -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> a) -> a -> a
forall a. a -> a
id (a -> (a -> a) -> a) -> m a -> m ((a -> a) -> a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
l m ((a -> a) -> a) -> m (a -> a) -> m a
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (a -> a)
rst
    rst :: m (a -> a)
rst = (\a -> b -> a
f b
y a -> a
g a
x -> a -> a
g (a -> b -> a
f a
x b
y)) ((a -> b -> a) -> b -> (a -> a) -> a -> a)
-> m (a -> b -> a) -> m (b -> (a -> a) -> a -> a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (a -> b -> a)
op m (b -> (a -> a) -> a -> a) -> m b -> m ((a -> a) -> a -> a)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m b
r m ((a -> a) -> a -> a) -> m (a -> a) -> m (a -> a)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (a -> a)
rst m (a -> a) -> m (a -> a) -> m (a -> a)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (a -> a) -> m (a -> a)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a -> a
forall a. a -> a
id

ann :: (DeltaParsing m, Functor f) => m (f (Fix f)) -> m (Cofree f Delta)
ann :: forall (m :: * -> *) (f :: * -> *).
(DeltaParsing m, Functor f) =>
m (f (Fix f)) -> m (Cofree f Delta)
ann m (f (Fix f))
p = Delta -> Fix f -> Cofree f Delta
forall (f :: * -> *) a. Functor f => a -> Fix f -> Cofree f a
cofreeFix (Delta -> Fix f -> Cofree f Delta)
-> m Delta -> m (Fix f -> Cofree f Delta)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Delta
forall (m :: * -> *). DeltaParsing m => m Delta
Trifecta.position m (Fix f -> Cofree f Delta) -> m (Fix f) -> m (Cofree f Delta)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (f (Fix f) -> Fix f
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (f (Fix f) -> Fix f) -> m (f (Fix f)) -> m (Fix f)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (f (Fix f))
p)

pack :: Functor f => f String -> f Value
pack :: forall (f :: * -> *). Functor f => f String -> f Value
pack = (String -> Value) -> f String -> f Value
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> Value
String (Text -> Value) -> (String -> Text) -> String -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Text.pack)

triml :: Parser m => m a -> m a
triml :: forall (m :: * -> *) a. Parser m => m a -> m a
triml m a
p = do
  Int64
c <- Delta -> Int64
forall t. HasDelta t => t -> Int64
Trifecta.Delta.column (Delta -> Int64) -> m Delta -> m Int64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Delta
forall (m :: * -> *). DeltaParsing m => m Delta
Trifecta.position
  if Int64
c Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== Int64
0
    then m ()
forall (m :: * -> *). CharParsing m => m ()
Trifecta.spaces m () -> m a -> m a
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m a
p
    else String -> m a
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"left whitespace removal failed"

trimr :: Parser m => m a -> m a
trimr :: forall (m :: * -> *) a. Parser m => m a -> m a
trimr m a
p = m a
p m a -> m Char -> m a
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m Char
forall (m :: * -> *). CharParsing m => m Char
Trifecta.newline -- <* Trifecta.newline

pragmak :: Parser m => String -> m ()
pragmak :: forall (m :: * -> *). Parser m => String -> m ()
pragmak = IdentifierStyle m -> String -> m ()
forall (m :: * -> *).
(TokenParsing m, Monad m) =>
IdentifierStyle m -> String -> m ()
Trifecta.reserve IdentifierStyle m
forall (m :: * -> *). TokenParsing m => IdentifierStyle m
pragmaStyle

pragmal, pragmar :: Parser m => m String
pragmal :: forall (m :: * -> *). Parser m => m String
pragmal = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
left (Delim -> f Delim) -> Env -> f Env
forall c. HasSyntax c => Lens' c Delim
Lens' Env Delim
Getter Env Delim
delimPragma m String -> (String -> m String) -> m String
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> m String
forall (m :: * -> *). TokenParsing m => String -> m String
Trifecta.symbol
pragmar :: forall (m :: * -> *). Parser m => m String
pragmar = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
right (Delim -> f Delim) -> Env -> f Env
forall c. HasSyntax c => Lens' c Delim
Lens' Env Delim
Getter Env Delim
delimPragma m String -> (String -> m String) -> m String
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
Trifecta.string

commentl, commentr :: MonadState Env m => m String
commentl :: forall (m :: * -> *). MonadState Env m => m String
commentl = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
left (Delim -> f Delim) -> Env -> f Env
forall c. HasSyntax c => Lens' c Delim
Lens' Env Delim
Getter Env Delim
delimComment
commentr :: forall (m :: * -> *). MonadState Env m => m String
commentr = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
right (Delim -> f Delim) -> Env -> f Env
forall c. HasSyntax c => Lens' c Delim
Lens' Env Delim
Getter Env Delim
delimComment

inlinel, inliner :: Parser m => m String
inlinel :: forall (m :: * -> *). Parser m => m String
inlinel = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
left (Delim -> f Delim) -> Env -> f Env
forall c. HasSyntax c => Lens' c Delim
Lens' Env Delim
Getter Env Delim
delimInline m String -> (String -> m String) -> m String
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> m String
forall (m :: * -> *). TokenParsing m => String -> m String
Trifecta.symbol
inliner :: forall (m :: * -> *). Parser m => m String
inliner = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
right (Delim -> f Delim) -> Env -> f Env
forall c. HasSyntax c => Lens' c Delim
Lens' Env Delim
Getter Env Delim
delimInline m String -> (String -> m String) -> m String
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
Trifecta.string

blockl, blockr :: Parser m => m String
blockl :: forall (m :: * -> *). Parser m => m String
blockl = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
left (Delim -> f Delim) -> Env -> f Env
forall c. HasSyntax c => Lens' c Delim
Lens' Env Delim
Getter Env Delim
delimBlock m String -> (String -> m String) -> m String
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> m String
forall (m :: * -> *). TokenParsing m => String -> m String
Trifecta.symbol
blockr :: forall (m :: * -> *). Parser m => m String
blockr = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
right (Delim -> f Delim) -> Env -> f Env
forall c. HasSyntax c => Lens' c Delim
Lens' Env Delim
Getter Env Delim
delimBlock m String -> (String -> m String) -> m String
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
Trifecta.string

left, right :: MonadState s m => Lens.Getter s Delim -> m String
left :: forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
left Getter s Delim
d = (s -> String) -> m String
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
State.gets (Delim -> String
forall a b. (a, b) -> a
fst (Delim -> String) -> (s -> Delim) -> s -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting Delim s Delim -> s -> Delim
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
Lens.view Getting Delim s Delim
Getter s Delim
d)
right :: forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
right Getter s Delim
d = (s -> String) -> m String
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
State.gets (Delim -> String
forall a b. (a, b) -> b
snd (Delim -> String) -> (s -> Delim) -> s -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting Delim s Delim -> s -> Delim
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
Lens.view Getting Delim s Delim
Getter s Delim
d)