| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Posix filepaths |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --guardedness #-} |
| 8 |
|
| 9 |
module System.FilePath.Posix where |
| 10 |
|
| 11 |
open import Agda.Builtin.Bool using (Bool) |
| 12 |
open import Agda.Builtin.List using (List) |
| 13 |
open import Agda.Builtin.String using (String) |
| 14 |
open import IO.Base using (IO; lift) |
| 15 |
open import Data.Maybe.Base using (Maybe) |
| 16 |
open import Data.Product.Base using (_×_) |
| 17 |
open import Data.Sum.Base using (_⊎_) |
| 18 |
|
| 19 |
open import Foreign.Haskell.Coerce |
| 20 |
|
| 21 |
open import System.FilePath.Posix.Primitive as Prim |
| 22 |
public |
| 23 |
-- Some of these functions are not directly re-exported because their |
| 24 |
-- respective types mentions FFI-friendly versions of the stdlib's types |
| 25 |
-- e.g. `Pair` instead of `_×_`. |
| 26 |
-- A wrapper is systematically defined below using Foreign.Haskell.Coerce's |
| 27 |
-- zero-cost coercion to expose a more useful function to users. |
| 28 |
using ( module Nature |
| 29 |
; Nature |
| 30 |
; FilePath |
| 31 |
; mkFilePath |
| 32 |
; getFilePath |
| 33 |
; AbsolutePath |
| 34 |
; RelativePath |
| 35 |
; SomePath |
| 36 |
; Extension |
| 37 |
; mkExtension |
| 38 |
; getExtension |
| 39 |
-- Separator predicates |
| 40 |
; pathSeparator |
| 41 |
; pathSeparators |
| 42 |
; isPathSeparator |
| 43 |
; searchPathSeparator |
| 44 |
; isSearchPathSeparator |
| 45 |
; extSeparator |
| 46 |
; isExtSeparator |
| 47 |
-- $PATH methods |
| 48 |
; splitSearchPath |
| 49 |
-- ; getSearchPath see below: lift needed |
| 50 |
-- Extension functions |
| 51 |
-- ; splitExtension see below: coerce needed |
| 52 |
; takeExtension |
| 53 |
; replaceExtension |
| 54 |
; dropExtension |
| 55 |
; addExtension |
| 56 |
; hasExtension |
| 57 |
; takeExtensions |
| 58 |
; replaceExtensions |
| 59 |
; dropExtensions |
| 60 |
; isExtensionOf |
| 61 |
-- ; stripExtension see below: coerce needed |
| 62 |
-- Filename/directory functions |
| 63 |
-- ; splitFileName see below: coerce needed |
| 64 |
; takeFileName |
| 65 |
; replaceFileName |
| 66 |
; dropFileName |
| 67 |
; takeBaseName |
| 68 |
; replaceBaseName |
| 69 |
; takeDirectory |
| 70 |
; replaceDirectory |
| 71 |
; combine |
| 72 |
; splitPath |
| 73 |
; joinPath |
| 74 |
; splitDirectories |
| 75 |
-- Trailing slash functions |
| 76 |
; hasTrailingPathSeparator |
| 77 |
; addTrailingPathSeparator |
| 78 |
; dropTrailingPathSeparator |
| 79 |
-- File name manipulations |
| 80 |
; normalise |
| 81 |
; equalFilePath |
| 82 |
; makeRelative |
| 83 |
-- ; checkFilePath see below: coerce needed |
| 84 |
; isRelative |
| 85 |
; isAbsolute |
| 86 |
; isValid |
| 87 |
; makeValid |
| 88 |
) |
| 89 |
|
| 90 |
private |
| 91 |
variable |
| 92 |
m n : Nature |
| 93 |
|
| 94 |
-- singleton type for Nature |
| 95 |
data KnownNature : Nature → Set where |
| 96 |
instance |
| 97 |
absolute : KnownNature Nature.absolute |
| 98 |
relative : KnownNature Nature.relative |
| 99 |
|
| 100 |
currentDirectory : SomePath |
| 101 |
currentDirectory = mkFilePath "." |
| 102 |
|
| 103 |
splitExtension : FilePath n → FilePath n × Extension |
| 104 |
splitExtension = coerce Prim.splitExtension |
| 105 |
|
| 106 |
splitExtensions : FilePath n → FilePath n × Extension |
| 107 |
splitExtensions = coerce Prim.splitExtensions |
| 108 |
|
| 109 |
stripExtension : Extension → FilePath n → Maybe (FilePath n) |
| 110 |
stripExtension = coerce Prim.stripExtension |
| 111 |
|
| 112 |
getSearchPath : IO (List SomePath) |
| 113 |
getSearchPath = lift Prim.getSearchPath |
| 114 |
|
| 115 |
splitFileName : FilePath n → FilePath n × RelativePath |
| 116 |
splitFileName = coerce Prim.splitFileName |
| 117 |
|
| 118 |
checkFilePath : FilePath n → RelativePath ⊎ AbsolutePath |
| 119 |
checkFilePath = coerce Prim.checkFilePath |