Parser: support tilde in paths
This commit is contained in:
parent
86b09103d6
commit
bbb72654d7
|
@ -290,7 +290,8 @@ instance (MonadFix m, MonadCatch m, MonadThrow m, MonadIO m)
|
|||
_ -> throwError $ "addPath: failed: nix-store --add " ++ show path
|
||||
|
||||
makeAbsolutePath origPath = do
|
||||
absPath <- if isAbsolute origPath then pure origPath else do
|
||||
origPathExpanded <- liftIO $ expandHomePath origPath
|
||||
absPath <- if isAbsolute origPathExpanded then pure origPathExpanded else do
|
||||
cwd <- do
|
||||
mres <- lookupVar @_ @(NThunk (Lazy m)) "__cur_file"
|
||||
case mres of
|
||||
|
@ -301,7 +302,8 @@ instance (MonadFix m, MonadCatch m, MonadThrow m, MonadIO m)
|
|||
++ " __cur_file is in scope,"
|
||||
++ " but is not a path; it is: "
|
||||
++ show v
|
||||
pure $ cwd <///> origPath
|
||||
pure $ cwd <///> origPathExpanded
|
||||
_ <- liftIO $ putStrLn $ show absPath
|
||||
liftIO $ removeDotDotIndirections <$> canonicalizePath absPath
|
||||
|
||||
findEnvPath = findEnvPathM
|
||||
|
@ -418,6 +420,10 @@ removeDotDotIndirections = intercalate "/" . go [] . splitOn "/"
|
|||
go (_:s) ("..":rest) = go s rest
|
||||
go s (this:rest) = go (this:s) rest
|
||||
|
||||
expandHomePath :: FilePath -> IO FilePath
|
||||
expandHomePath ('~' : xs) = flip (++) xs <$> getHomeDirectory
|
||||
expandHomePath p = return p
|
||||
|
||||
-- Given a path, determine the nix file to load
|
||||
pathToDefaultNixFile :: FilePath -> IO FilePath
|
||||
pathToDefaultNixFile p = do
|
||||
|
|
|
@ -126,7 +126,7 @@ nixList :: Parser NExprLoc
|
|||
nixList = annotateLocation1 (brackets (NList <$> many nixTerm) <?> "list")
|
||||
|
||||
pathChar :: Char -> Bool
|
||||
pathChar x = isAlpha x || isDigit x || x == '.' || x == '_' || x == '-' || x == '+'
|
||||
pathChar x = isAlpha x || isDigit x || x == '.' || x == '_' || x == '-' || x == '+' || x == '~'
|
||||
|
||||
slash :: Parser Char
|
||||
slash = try (char '/' <* notFollowedBy (satisfy (\x -> x == '/' || x == '*' || isSpace x)))
|
||||
|
|
|
@ -53,6 +53,10 @@ case_constant_path = do
|
|||
assertParseFail "/"
|
||||
assertParseFail "a/"
|
||||
assertParseFail "a/def/"
|
||||
assertParseFail "~"
|
||||
assertParseFail "~/"
|
||||
assertParseText "~/a" $ mkPath False "~/a"
|
||||
assertParseText "~/a/b" $ mkPath False "~/a/b"
|
||||
|
||||
case_constant_uri = do
|
||||
assertParseText "a:a" $ mkUri "a:a"
|
||||
|
|
Loading…
Reference in a new issue