{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

-- | Parsers for PLC terms in DefaultUni.

module PlutusCore.Parser
    ( module Export
    , program
    , parseProgram
    , parseTerm
    , parseType
    , SourcePos
    , ParserError(..)
    ) where

import PlutusCore.Annotation
import PlutusCore.Core (Program (..), Term (..), Type)
import PlutusCore.Default
import PlutusCore.Error (AsParserErrorBundle, ParserError (..))
import PlutusCore.MkPlc (mkIterApp, mkIterInst)
import PlutusCore.Name.Unique (Name, TyName)
import PlutusCore.Parser.Builtin as Export
import PlutusCore.Parser.ParserCommon as Export
import PlutusCore.Parser.Type as Export
import PlutusCore.Quote (MonadQuote)

import Control.Monad.Except (MonadError)
import Data.Text (Text)
import PlutusCore.Version
import Text.Megaparsec (MonadParsec (notFollowedBy), anySingle, choice, many, some, try)
import Text.Megaparsec.Char.Lexer qualified as Lex

-- | A parsable PLC term.
type PTerm = Term TyName Name DefaultUni DefaultFun SrcSpan

varTerm :: Parser PTerm
varTerm :: Parser PTerm
varTerm = (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan -> Parser PTerm) -> Parser PTerm)
-> (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp ->
    SrcSpan -> Name -> PTerm
forall tyname name (uni :: * -> *) fun ann.
ann -> name -> Term tyname name uni fun ann
Var SrcSpan
sp (Name -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     Name
-> Parser PTerm
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  Name
name

tyAbsTerm :: Parser PTerm
tyAbsTerm :: Parser PTerm
tyAbsTerm = (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan -> Parser PTerm) -> Parser PTerm)
-> (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp ->
    Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
inParens (Parser PTerm -> Parser PTerm) -> Parser PTerm -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ SrcSpan -> TyName -> Kind SrcSpan -> PTerm -> PTerm
forall tyname name (uni :: * -> *) fun ann.
ann
-> tyname
-> Kind ann
-> Term tyname name uni fun ann
-> Term tyname name uni fun ann
TyAbs SrcSpan
sp (TyName -> Kind SrcSpan -> PTerm -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     TyName
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Kind SrcSpan -> PTerm -> PTerm)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Parser Text
symbol Text
"abs" Parser Text
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     TyName
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     TyName
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  TyName
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     TyName
forall a. Parser a -> Parser a
trailingWhitespace ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  TyName
tyName)  ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Kind SrcSpan -> PTerm -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Kind SrcSpan)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (PTerm -> PTerm)
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (a -> b)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Kind SrcSpan)
kind ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (PTerm -> PTerm)
-> Parser PTerm -> Parser PTerm
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (a -> b)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PTerm
term

lamTerm :: Parser PTerm
lamTerm :: Parser PTerm
lamTerm = (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan -> Parser PTerm) -> Parser PTerm)
-> (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp ->
    Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
inParens (Parser PTerm -> Parser PTerm) -> Parser PTerm -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Name -> Type TyName DefaultUni SrcSpan -> PTerm -> PTerm
forall tyname name (uni :: * -> *) fun ann.
ann
-> name
-> Type tyname uni ann
-> Term tyname name uni fun ann
-> Term tyname name uni fun ann
LamAbs SrcSpan
sp (Name -> Type TyName DefaultUni SrcSpan -> PTerm -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     Name
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan -> PTerm -> PTerm)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Parser Text
symbol Text
"lam" Parser Text
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     Name
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     Name
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  Name
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     Name
forall a. Parser a -> Parser a
trailingWhitespace ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  Name
name) ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Type TyName DefaultUni SrcSpan -> PTerm -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (PTerm -> PTerm)
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (a -> b)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Type TyName DefaultUni SrcSpan)
pType ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (PTerm -> PTerm)
-> Parser PTerm -> Parser PTerm
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (a -> b)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PTerm
term

