replace *StringIgnoreContextMaybe with more accurate *GetStringNoContext
This commit is contained in:
parent
340e97e8d3
commit
ff1166aba6
|
@ -469,7 +469,7 @@ splitVersion s = case Text.uncons s of
|
|||
|
||||
splitVersion_ :: MonadNix e m => m (NValue m) -> m (NValue m)
|
||||
splitVersion_ = fromValue >=> \str ->
|
||||
case principledStringIgnoreContextMaybe str of
|
||||
case principledGetStringNoContext str of
|
||||
Just s -> return $ nvList $ flip map (splitVersion s) $ \c ->
|
||||
valueThunk $ nvStr $ principledMakeNixStringWithoutContext $ versionComponentToString c
|
||||
Nothing -> throwError $ ErrorCall $
|
||||
|
@ -486,7 +486,7 @@ compareVersions_ :: MonadNix e m => m (NValue m) -> m (NValue m) -> m (NValue m)
|
|||
compareVersions_ t1 t2 =
|
||||
fromValue t1 >>= \s1 ->
|
||||
fromValue t2 >>= \s2 ->
|
||||
case (principledStringIgnoreContextMaybe s1, principledStringIgnoreContextMaybe s2) of
|
||||
case (principledGetStringNoContext s1, principledGetStringNoContext s2) of
|
||||
(Just str1, Just str2) -> return $ nvConstant $ NInt $
|
||||
case compareVersions str1 str2 of
|
||||
LT -> -1
|
||||
|
|
|
@ -148,7 +148,7 @@ instance Convertible e m
|
|||
instance (Convertible e m, MonadEffects m)
|
||||
=> FromValue Text m (NValueNF m) where
|
||||
fromValueMay = \case
|
||||
Free (NVStrF ns) -> pure $ hackyStringIgnoreContextMaybe ns
|
||||
Free (NVStrF ns) -> pure $ hackyGetStringNoContext ns
|
||||
Free (NVPathF p) -> Just . Text.pack . unStorePath <$> addPath p
|
||||
Free (NVSetF s _) -> case M.lookup "outPath" s of
|
||||
Nothing -> pure Nothing
|
||||
|
@ -161,7 +161,7 @@ instance (Convertible e m, MonadEffects m)
|
|||
instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m, MonadEffects m)
|
||||
=> FromValue Text m (NValue m) where
|
||||
fromValueMay = \case
|
||||
NVStr ns -> pure $ hackyStringIgnoreContextMaybe ns
|
||||
NVStr ns -> pure $ hackyGetStringNoContext ns
|
||||
NVPath p -> Just . Text.pack . unStorePath <$> addPath p
|
||||
NVSet s _ -> case M.lookup "outPath" s of
|
||||
Nothing -> pure Nothing
|
||||
|
@ -200,7 +200,7 @@ instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m, MonadEffects m)
|
|||
instance Convertible e m
|
||||
=> FromValue ByteString m (NValueNF m) where
|
||||
fromValueMay = \case
|
||||
Free (NVStrF ns) -> pure $ encodeUtf8 <$> hackyStringIgnoreContextMaybe ns
|
||||
Free (NVStrF ns) -> pure $ encodeUtf8 <$> hackyGetStringNoContext ns
|
||||
_ -> pure Nothing
|
||||
fromValue v = fromValueMay v >>= \case
|
||||
Just b -> pure b
|
||||
|
@ -209,7 +209,7 @@ instance Convertible e m
|
|||
instance Convertible e m
|
||||
=> FromValue ByteString m (NValue m) where
|
||||
fromValueMay = \case
|
||||
NVStr ns -> pure $ encodeUtf8 <$> hackyStringIgnoreContextMaybe ns
|
||||
NVStr ns -> pure $ encodeUtf8 <$> hackyGetStringNoContext ns
|
||||
_ -> pure Nothing
|
||||
fromValue v = fromValueMay v >>= \case
|
||||
Just b -> pure b
|
||||
|
@ -221,7 +221,7 @@ newtype Path = Path { getPath :: FilePath }
|
|||
instance Convertible e m => FromValue Path m (NValueNF m) where
|
||||
fromValueMay = \case
|
||||
Free (NVPathF p) -> pure $ Just (Path p)
|
||||
Free (NVStrF ns) -> pure $ Path . Text.unpack <$> hackyStringIgnoreContextMaybe ns
|
||||
Free (NVStrF ns) -> pure $ Path . Text.unpack <$> hackyGetStringNoContext ns
|
||||
Free (NVSetF s _) -> case M.lookup "outPath" s of
|
||||
Nothing -> pure Nothing
|
||||
Just p -> fromValueMay @Path p
|
||||
|
@ -234,7 +234,7 @@ instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m)
|
|||
=> FromValue Path m (NValue m) where
|
||||
fromValueMay = \case
|
||||
NVPath p -> pure $ Just (Path p)
|
||||
NVStr ns -> pure $ Path . Text.unpack <$> hackyStringIgnoreContextMaybe ns
|
||||
NVStr ns -> pure $ Path . Text.unpack <$> hackyGetStringNoContext ns
|
||||
NVSet s _ -> case M.lookup "outPath" s of
|
||||
Nothing -> pure Nothing
|
||||
Just p -> fromValueMay @Path p
|
||||
|
@ -322,7 +322,7 @@ instance (Convertible e m, MonadEffects m)
|
|||
NFloat n -> toJSON n
|
||||
NBool b -> toJSON b
|
||||
NNull -> A.Null
|
||||
Free (NVStrF ns) -> pure $ toJSON <$> hackyStringIgnoreContextMaybe ns
|
||||
Free (NVStrF ns) -> pure $ toJSON <$> hackyGetStringNoContext ns
|
||||
Free (NVListF l) ->
|
||||
fmap (A.Array . V.fromList) . sequence
|
||||
<$> traverse fromValueMay l
|
||||
|
|
|
@ -406,8 +406,8 @@ execBinaryOp scope span op lval rarg = do
|
|||
_ -> nverr $ ErrorCall $ unsupportedTypes lval rval
|
||||
|
||||
(NVPath p, NVStr ns) -> case op of
|
||||
NEq -> toBool $ Just p == fmap Text.unpack (hackyStringIgnoreContextMaybe ns)
|
||||
NNEq -> toBool $ Just p /= fmap Text.unpack (hackyStringIgnoreContextMaybe ns)
|
||||
NEq -> toBool $ Just p == fmap Text.unpack (hackyGetStringNoContext ns)
|
||||
NNEq -> toBool $ Just p /= fmap Text.unpack (hackyGetStringNoContext ns)
|
||||
NPlus -> bin nvPathP <$> makeAbsolutePath (p `mappend` Text.unpack (hackyStringIgnoreContext ns))
|
||||
_ -> nverr $ ErrorCall $ unsupportedTypes lval rval
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ module Nix.String (
|
|||
, ContextFlavor(..)
|
||||
, stringHasContext
|
||||
, principledIntercalateNixString
|
||||
, hackyStringIgnoreContextMaybe
|
||||
, principledStringIgnoreContextMaybe
|
||||
, hackyGetStringNoContext
|
||||
, principledGetStringNoContext
|
||||
, principledStringIgnoreContext
|
||||
, hackyStringIgnoreContext
|
||||
, hackyMakeNixStringWithoutContext
|
||||
|
@ -28,7 +28,7 @@ import qualified Data.Text as Text
|
|||
import GHC.Generics
|
||||
import Data.Semigroup
|
||||
|
||||
-- {-# WARNING hackyStringIgnoreContextMaybe, hackyStringIgnoreContext, hackyMakeNixStringWithoutContext "This NixString function needs to be replaced" #-}
|
||||
-- {-# WARNING hackyGetStringNoContext, hackyStringIgnoreContext, hackyMakeNixStringWithoutContext "This NixString function needs to be replaced" #-}
|
||||
|
||||
-- | A 'ContextFlavor' describes the sum of possible derivations for string contexts
|
||||
data ContextFlavor =
|
||||
|
@ -94,13 +94,13 @@ principledStringMConcat = foldr principledStringMappend (NixString mempty mempty
|
|||
-- mappend = (<>)
|
||||
|
||||
-- | Extract the string contents from a NixString that has no context
|
||||
hackyStringIgnoreContextMaybe :: NixString -> Maybe Text
|
||||
hackyStringIgnoreContextMaybe (NixString s c) | null c = Just s
|
||||
hackyGetStringNoContext :: NixString -> Maybe Text
|
||||
hackyGetStringNoContext (NixString s c) | null c = Just s
|
||||
| otherwise = Nothing
|
||||
|
||||
-- | Extract the string contents from a NixString that has no context
|
||||
principledStringIgnoreContextMaybe :: NixString -> Maybe Text
|
||||
principledStringIgnoreContextMaybe (NixString s c) | null c = Just s
|
||||
principledGetStringNoContext :: NixString -> Maybe Text
|
||||
principledGetStringNoContext (NixString s c) | null c = Just s
|
||||
| otherwise = Nothing
|
||||
|
||||
-- | Extract the string contents from a NixString even if the NixString has an associated context
|
||||
|
|
|
@ -260,8 +260,8 @@ valueEq :: MonadThunk (NValue m) (NThunk m) m
|
|||
valueEq = curry $ \case
|
||||
(NVConstant lc, NVConstant rc) -> pure $ lc == rc
|
||||
(NVStr ls, NVStr rs) -> pure $ principledStringIgnoreContext ls == principledStringIgnoreContext rs
|
||||
(NVStr ns, NVConstant NNull) -> pure (hackyStringIgnoreContextMaybe ns == Just "")
|
||||
(NVConstant NNull, NVStr ns) -> pure (Just "" == hackyStringIgnoreContextMaybe ns)
|
||||
(NVStr ns, NVConstant NNull) -> pure (hackyGetStringNoContext ns == Just "")
|
||||
(NVConstant NNull, NVStr ns) -> pure (Just "" == hackyGetStringNoContext ns)
|
||||
(NVList ls, NVList rs) -> alignEqM thunkEq ls rs
|
||||
(NVSet lm _, NVSet rm _) -> do
|
||||
let compareAttrs = alignEqM thunkEq lm rm
|
||||
|
|
Loading…
Reference in a new issue