Move normalization code from Dhall.Core to a new module Dhall.Normalize (#1452)
Also try to decouple a few modules from Dhall.Core. Closes #1127.
This commit is contained in:
parent
6c2db48d42
commit
8f2c28a5dc
|
@ -484,41 +484,42 @@ Library
|
|||
TemplateHaskell
|
||||
|
||||
Exposed-Modules:
|
||||
Dhall,
|
||||
Dhall.Binary,
|
||||
Dhall.Context,
|
||||
Dhall.Core,
|
||||
Dhall.Crypto,
|
||||
Dhall.Diff,
|
||||
Dhall.Tags,
|
||||
Dhall.Format,
|
||||
Dhall.Freeze,
|
||||
Dhall.Import,
|
||||
Dhall.Lint,
|
||||
Dhall.Main,
|
||||
Dhall.Map,
|
||||
Dhall.Optics,
|
||||
Dhall.Set,
|
||||
Dhall.Src,
|
||||
Dhall.Parser,
|
||||
Dhall.Parser.Expression,
|
||||
Dhall.Parser.Token,
|
||||
Dhall.Pretty,
|
||||
Dhall.Repl,
|
||||
Dhall.Tutorial,
|
||||
Dhall.TypeCheck,
|
||||
Dhall
|
||||
Dhall.Binary
|
||||
Dhall.Context
|
||||
Dhall.Core
|
||||
Dhall.Crypto
|
||||
Dhall.Diff
|
||||
Dhall.Format
|
||||
Dhall.Freeze
|
||||
Dhall.Import
|
||||
Dhall.Lint
|
||||
Dhall.Main
|
||||
Dhall.Map
|
||||
Dhall.Optics
|
||||
Dhall.Parser
|
||||
Dhall.Parser.Expression
|
||||
Dhall.Parser.Token
|
||||
Dhall.Pretty
|
||||
Dhall.Repl
|
||||
Dhall.Set
|
||||
Dhall.Src
|
||||
Dhall.Tags
|
||||
Dhall.Tutorial
|
||||
Dhall.TypeCheck
|
||||
Dhall.Util
|
||||
Dhall.Version
|
||||
if !flag(cross)
|
||||
Exposed-Modules:
|
||||
Dhall.TH
|
||||
Other-Modules:
|
||||
Dhall.Pretty.Internal,
|
||||
Dhall.Parser.Combinators,
|
||||
Dhall.URL,
|
||||
Dhall.Import.Types,
|
||||
Dhall.Syntax,
|
||||
Dhall.Eval,
|
||||
Dhall.Eval
|
||||
Dhall.Import.Types
|
||||
Dhall.Normalize
|
||||
Dhall.Parser.Combinators
|
||||
Dhall.Pretty.Internal
|
||||
Dhall.Syntax
|
||||
Dhall.URL
|
||||
Paths_dhall
|
||||
Autogen-Modules:
|
||||
Paths_dhall
|
||||
|
|
|
@ -140,7 +140,7 @@ import Data.Typeable (Typeable)
|
|||
import Data.Vector (Vector)
|
||||
import Data.Void (Void)
|
||||
import Data.Word (Word8, Word16, Word32, Word64)
|
||||
import Dhall.Core (Expr(..), Chunks(..), DhallDouble(..))
|
||||
import Dhall.Syntax (Expr(..), Chunks(..), DhallDouble(..))
|
||||
import Dhall.Import (Imported(..))
|
||||
import Dhall.Parser (Src(..))
|
||||
import Dhall.TypeCheck (DetailedTypeError(..), TypeError)
|
||||
|
|
|
@ -26,7 +26,7 @@ module Dhall.Binary
|
|||
import Codec.CBOR.Term (Term(..))
|
||||
import Control.Applicative (empty, (<|>))
|
||||
import Control.Exception (Exception)
|
||||
import Dhall.Core
|
||||
import Dhall.Syntax
|
||||
( Binding(..)
|
||||
, Chunks(..)
|
||||
, Const(..)
|
||||
|
@ -55,7 +55,7 @@ import qualified Control.Monad as Monad
|
|||
import qualified Data.ByteArray
|
||||
import qualified Data.ByteString
|
||||
import qualified Data.Sequence
|
||||
import qualified Dhall.Core
|
||||
import qualified Dhall.Syntax
|
||||
import qualified Dhall.Crypto
|
||||
import qualified Dhall.Map
|
||||
import qualified Dhall.Set
|
||||
|
@ -375,7 +375,7 @@ instance ToTerm a => ToTerm (Expr Void a) where
|
|||
encode (Let a b) =
|
||||
TList ([ TInt 25 ] ++ as₁ ++ [ b₁ ])
|
||||
where
|
||||
MultiLet as₀ b₀ = Dhall.Core.multiLet a b
|
||||
MultiLet as₀ b₀ = Dhall.Syntax.multiLet a b
|
||||
|
||||
as₁ = do
|
||||
Binding _ x₀ _ mA₀ _ a₀ <- toList as₀
|
||||
|
@ -922,7 +922,7 @@ strip55799Tag term =
|
|||
-- This 'Dhall.Core.denote's the expression before encoding it. To encode an
|
||||
-- already denoted expression, it is more efficient to directly use 'encode'.
|
||||
encodeExpression :: Expr s Import -> Term
|
||||
encodeExpression e = encode (Dhall.Core.denote e :: Expr Void Import)
|
||||
encodeExpression e = encode (Dhall.Syntax.denote e :: Expr Void Import)
|
||||
|
||||
-- | Decode a Dhall expression from a CBOR `Term`
|
||||
decodeExpression :: FromTerm a => Term -> Either DecodingFailure (Expr s a)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,7 +25,7 @@ import Data.String (IsString(..))
|
|||
import Data.Text (Text)
|
||||
import Data.Text.Prettyprint.Doc (Doc, Pretty)
|
||||
import Data.Void (Void)
|
||||
import Dhall.Core (Binding(..), Chunks (..), Const(..), DhallDouble(..), Expr(..), Var(..))
|
||||
import Dhall.Syntax (Binding(..), Chunks (..), Const(..), DhallDouble(..), Expr(..), Var(..))
|
||||
import Dhall.Binary (ToTerm)
|
||||
import Dhall.Map (Map)
|
||||
import Dhall.Set (Set)
|
||||
|
@ -37,7 +37,7 @@ import qualified Data.List.NonEmpty
|
|||
import qualified Data.Set
|
||||
import qualified Data.Text
|
||||
import qualified Data.Text.Prettyprint.Doc as Pretty
|
||||
import qualified Dhall.Core
|
||||
import qualified Dhall.Normalize
|
||||
import qualified Dhall.Map
|
||||
import qualified Dhall.Set
|
||||
import qualified Dhall.Pretty.Internal as Internal
|
||||
|
@ -159,8 +159,8 @@ rparen = token Internal.rparen
|
|||
diffNormalized :: (Eq a, Pretty a, ToTerm a) => Expr s a -> Expr s a -> Diff
|
||||
diffNormalized l0 r0 = Dhall.Diff.diff l1 r1
|
||||
where
|
||||
l1 = Dhall.Core.alphaNormalize (Dhall.Core.normalize l0)
|
||||
r1 = Dhall.Core.alphaNormalize (Dhall.Core.normalize r0)
|
||||
l1 = Dhall.Normalize.alphaNormalize (Dhall.Normalize.normalize l0)
|
||||
r1 = Dhall.Normalize.alphaNormalize (Dhall.Normalize.normalize r0)
|
||||
|
||||
diffPrimitive :: Eq a => (a -> Diff) -> a -> a -> Diff
|
||||
diffPrimitive f l r
|
||||
|
|
|
@ -18,7 +18,7 @@ import Control.Exception (SomeException)
|
|||
import Data.Monoid ((<>))
|
||||
import Data.Text
|
||||
import Data.Void (Void)
|
||||
import Dhall.Core (Expr(..), Import(..), ImportHashed(..), ImportType(..))
|
||||
import Dhall.Syntax (Expr(..), Import(..), ImportHashed(..), ImportType(..))
|
||||
import Dhall.Parser (Src)
|
||||
import Dhall.Pretty (CharacterSet, annToAnsiStyle, layoutOpts, prettyCharacterSet)
|
||||
import Dhall.Util (Censor, Input(..))
|
||||
|
|
|
@ -158,7 +158,7 @@ import Data.Traversable (traverse)
|
|||
import Data.Typeable (Typeable)
|
||||
import System.FilePath ((</>))
|
||||
import Dhall.Binary (StandardVersion(..))
|
||||
import Dhall.Core
|
||||
import Dhall.Syntax
|
||||
( Expr(..)
|
||||
, Chunks(..)
|
||||
, Directory(..)
|
||||
|
|
|
@ -9,7 +9,7 @@ module Dhall.Lint
|
|||
) where
|
||||
|
||||
import Control.Applicative ((<|>))
|
||||
import Dhall.Core (Binding(..), Expr(..), Import, Var(..), subExpressions)
|
||||
import Dhall.Syntax (Binding(..), Expr(..), Import, Var(..), subExpressions)
|
||||
|
||||
import qualified Dhall.Core
|
||||
import qualified Dhall.Optics
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,7 +25,7 @@ import Control.Exception (Exception)
|
|||
import Data.Semigroup (Semigroup(..))
|
||||
import Data.Text (Text)
|
||||
import Data.Void (Void)
|
||||
import Dhall.Core
|
||||
import Dhall.Syntax
|
||||
import Dhall.Src (Src(..))
|
||||
import Prelude hiding (const, pi)
|
||||
import Text.Megaparsec (ParseErrorBundle(..), PosState(..))
|
||||
|
|
|
@ -14,7 +14,7 @@ import Data.Functor (void)
|
|||
import Data.List.NonEmpty (NonEmpty(..))
|
||||
import Data.Semigroup (Semigroup(..))
|
||||
import Data.Text (Text)
|
||||
import Dhall.Core
|
||||
import Dhall.Syntax
|
||||
import Dhall.Src (Src(..))
|
||||
import Prelude hiding (const, pi)
|
||||
import Text.Parser.Combinators (choice, try, (<?>))
|
||||
|
@ -214,7 +214,7 @@ parsers embedded = Parsers {..}
|
|||
-- (Let y …
|
||||
-- (Note …
|
||||
-- (Let z …
|
||||
return (Dhall.Core.wrapInLets as b)
|
||||
return (Dhall.Syntax.wrapInLets as b)
|
||||
|
||||
alternative3 = do
|
||||
_forall
|
||||
|
|
|
@ -112,7 +112,7 @@ import Control.Applicative (Alternative(..), optional)
|
|||
import Data.Functor (void)
|
||||
import Data.Semigroup (Semigroup(..))
|
||||
import Data.Text (Text)
|
||||
import Dhall.Core
|
||||
import Dhall.Syntax
|
||||
import Dhall.Set (Set)
|
||||
import Prelude hiding (const, pi)
|
||||
import Text.Parser.Combinators (choice, try, (<?>))
|
||||
|
@ -463,7 +463,7 @@ pathComponent componentType = do
|
|||
let pathData =
|
||||
case componentType of
|
||||
FileComponent -> do
|
||||
Text.Megaparsec.takeWhile1P Nothing Dhall.Core.pathCharacter
|
||||
Text.Megaparsec.takeWhile1P Nothing Dhall.Syntax.pathCharacter
|
||||
URLComponent -> do
|
||||
star pchar
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import Dhall.Map (foldMapWithKey)
|
|||
import Data.Text (Text)
|
||||
import Data.Text.Encoding (encodeUtf8)
|
||||
import Dhall.Util (Input(..))
|
||||
import Dhall.Core (Expr(..), Binding(..))
|
||||
import Dhall.Syntax (Expr(..), Binding(..))
|
||||
import Dhall.Src (Src(srcStart))
|
||||
import Dhall.Parser (exprFromText)
|
||||
import System.FilePath ((</>), takeFileName)
|
||||
|
|
|
@ -39,7 +39,7 @@ import Data.Typeable (Typeable)
|
|||
import Data.Void (Void, absurd)
|
||||
import Dhall.Binary (ToTerm(..))
|
||||
import Dhall.Context (Context)
|
||||
import Dhall.Core (Binding(..), Const(..), Chunks(..), Expr(..), Var(..))
|
||||
import Dhall.Syntax (Binding(..), Const(..), Chunks(..), Expr(..), Var(..))
|
||||
import Dhall.Eval
|
||||
(Environment(..), Names(..), Val(..), (~>))
|
||||
import Dhall.Pretty (Ann, layoutOpts)
|
||||
|
|
|
@ -6,7 +6,7 @@ module Dhall.URL where
|
|||
import Data.Monoid ((<>))
|
||||
import Data.Text (Text)
|
||||
|
||||
import Dhall.Core
|
||||
import Dhall.Syntax
|
||||
( Scheme(..)
|
||||
, URL(..)
|
||||
, File(..)
|
||||
|
|
|
@ -16,21 +16,23 @@ module Dhall.Util
|
|||
, Header(..)
|
||||
) where
|
||||
|
||||
import Control.Exception (Exception(..))
|
||||
import Control.Monad.IO.Class (MonadIO(..))
|
||||
import Data.Bifunctor (first)
|
||||
import Data.Monoid ((<>))
|
||||
import Data.String (IsString)
|
||||
import Data.Text (Text)
|
||||
import Data.Text.Prettyprint.Doc (Doc, Pretty)
|
||||
import Dhall.Core (Expr, Import)
|
||||
import Dhall.Parser (ParseError, Header(..))
|
||||
import Dhall.Pretty (Ann)
|
||||
import Dhall.Syntax (Expr, Import)
|
||||
import Dhall.Src (Src)
|
||||
|
||||
import qualified Control.Exception
|
||||
import qualified Data.Text
|
||||
import qualified Data.Text.IO
|
||||
import qualified Data.Text.Prettyprint.Doc as Pretty
|
||||
import qualified Data.Text.Prettyprint.Doc.Render.Text as Pretty
|
||||
import qualified Dhall.Core
|
||||
import qualified Dhall.Parser
|
||||
import qualified Dhall.Pretty
|
||||
|
||||
|
@ -117,7 +119,14 @@ get parser censor input = do
|
|||
NoCensor -> result
|
||||
Censor -> first Dhall.Parser.censor result
|
||||
|
||||
Dhall.Core.throws censoredResult
|
||||
throws censoredResult
|
||||
|
||||
{-| Convenience utility for converting `Either`-based exceptions to `IO`-based
|
||||
exceptions
|
||||
-}
|
||||
throws :: (Exception e, MonadIO io) => Either e a -> io a
|
||||
throws (Left e) = liftIO (Control.Exception.throwIO e)
|
||||
throws (Right r) = return r
|
||||
|
||||
-- | Set to `Censor` if you want to censor error text that might include secrets
|
||||
data Censor = NoCensor | Censor
|
||||
|
|
Loading…
Reference in New Issue