appTerm :: Parser PTerm
appTerm :: Parser PTerm
appTerm = (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan -> Parser PTerm) -> Parser PTerm)
-> (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp ->
    -- TODO: should not use the same `sp` for all arguments.
    Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
inBrackets (Parser PTerm -> Parser PTerm) -> Parser PTerm -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ PTerm -> [(SrcSpan, PTerm)] -> PTerm
forall (term :: * -> *) tyname name (uni :: * -> *) fun ann.
TermLike term tyname name uni fun =>
term ann -> [(ann, term ann)] -> term ann
mkIterApp (PTerm -> [(SrcSpan, PTerm)] -> PTerm)
-> Parser PTerm
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     ([(SrcSpan, PTerm)] -> PTerm)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser PTerm
term ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  ([(SrcSpan, PTerm)] -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     [(SrcSpan, PTerm)]
-> Parser PTerm
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (a -> b)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((PTerm -> (SrcSpan, PTerm)) -> [PTerm] -> [(SrcSpan, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SrcSpan
sp,) ([PTerm] -> [(SrcSpan, PTerm)])
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     [PTerm]
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     [(SrcSpan, PTerm)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser PTerm
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     [PTerm]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
some Parser PTerm
term)

conTerm :: Parser PTerm
conTerm :: Parser PTerm
conTerm = (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan -> Parser PTerm) -> Parser PTerm)
-> (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp ->
    Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
inParens (Parser PTerm -> Parser PTerm) -> Parser PTerm -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Some (ValueOf DefaultUni) -> PTerm
forall tyname name (uni :: * -> *) fun ann.
ann -> Some (ValueOf uni) -> Term tyname name uni fun ann
Constant SrcSpan
sp (Some (ValueOf DefaultUni) -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Some (ValueOf DefaultUni))
-> Parser PTerm
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Parser Text
symbol Text
"con" Parser Text
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Some (ValueOf DefaultUni))
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Some (ValueOf DefaultUni))
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Some (ValueOf DefaultUni))
constant)

builtinTerm :: Parser PTerm
builtinTerm :: Parser PTerm
builtinTerm = (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan -> Parser PTerm) -> Parser PTerm)
-> (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp ->
    Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
inParens (Parser PTerm -> Parser PTerm) -> Parser PTerm -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ SrcSpan -> DefaultFun -> PTerm
forall tyname name (uni :: * -> *) fun ann.
ann -> fun -> Term tyname name uni fun ann
Builtin SrcSpan
sp (DefaultFun -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     DefaultFun
-> Parser PTerm
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Parser Text
symbol Text
"builtin" Parser Text
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     DefaultFun
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     DefaultFun
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  DefaultFun
builtinFunction)

tyInstTerm :: Parser PTerm
tyInstTerm :: Parser PTerm
tyInstTerm = (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan -> Parser PTerm) -> Parser PTerm)
-> (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp ->
    -- TODO: should not use the same `sp` for all arguments.
    Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
inBraces (Parser PTerm -> Parser PTerm) -> Parser PTerm -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ PTerm -> [(SrcSpan, Type TyName DefaultUni SrcSpan)] -> PTerm
forall (term :: * -> *) tyname name (uni :: * -> *) fun ann.
TermLike term tyname name uni fun =>
term ann -> [(ann, Type tyname uni ann)] -> term ann
mkIterInst (PTerm -> [(SrcSpan, Type TyName DefaultUni SrcSpan)] -> PTerm)
-> Parser PTerm
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     ([(SrcSpan, Type TyName DefaultUni SrcSpan)] -> PTerm)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser PTerm
term ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  ([(SrcSpan, Type TyName DefaultUni SrcSpan)] -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     [(SrcSpan, Type TyName DefaultUni SrcSpan)]
-> Parser PTerm
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (a -> b)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Type TyName DefaultUni SrcSpan
 -> (SrcSpan, Type TyName DefaultUni SrcSpan))
-> [Type TyName DefaultUni SrcSpan]
-> [(SrcSpan, Type TyName DefaultUni SrcSpan)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SrcSpan
sp,) ([Type TyName DefaultUni SrcSpan]
 -> [(SrcSpan, Type TyName DefaultUni SrcSpan)])
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     [Type TyName DefaultUni SrcSpan]
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     [(SrcSpan, Type TyName DefaultUni SrcSpan)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Type TyName DefaultUni SrcSpan)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     [Type TyName DefaultUni SrcSpan]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Type TyName DefaultUni SrcSpan)
pType)

