Add and use fromStringNoContext
This commit is contained in:
parent
ff1166aba6
commit
3beeaa6a79
|
@ -468,12 +468,9 @@ splitVersion s = case Text.uncons s of
|
|||
in thisComponent : splitVersion rest
|
||||
|
||||
splitVersion_ :: MonadNix e m => m (NValue m) -> m (NValue m)
|
||||
splitVersion_ = fromValue >=> \str ->
|
||||
case principledGetStringNoContext str of
|
||||
Just s -> return $ nvList $ flip map (splitVersion s) $ \c ->
|
||||
valueThunk $ nvStr $ principledMakeNixStringWithoutContext $ versionComponentToString c
|
||||
Nothing -> throwError $ ErrorCall $
|
||||
"builtins.splitVersion: string must not have context"
|
||||
splitVersion_ = fromStringNoContext >=> \s ->
|
||||
return $ nvList $ flip map (splitVersion s) $ \c ->
|
||||
valueThunk $ nvStr $ principledMakeNixStringWithoutContext $ versionComponentToString c
|
||||
|
||||
compareVersions :: Text -> Text -> Ordering
|
||||
compareVersions s1 s2 =
|
||||
|
@ -484,15 +481,12 @@ compareVersions s1 s2 =
|
|||
|
||||
compareVersions_ :: MonadNix e m => m (NValue m) -> m (NValue m) -> m (NValue m)
|
||||
compareVersions_ t1 t2 =
|
||||
fromValue t1 >>= \s1 ->
|
||||
fromValue t2 >>= \s2 ->
|
||||
case (principledGetStringNoContext s1, principledGetStringNoContext s2) of
|
||||
(Just str1, Just str2) -> return $ nvConstant $ NInt $
|
||||
case compareVersions str1 str2 of
|
||||
LT -> -1
|
||||
EQ -> 0
|
||||
GT -> 1
|
||||
_ -> throwError $ ErrorCall "builtins.compareVersions: expecting strings with no context"
|
||||
fromStringNoContext t1 >>= \s1 ->
|
||||
fromStringNoContext t2 >>= \s2 ->
|
||||
return $ nvConstant $ NInt $ case compareVersions s1 s2 of
|
||||
LT -> -1
|
||||
EQ -> 0
|
||||
GT -> 1
|
||||
|
||||
splitDrvName :: Text -> (Text, Text)
|
||||
splitDrvName s =
|
||||
|
|
|
@ -475,6 +475,13 @@ coerceToString copyToStore coerceMore = go
|
|||
where
|
||||
t = Text.pack $ unStorePath sp
|
||||
|
||||
fromStringNoContext :: MonadNix e m => m (NValue m) -> m Text
|
||||
fromStringNoContext =
|
||||
fromValue >=> \s -> case principledGetStringNoContext s of
|
||||
Just str -> return str
|
||||
Nothing -> throwError $ ErrorCall
|
||||
"expected string with no context"
|
||||
|
||||
newtype Lazy m a = Lazy
|
||||
{ runLazy :: ReaderT (Context (Lazy m) (NThunk (Lazy m)))
|
||||
(StateT (HashMap FilePath NExprLoc) m) a }
|
||||
|
|
Loading…
Reference in a new issue