{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module Dhall.Core (
Const(..)
, Directory(..)
, File(..)
, FilePrefix(..)
, Import(..)
, ImportHashed(..)
, ImportMode(..)
, ImportType(..)
, URL(..)
, Scheme(..)
, DhallDouble(..)
, Var(..)
, Binding(..)
, makeBinding
, Chunks(..)
, Expr(..)
, alphaNormalize
, normalize
, normalizeWith
, normalizeWithM
, Normalizer
, NormalizerM
, ReifiedNormalizer (..)
, judgmentallyEqual
, subst
, shift
, isNormalized
, isNormalizedWith
, denote
, renote
, shallowDenote
, freeIn
, pretty
, subExpressions
, chunkExprs
, bindingExprs
, multiLet
, wrapInLets
, MultiLet(..)
, internalError
, reservedIdentifiers
, escapeText
, pathCharacter
, throws
, Eval.textShow
, censorExpression
, censorText
) where
import Control.Exception (Exception)
import Control.Monad.IO.Class (MonadIO(..))
import Data.Semigroup (Semigroup(..))
import Data.Text (Text)
import Data.Text.Prettyprint.Doc (Pretty)
import Dhall.Normalize
import Dhall.Src (Src(..))
import Dhall.Syntax
import Dhall.Pretty.Internal
import Instances.TH.Lift ()
import Lens.Family (over)
import Prelude hiding (succ)
import qualified Control.Exception
import qualified Dhall.Eval as Eval
import qualified Data.Text
pretty :: Pretty a => a -> Text
pretty = pretty_
{-# INLINE pretty #-}
_ERROR :: String
_ERROR = "\ESC[1;31mError\ESC[0m"
internalError :: Data.Text.Text -> forall b . b
internalError text = error (unlines
[ _ERROR <> ": Compiler bug "
, " "
, "Explanation: This error message means that there is a bug in the Dhall compiler."
, "You didn't do anything wrong, but if you would like to see this problem fixed "
, "then you should report the bug at: "
, " "
, "https://github.com/dhall-lang/dhall-haskell/issues "
, " "
, "Please include the following text in your bug report: "
, " "
, "``` "
, Data.Text.unpack text <> " "
, "``` "
] )
escapeText :: Text -> Text
escapeText = escapeText_
{-# INLINE escapeText #-}
censorExpression :: Expr Src a -> Expr Src a
censorExpression (TextLit chunks) = TextLit (censorChunks chunks)
censorExpression (Note src e) = Note (censorSrc src) (censorExpression e)
censorExpression e = over subExpressions censorExpression e
censorChunks :: Chunks Src a -> Chunks Src a
censorChunks (Chunks xys z) = Chunks xys' z'
where
z' = censorText z
xys' = [ (censorText x, censorExpression y) | (x, y) <- xys ]
censorText :: Text -> Text
censorText = Data.Text.map (\_ -> ' ')
censorSrc :: Src -> Src
censorSrc (Src { srcText = oldText, .. }) = Src { srcText = newText, .. }
where
newText = censorText oldText
throws :: (Exception e, MonadIO io) => Either e a -> io a
throws (Left e) = liftIO (Control.Exception.throwIO e)
throws (Right r) = return r