unwrapTerm :: Parser PTerm
unwrapTerm :: Parser PTerm
unwrapTerm = (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan -> Parser PTerm) -> Parser PTerm)
-> (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp ->
    Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
inParens (Parser PTerm -> Parser PTerm) -> Parser PTerm -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ SrcSpan -> PTerm -> PTerm
forall tyname name (uni :: * -> *) fun ann.
ann -> Term tyname name uni fun ann -> Term tyname name uni fun ann
Unwrap SrcSpan
sp (PTerm -> PTerm) -> Parser PTerm -> Parser PTerm
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Parser Text
symbol Text
"unwrap" Parser Text -> Parser PTerm -> Parser PTerm
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser PTerm
term)

iwrapTerm :: Parser PTerm
iwrapTerm :: Parser PTerm
iwrapTerm = (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan -> Parser PTerm) -> Parser PTerm)
-> (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp ->
    Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
inParens (Parser PTerm -> Parser PTerm) -> Parser PTerm -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> Type TyName DefaultUni SrcSpan
-> Type TyName DefaultUni SrcSpan
-> PTerm
-> PTerm
forall tyname name (uni :: * -> *) fun ann.
ann
-> Type tyname uni ann
-> Type tyname uni ann
-> Term tyname name uni fun ann
-> Term tyname name uni fun ann
IWrap SrcSpan
sp (Type TyName DefaultUni SrcSpan
 -> Type TyName DefaultUni SrcSpan -> PTerm -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan -> PTerm -> PTerm)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Parser Text
symbol Text
"iwrap" Parser Text
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Type TyName DefaultUni SrcSpan)
pType) ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Type TyName DefaultUni SrcSpan -> PTerm -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (PTerm -> PTerm)
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (a -> b)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Type TyName DefaultUni SrcSpan)
pType ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (PTerm -> PTerm)
-> Parser PTerm -> Parser PTerm
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (a -> b)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PTerm
term

errorTerm :: Parser PTerm
errorTerm :: Parser PTerm
errorTerm = (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan -> Parser PTerm) -> Parser PTerm)
-> (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp ->
    Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
inParens (Parser PTerm -> Parser PTerm) -> Parser PTerm -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Type TyName DefaultUni SrcSpan -> PTerm
forall tyname name (uni :: * -> *) fun ann.
ann -> Type tyname uni ann -> Term tyname name uni fun ann
Error SrcSpan
sp (Type TyName DefaultUni SrcSpan -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
-> Parser PTerm
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Parser Text
symbol Text
"error" Parser Text
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Type TyName DefaultUni SrcSpan)
pType)

