From f682907c97750338264d282a5a403a1cfc92fec8 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 16 May 2019 21:42:49 +0200 Subject: [PATCH] Make URI's be separate from strings --- src/Nix/Atoms.hs | 5 ++++- src/Nix/Builtins.hs | 1 + src/Nix/Lint.hs | 11 ++++++----- src/Nix/Type/Infer.hs | 1 + src/Nix/Value.hs | 1 + src/Nix/XML.hs | 1 + 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Nix/Atoms.hs b/src/Nix/Atoms.hs index c69c65b..c5d04a8 100644 --- a/src/Nix/Atoms.hs +++ b/src/Nix/Atoms.hs @@ -22,9 +22,11 @@ import GHC.Generics -- they appear in both the parsed AST (in the form of literals) and -- the evaluated form. data NAtom + -- | An URI like @https://example.com@. + = NURI Text -- | An integer. The c nix implementation currently only supports -- integers that fit in the range of 'Int64'. - = NInt Integer + | NInt Integer -- | A floating point number | NFloat Float -- | Booleans. @@ -40,6 +42,7 @@ instance Serialise NAtom -- | Translate an atom into its nix representation. atomText :: NAtom -> Text +atomText (NURI t) = t atomText (NInt i) = pack (show i) atomText (NFloat f) = pack (showNixFloat f) where diff --git a/src/Nix/Builtins.hs b/src/Nix/Builtins.hs index 68b1662..5c3c8c6 100644 --- a/src/Nix/Builtins.hs +++ b/src/Nix/Builtins.hs @@ -1347,6 +1347,7 @@ toXML_ v = demand v $ fmap (nvStr . toXML) . normalForm typeOf :: MonadNix e t f m => NValue t f m -> m (NValue t f m) typeOf v = demand v $ toValue . principledMakeNixStringWithoutContext . \case NVConstant a -> case a of + NURI _ -> "string" NInt _ -> "int" NFloat _ -> "float" NBool _ -> "bool" diff --git a/src/Nix/Lint.hs b/src/Nix/Lint.hs index 78910e0..fc972ce 100644 --- a/src/Nix/Lint.hs +++ b/src/Nix/Lint.hs @@ -300,13 +300,14 @@ instance MonadLint e m => MonadEval (Symbolic m) m where go f l c = [(Text.pack "file", f), (Text.pack "line", l), (Text.pack "col", c)] - evalConstant c = mkSymbolic [TConstant [go c]] + evalConstant c = mkSymbolic [go c] where go = \case - NInt _ -> TInt - NFloat _ -> TFloat - NBool _ -> TBool - NNull -> TNull + NURI _ -> TStr + NInt _ -> TConstant [TInt] + NFloat _ -> TConstant [TFloat] + NBool _ -> TConstant [TBool] + NNull -> TConstant [TNull] evalString = const $ mkSymbolic [TStr] evalLiteralPath = const $ mkSymbolic [TPath] diff --git a/src/Nix/Type/Infer.hs b/src/Nix/Type/Infer.hs index 6e0b407..87706fb 100644 --- a/src/Nix/Type/Infer.hs +++ b/src/Nix/Type/Infer.hs @@ -442,6 +442,7 @@ instance MonadInfer m => MonadEval (Judgment s) (InferT s m) where evalConstant c = return $ Judgment As.empty [] (go c) where go = \case + NURI _ -> typeString NInt _ -> typeInt NFloat _ -> typeFloat NBool _ -> typeBool diff --git a/src/Nix/Value.hs b/src/Nix/Value.hs index 258704d..2e1d6cd 100644 --- a/src/Nix/Value.hs +++ b/src/Nix/Value.hs @@ -413,6 +413,7 @@ data ValueType valueType :: NValueF a m r -> ValueType valueType = \case NVConstantF a -> case a of + NURI _ -> TString NoContext NInt _ -> TInt NFloat _ -> TFloat NBool _ -> TBool diff --git a/src/Nix/XML.hs b/src/Nix/XML.hs index 74f910f..e56acef 100644 --- a/src/Nix/XML.hs +++ b/src/Nix/XML.hs @@ -30,6 +30,7 @@ toXML = runWithStringContext . fmap pp . iterNValue (\_ _ -> cyc) phi phi :: NValue' t f m (WithStringContext Element) -> WithStringContext Element phi = \case NVConstant' a -> case a of + NURI t -> return $ mkElem "string" "value" (Text.unpack t) NInt n -> return $ mkElem "int" "value" (show n) NFloat f -> return $ mkElem "float" "value" (show f) NBool b -> return $ mkElem "bool" "value" (if b then "true" else "false")