aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Input.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/Input.hs')
-rw-r--r--compiler/src/Input.hs18
1 files changed, 14 insertions, 4 deletions
diff --git a/compiler/src/Input.hs b/compiler/src/Input.hs
index c90db5c..597394e 100644
--- a/compiler/src/Input.hs
+++ b/compiler/src/Input.hs
@@ -34,10 +34,12 @@ import Control.Exception (Exception, throwIO)
34import Control.Monad.IO.Class (MonadIO, liftIO) 34import Control.Monad.IO.Class (MonadIO, liftIO)
35import Data.Function ((&)) 35import Data.Function ((&))
36import Data.Maybe (mapMaybe, catMaybes) 36import Data.Maybe (mapMaybe, catMaybes)
37import Data.Bool (bool)
37import Data.List (find) 38import Data.List (find)
38import Data.Yaml (ParseException, decodeFileEither) 39import Data.Yaml (ParseException, decodeFileEither)
39import Data.Aeson (FromJSON) 40import Data.Aeson (FromJSON)
40import System.FilePath (isExtensionOf, dropExtension) 41import System.FilePath (isExtensionOf, dropExtension)
42import System.Directory (doesFileExist)
41 43
42import Files 44import Files
43 45
@@ -76,15 +78,23 @@ emptySidecar = Sidecar
76 , description = Nothing 78 , description = Nothing
77 , tags = Nothing } 79 , tags = Nothing }
78 80
81sidecarExt :: String
82sidecarExt = "yaml"
83
84readSidecarFile :: FilePath -> IO Sidecar
85readSidecarFile filepath =
86 doesFileExist filepath
87 >>= bool (return Nothing) (decodeYamlFile filepath)
88 >>= return . maybe emptySidecar id
89
79 90
80readInputTree :: AnchoredFSNode -> IO InputTree 91readInputTree :: AnchoredFSNode -> IO InputTree
81readInputTree (AnchoredFSNode anchor root@Dir{}) = mkDirNode root 92readInputTree (AnchoredFSNode anchor root@Dir{}) = mkDirNode root
82 where 93 where
83 mkInputNode :: FSNode -> IO (Maybe InputTree) 94 mkInputNode :: FSNode -> IO (Maybe InputTree)
84 mkInputNode (File path@(filename:pathto)) | ".yaml" `isExtensionOf` filename = 95 mkInputNode (File path@(filename:_)) | not (sidecarExt `isExtensionOf` filename) =
85 (decodeYamlFile (localPath $ anchor /> path) :: IO (Maybe Sidecar)) 96 readSidecarFile (localPath $ anchor /> path <.> sidecarExt)
86 >>= return . maybe emptySidecar id 97 >>= return . InputFile path
87 >>= return . InputFile ((dropExtension filename):pathto)
88 >>= return . Just 98 >>= return . Just
89 mkInputNode File{} = return Nothing 99 mkInputNode File{} = return Nothing
90 mkInputNode dir@Dir{} = mkDirNode dir >>= return . Just 100 mkInputNode dir@Dir{} = mkDirNode dir >>= return . Just