{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
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, void, unless)
import Control.Monad.State.Strict (MonadState, StateT)
import qualified Control.Monad.State.Strict as State
import Control.Monad.Trans (lift)
import Data.Aeson.Types (Array, Object, Value (..))
import qualified Data.Bifunctor as Bifunctor
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 qualified Data.Vector as Vector
import Text.EDE.Internal.AST
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)
}
$(Lens.makeLenses ''Env)
instance HasSyntax Env where
syntax :: (Syntax -> f Syntax) -> Env -> f Env
syntax = (Syntax -> f Syntax) -> Env -> f Env
Lens' Env Syntax
settings
type Parser m =
( Monad m,
#if MIN_VERSION_base(4,13,0)
MonadFail m,
#endif
MonadState Env m,
Trifecta.TokenParsing m,
Trifecta.DeltaParsing m,
LookAhead.LookAheadParsing m,
Trifecta.Errable m
)
newtype EDE a = EDE {EDE a -> Parser a
runEDE :: Trifecta.Parser a}
deriving
( a -> EDE b -> EDE a
(a -> b) -> EDE a -> EDE b
(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
<$ :: a -> EDE b -> EDE a
$c<$ :: forall a b. a -> EDE b -> EDE a
fmap :: (a -> b) -> EDE a -> EDE b
$cfmap :: forall a b. (a -> b) -> EDE a -> EDE b
Functor,
Functor EDE
a -> EDE a
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
EDE a -> EDE b -> EDE b
EDE a -> EDE b -> EDE a
EDE (a -> b) -> EDE a -> EDE b
(a -> b -> c) -> EDE a -> EDE b -> EDE c
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
<* :: EDE a -> EDE b -> EDE a
$c<* :: forall a b. EDE a -> EDE b -> EDE a
*> :: EDE a -> EDE b -> EDE b
$c*> :: forall a b. EDE a -> EDE b -> EDE b
liftA2 :: (a -> b -> c) -> EDE a -> EDE b -> EDE c
$cliftA2 :: forall a b c. (a -> b -> c) -> EDE a -> EDE b -> EDE c
<*> :: EDE (a -> b) -> EDE a -> EDE b
$c<*> :: forall a b. EDE (a -> b) -> EDE a -> EDE b
pure :: a -> EDE a
$cpure :: forall a. a -> EDE a
$cp1Applicative :: Functor EDE
Applicative,
Applicative EDE
EDE a
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
EDE a -> EDE a -> EDE a
EDE a -> EDE [a]
EDE a -> EDE [a]
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
many :: EDE a -> EDE [a]
$cmany :: forall a. EDE a -> EDE [a]
some :: EDE a -> EDE [a]
$csome :: forall a. EDE a -> EDE [a]
<|> :: EDE a -> EDE a -> EDE a
$c<|> :: forall a. EDE a -> EDE a -> EDE a
empty :: EDE a
$cempty :: forall a. EDE a
$cp1Alternative :: Applicative EDE
Alternative,
Applicative EDE
a -> EDE a
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
EDE a -> (a -> EDE b) -> EDE b
EDE a -> EDE b -> EDE b
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
return :: a -> EDE a
$creturn :: forall a. a -> EDE a
>> :: EDE a -> EDE b -> EDE b
$c>> :: forall a b. EDE a -> EDE b -> EDE b
>>= :: EDE a -> (a -> EDE b) -> EDE b
$c>>= :: forall a b. EDE a -> (a -> EDE b) -> EDE b
$cp1Monad :: Applicative EDE
Monad,
#if MIN_VERSION_base(4,13,0)
Monad EDE
Monad EDE -> (forall a. String -> EDE a) -> MonadFail EDE
String -> EDE a
forall a. String -> EDE a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
fail :: String -> EDE a
$cfail :: forall a. String -> EDE a
$cp1MonadFail :: Monad EDE
MonadFail,
#endif
Monad EDE
Alternative EDE
EDE a
Alternative EDE
-> Monad EDE
-> (forall a. EDE a)
-> (forall a. EDE a -> EDE a -> EDE a)
-> MonadPlus EDE
EDE a -> EDE a -> EDE a
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
mplus :: EDE a -> EDE a -> EDE a
$cmplus :: forall a. EDE a -> EDE a -> EDE a
mzero :: EDE a
$cmzero :: forall a. EDE a
$cp2MonadPlus :: Monad EDE
$cp1MonadPlus :: Alternative EDE
MonadPlus,
Alternative EDE
EDE ()
String -> EDE a
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
EDE a -> EDE a
EDE a -> String -> EDE a
EDE a -> EDE ()
EDE a -> EDE ()
EDE a -> 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
notFollowedBy :: EDE a -> EDE ()
$cnotFollowedBy :: forall a. Show a => EDE a -> EDE ()
eof :: EDE ()
$ceof :: EDE ()
unexpected :: String -> EDE a
$cunexpected :: forall a. String -> EDE a
skipSome :: EDE a -> EDE ()
$cskipSome :: forall a. EDE a -> EDE ()
skipMany :: EDE a -> EDE ()
$cskipMany :: forall a. EDE a -> EDE ()
<?> :: EDE a -> String -> EDE a
$c<?> :: forall a. EDE a -> String -> EDE a
try :: EDE a -> EDE a
$ctry :: forall a. EDE a -> EDE a
$cp1Parsing :: Alternative 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
text :: Text -> EDE Text
$ctext :: Text -> EDE Text
string :: String -> EDE String
$cstring :: String -> EDE String
anyChar :: EDE Char
$canyChar :: EDE Char
notChar :: Char -> EDE Char
$cnotChar :: Char -> EDE Char
char :: Char -> EDE Char
$cchar :: Char -> EDE Char
satisfy :: (Char -> Bool) -> EDE Char
$csatisfy :: (Char -> Bool) -> EDE Char
$cp1CharParsing :: Parsing EDE
Trifecta.CharParsing,
MonadPlus EDE
TokenParsing EDE
EDE ByteString
EDE Rendering
EDE Delta
MonadPlus EDE
-> TokenParsing EDE
-> EDE ByteString
-> EDE Delta
-> (forall a r. (a -> ByteString -> r) -> EDE a -> EDE r)
-> EDE Rendering
-> EDE ByteString
-> DeltaParsing EDE
(a -> ByteString -> r) -> EDE a -> EDE r
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
restOfLine :: EDE ByteString
$crestOfLine :: EDE ByteString
rend :: EDE Rendering
$crend :: EDE Rendering
slicedWith :: (a -> ByteString -> r) -> EDE a -> EDE r
$cslicedWith :: forall a r. (a -> ByteString -> r) -> EDE a -> EDE r
position :: EDE Delta
$cposition :: EDE Delta
line :: EDE ByteString
$cline :: EDE ByteString
$cp2DeltaParsing :: TokenParsing EDE
$cp1DeltaParsing :: MonadPlus EDE
Trifecta.DeltaParsing,
Parsing EDE
Parsing EDE -> (forall a. EDE a -> EDE a) -> LookAheadParsing EDE
EDE a -> EDE a
forall a. EDE a -> EDE a
forall (m :: * -> *).
Parsing m -> (forall a. m a -> m a) -> LookAheadParsing m
lookAhead :: EDE a -> EDE a
$clookAhead :: forall a. EDE a -> EDE a
$cp1LookAheadParsing :: Parsing EDE
LookAhead.LookAheadParsing,
Err -> EDE a
(forall a. Err -> EDE a) -> Errable EDE
forall a. Err -> EDE a
forall (m :: * -> *). (forall a. Err -> m a) -> Errable m
raiseErr :: Err -> EDE a
$craiseErr :: forall a. Err -> EDE a
Trifecta.Errable
)
instance TokenParsing EDE where
nesting :: 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 (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 (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 :: 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 (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 :: Err -> StateT Env EDE a
raiseErr = EDE a -> StateT Env EDE 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 (m :: * -> *) a. Errable m => Err -> m a
Trifecta.raiseErr
runParser ::
Syntax ->
Text ->
ByteString ->
Result (Exp Delta, HashMap Text (NonEmpty Delta))
runParser :: Syntax
-> Text
-> ByteString
-> Result (Exp Delta, HashMap Text (NonEmpty Delta))
runParser Syntax
o Text
n = Result (Exp Delta, Env)
-> Result (Exp Delta, HashMap Text (NonEmpty Delta))
forall a.
Result (a, Env) -> Result (a, HashMap Text (NonEmpty Delta))
res (Result (Exp Delta, Env)
-> Result (Exp Delta, HashMap Text (NonEmpty Delta)))
-> (ByteString -> Result (Exp Delta, Env))
-> ByteString
-> Result (Exp Delta, HashMap Text (NonEmpty 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 (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 (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) -> Env
Env Syntax
o HashMap Text (NonEmpty 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 (a, Env) -> Result (a, HashMap Text (NonEmpty Delta))
res = \case
Trifecta.Success (a, Env)
x -> (a, HashMap Text (NonEmpty Delta))
-> Result (a, HashMap Text (NonEmpty Delta))
forall a. a -> Result a
Success ((Env -> HashMap Text (NonEmpty Delta))
-> (a, Env) -> (a, HashMap Text (NonEmpty Delta))
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
Bifunctor.second Env -> HashMap Text (NonEmpty Delta)
_includes (a, Env)
x)
Trifecta.Failure ErrInfo
e -> AnsiDoc -> Result (a, HashMap Text (NonEmpty Delta))
forall a. AnsiDoc -> Result a
Failure (ErrInfo -> AnsiDoc
Trifecta._errDoc ErrInfo
e)
pragma :: Parser m => m ()
pragma :: 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (f :: * -> *) a. Applicative f => a -> f a
pure (Delim -> Identity Delim) -> Env -> Identity Env
forall c. HasSyntax c => Lens' c Delim
delimPragma
m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
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 (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 (f :: * -> *) a. Applicative f => a -> f a
pure (Delim -> Identity Delim) -> Env -> Identity Env
forall c. HasSyntax c => Lens' c Delim
delimInline
m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
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 (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 (f :: * -> *) a. Applicative f => a -> f a
pure (Delim -> Identity Delim) -> Env -> Identity Env
forall c. HasSyntax c => Lens' c Delim
delimComment
m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
-> m ((Delim -> Identity Delim) -> Env -> Identity Env)
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 (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 (f :: * -> *) a. Applicative f => a -> f a
pure (Delim -> Identity Delim) -> Env -> Identity Env
forall c. HasSyntax c => Lens' c Delim
delimBlock
document :: Parser m => m (Exp Delta)
document :: 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Exp Delta) -> m [Exp Delta]
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 (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 (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 (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 :: 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 :: 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 (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
Trifecta.notFollowedBy m ()
end0 m () -> m String -> m String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> m String -> m String
forall (m :: * -> *) a. Parsing m => m a -> m a
Trifecta.try m String
line0 m String -> m String -> m String
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 (m :: * -> *) a. Parsing m => m a -> m a
Trifecta.try (m () -> m ()
forall (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead m ()
end0) m () -> m () -> m ()
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 (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 (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m String -> m String
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 (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 (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 :: 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)
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 :: String -> m a -> m a
block String
k m a
p =
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 (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 :: 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 (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 (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 :: 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 (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 (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 :: 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 (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 :: 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Exp Delta, Exp Delta) -> m [(Exp Delta, Exp Delta)]
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 (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 (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 (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 :: 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (Alt (Exp Delta)) -> m [Alt (Exp Delta)]
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 (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 (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 (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 :: 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 (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 (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 (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 (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 :: 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Exp Delta -> m (Exp Delta)
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 (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 (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 (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Exp Delta)
forall (m :: * -> *). Parser m => m (Exp Delta)
term)
binding :: Parser m => m (Exp Delta)
binding :: 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 (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 (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 (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 (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
exit String
"endlet"
raw :: Parser m => m (Exp Delta)
raw :: 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 (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 (m :: * -> *) a. LookAheadParsing m => m a -> m a
lookAhead m ()
end)) m Value -> m () -> m Value
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 (f :: * -> *) a. Applicative f => a -> f a
pure ())
end :: m ()
end = String -> m ()
forall (m :: * -> *). Parser m => String -> m ()
exit String
"endraw"
comment :: Parser m => m (Exp Delta)
= 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 (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 (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (m () -> m ()
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 (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 (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 (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 (m :: * -> *) a. MonadFail m => String -> m a
fail String
"whitespace significant")
else' :: Parser m => m (Maybe (Exp Delta))
else' :: 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 (f :: * -> *) a. Applicative f => a -> f a
pure ()) m () -> m (Exp Delta) -> m (Exp Delta)
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 :: String -> m ()
exit String
k = String -> m () -> m ()
forall (m :: * -> *) a. Parser m => String -> m a -> m a
block String
k (() -> m ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
pattern :: Parser m => m Pat
pattern :: m Pat
pattern =
Pat
PWild Pat -> m Char -> m Pat
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 (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 (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 :: 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 (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 (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 (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 (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 :: 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 (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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> m Text
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 (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 (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 (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' :: 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 (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 (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Exp Delta] -> m [Exp Delta]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [])
collection :: Parser m => m (Exp Delta)
collection :: 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 (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) -> m Object -> m Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Object
forall (m :: * -> *). Parser m => m Object
object
m Value -> m Value -> m Value
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 (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 :: 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 (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 (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 (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Object -> Value
Object (Object -> Value) -> m Object -> m Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Object
forall (m :: * -> *). Parser m => m Object
object
m Value -> m Value -> m Value
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 :: 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 :: m Bool
bool =
String -> m String
forall (m :: * -> *). TokenParsing m => String -> m String
Trifecta.symbol String
"true" m String -> m Bool -> m Bool
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
m Bool -> m Bool -> m Bool
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 (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False
object :: Parser m => m Object
object :: m Object
object = [(Text, Value)] -> Object
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(Text, Value)] -> Object) -> m [(Text, Value)] -> m Object
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 (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 (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 (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 (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m Value
forall (m :: * -> *). Parser m => m Value
literal)
array :: Parser m => m Array
array :: 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 :: Text -> m Delta
operator Text
n = m Delta
forall (m :: * -> *). DeltaParsing m => m Delta
Trifecta.position m Delta -> m () -> m Delta
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 :: String -> m Delta
keyword String
k = m Delta
forall (m :: * -> *). DeltaParsing m => m Delta
Trifecta.position m Delta -> m () -> m Delta
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m () -> m ()
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 :: 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. [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 :: 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 :: m ()
spaces = m Char -> 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 :: m a -> m b -> 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 (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 :: 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 (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 (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' :: 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 (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 (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 (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 (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (a -> a) -> m (a -> 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 :: 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 (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 :: f String -> f Value
pack = (String -> Value) -> f String -> f Value
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 :: 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 (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m a
p
else 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 :: m a -> m a
trimr m a
p = m a
p m a -> m Char -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m Char
forall (m :: * -> *). CharParsing m => m Char
Trifecta.newline
pragmak :: Parser m => String -> m ()
pragmak :: 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 :: m String
pragmal = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
left forall c. HasSyntax c => Lens' c Delim
Getter Env Delim
delimPragma m String -> (String -> m String) -> m String
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 :: m String
pragmar = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
right forall c. HasSyntax c => Lens' c Delim
Getter Env Delim
delimPragma m String -> (String -> m String) -> m String
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
= Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
left forall c. HasSyntax c => Lens' c Delim
Getter Env Delim
delimComment
= Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
right forall c. HasSyntax c => Lens' c Delim
Getter Env Delim
delimComment
inlinel, inliner :: Parser m => m String
inlinel :: m String
inlinel = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
left forall c. HasSyntax c => Lens' c Delim
Getter Env Delim
delimInline m String -> (String -> m String) -> m String
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 :: m String
inliner = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
right forall c. HasSyntax c => Lens' c Delim
Getter Env Delim
delimInline m String -> (String -> m String) -> m String
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 :: m String
blockl = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
left forall c. HasSyntax c => Lens' c Delim
Getter Env Delim
delimBlock m String -> (String -> m String) -> m String
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 :: m String
blockr = Getter Env Delim -> m String
forall s (m :: * -> *).
MonadState s m =>
Getter s Delim -> m String
right forall c. HasSyntax c => Lens' c Delim
Getter Env Delim
delimBlock m String -> (String -> m String) -> m String
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 :: 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 :: 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)