constrTerm :: Parser PTerm
constrTerm :: Parser PTerm
constrTerm = (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan -> Parser PTerm) -> Parser PTerm)
-> (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp ->
    Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
inParens (Parser PTerm -> Parser PTerm) -> Parser PTerm -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ do
      PTerm
res <- SrcSpan
-> Type TyName DefaultUni SrcSpan -> Word64 -> [PTerm] -> PTerm
forall tyname name (uni :: * -> *) fun ann.
ann
-> Type tyname uni ann
-> Word64
-> [Term tyname name uni fun ann]
-> Term tyname name uni fun ann
Constr SrcSpan
sp (Type TyName DefaultUni SrcSpan -> Word64 -> [PTerm] -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Word64 -> [PTerm] -> PTerm)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Parser Text
symbol Text
"constr" Parser Text
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Type TyName DefaultUni SrcSpan)
pType) ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Word64 -> [PTerm] -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     Word64
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     ([PTerm] -> PTerm)
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (a -> b)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  Word64
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     Word64
forall a. Parser a -> Parser a
lexeme ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  Word64
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
Lex.decimal ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  ([PTerm] -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     [PTerm]
-> Parser PTerm
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (a -> b)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PTerm
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     [PTerm]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many Parser PTerm
term
      (Version -> Bool) -> Parser () -> Parser ()
whenVersion (\Version
v -> Version
v Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
< Version
plcVersion110) (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
forall a.
String
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"'constr' is not allowed before version 1.1.0"
      PTerm -> Parser PTerm
forall a.
a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PTerm
res

caseTerm :: Parser PTerm
caseTerm :: Parser PTerm
caseTerm = (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan -> Parser PTerm) -> Parser PTerm)
-> (SrcSpan -> Parser PTerm) -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp ->
    Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
inParens (Parser PTerm -> Parser PTerm) -> Parser PTerm -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ do
      PTerm
res <- SrcSpan
-> Type TyName DefaultUni SrcSpan -> PTerm -> [PTerm] -> PTerm
forall tyname name (uni :: * -> *) fun ann.
ann
-> Type tyname uni ann
-> Term tyname name uni fun ann
-> [Term tyname name uni fun ann]
-> Term tyname name uni fun ann
Case SrcSpan
sp (Type TyName DefaultUni SrcSpan -> PTerm -> [PTerm] -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (PTerm -> [PTerm] -> PTerm)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> Parser Text
symbol Text
"case" Parser Text
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     (Type TyName DefaultUni SrcSpan)
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Type TyName DefaultUni SrcSpan)
pType) ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (PTerm -> [PTerm] -> PTerm)
-> Parser PTerm
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     ([PTerm] -> PTerm)
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (a -> b)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PTerm
term ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  ([PTerm] -> PTerm)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     [PTerm]
-> Parser PTerm
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (a -> b)
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PTerm
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     [PTerm]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many Parser PTerm
term
      (Version -> Bool) -> Parser () -> Parser ()
whenVersion (\Version
v -> Version
v Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
< Version
plcVersion110) (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
forall a.
String
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"'case' is not allowed before version 1.1.0"
      PTerm -> Parser PTerm
forall a.
a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PTerm
res

-- | Parser for all PLC terms.
term :: Parser PTerm
term :: Parser PTerm
term = Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
leadingWhitespace Parser PTerm
go
  where
    go :: Parser PTerm
go =
        [Parser PTerm] -> Parser PTerm
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice ([Parser PTerm] -> Parser PTerm) -> [Parser PTerm] -> Parser PTerm
forall a b. (a -> b) -> a -> b
$ (Parser PTerm -> Parser PTerm) -> [Parser PTerm] -> [Parser PTerm]
forall a b. (a -> b) -> [a] -> [b]
map Parser PTerm -> Parser PTerm
forall a. Parser a -> Parser a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try
            [ Parser PTerm
tyAbsTerm
            , Parser PTerm
lamTerm
            , Parser PTerm
appTerm
            , Parser PTerm
conTerm
            , Parser PTerm
builtinTerm
            , Parser PTerm
tyInstTerm
            , Parser PTerm
unwrapTerm
            , Parser PTerm
iwrapTerm
            , Parser PTerm
errorTerm
            , Parser PTerm
varTerm
            , Parser PTerm
constrTerm
            , Parser PTerm
caseTerm
            ]

-- | Parse a PLC program. The resulting program will have fresh names. The
-- underlying monad must be capable of handling any parse errors.  This passes
-- "test" to the parser as the name of the input stream; to supply a name
-- explicity, use `parse program <name> <input>`.
parseProgram ::
    (AsParserErrorBundle e, MonadError e m, MonadQuote m)
    => Text
    -> m (Program TyName Name DefaultUni DefaultFun SrcSpan)
parseProgram :: forall e (m :: * -> *).
(AsParserErrorBundle e, MonadError e m, MonadQuote m) =>
Text -> m (Program TyName Name DefaultUni DefaultFun SrcSpan)
parseProgram = Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
-> Text -> m (Program TyName Name DefaultUni DefaultFun SrcSpan)
forall e (m :: * -> *) a.
(AsParserErrorBundle e, MonadError e m, MonadQuote m) =>
Parser a -> Text -> m a
parseGen Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
program

-- | Parser for PLC programs.
program :: Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
program :: Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
program = Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
-> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
forall a. Parser a -> Parser a
leadingWhitespace Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
go
  where
    go :: Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
go = do
        Program TyName Name DefaultUni DefaultFun SrcSpan
prog <- (SrcSpan
 -> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan))
-> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
forall a. (SrcSpan -> Parser a) -> Parser a
withSpan ((SrcSpan
  -> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan))
 -> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan))
-> (SrcSpan
    -> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan))
-> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
forall a b. (a -> b) -> a -> b
$ \SrcSpan
sp -> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
-> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
forall a. Parser a -> Parser a
inParens (Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
 -> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan))
-> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
-> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
forall a b. (a -> b) -> a -> b
$ do
            Version
v <- Text -> Parser Text
symbol Text
"program" Parser Text
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     Version
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     Version
forall a b.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  Version
version
            Version
-> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
-> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
forall a. Version -> Parser a -> Parser a
withVersion Version
v (Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
 -> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan))
-> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
-> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> Version
-> PTerm
-> Program TyName Name DefaultUni DefaultFun SrcSpan
forall tyname name (uni :: * -> *) fun ann.
ann
-> Version
-> Term tyname name uni fun ann
-> Program tyname name uni fun ann
Program SrcSpan
sp Version
v (PTerm -> Program TyName Name DefaultUni DefaultFun SrcSpan)
-> Parser PTerm
-> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser PTerm
term
        ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Token Text)
-> Parser ()
forall a.
ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  a
-> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Token Text)
forall e s (m :: * -> *). MonadParsec e s m => m (Token s)
anySingle
        Program TyName Name DefaultUni DefaultFun SrcSpan
-> Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
forall a.
a
-> ParsecT
     ParserError
     Text
     (StateT ParserState (ReaderT (Maybe Version) Quote))
     a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Program TyName Name DefaultUni DefaultFun SrcSpan
prog

-- | Parse a PLC term. The resulting program will have fresh names. The underlying monad
-- must be capable of handling any parse errors.
parseTerm :: (AsParserErrorBundle e, MonadError e m, MonadQuote m) =>
    Text -> m (Term TyName Name DefaultUni DefaultFun SrcSpan)
parseTerm :: forall e (m :: * -> *).
(AsParserErrorBundle e, MonadError e m, MonadQuote m) =>
Text -> m PTerm
parseTerm = Parser PTerm -> Text -> m PTerm
forall e (m :: * -> *) a.
(AsParserErrorBundle e, MonadError e m, MonadQuote m) =>
Parser a -> Text -> m a
parseGen Parser PTerm
term

-- | Parse a PLC type. The resulting program will have fresh names. The underlying monad
-- must be capable of handling any parse errors.
parseType :: (AsParserErrorBundle e, MonadError e m, MonadQuote m) =>
    Text -> m (Type TyName DefaultUni SrcSpan)
parseType :: forall e (m :: * -> *).
(AsParserErrorBundle e, MonadError e m, MonadQuote m) =>
Text -> m (Type TyName DefaultUni SrcSpan)
parseType = ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Type TyName DefaultUni SrcSpan)
-> Text -> m (Type TyName DefaultUni SrcSpan)
forall e (m :: * -> *) a.
(AsParserErrorBundle e, MonadError e m, MonadQuote m) =>
Parser a -> Text -> m a
parseGen ParsecT
  ParserError
  Text
  (StateT ParserState (ReaderT (Maybe Version) Quote))
  (Type TyName DefaultUni SrcSpan)
pType