-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigReader.hs
33 lines (25 loc) · 937 Bytes
/
ConfigReader.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE GADTs #-}
module GameEngine.ConfigReader where
import GameEngine.ConfigReader.ArgFmt
import GameEngine.ConfigReader.Config
import GameEngine.ConfigReader.ConfigFmt
import GameEngine.ConfigReader.Parser
import Prelude hiding (readFile)
import Control.Applicative
import System.Directory
import Text.Megaparsec
import Text.Megaparsec.Text
import Data.Text.IO (readFile)
parseConfigFile :: ConfigFmt -> FilePath -> IO (Either (ParseError Char Dec) Config)
parseConfigFile fmt file = runParser (configP fmt) file <$> readFile file
-- NAME.{EXTENSION}
extension :: FilePath -> String
extension = drop 1 . dropWhile (/= '.')
-- {NAME}.EXTENSION
name :: FilePath -> String
name = takeWhile (/= '.')
-- List all the non-special (.,..) entries in a directory
listDirectory :: FilePath -> IO [FilePath]
listDirectory path =
(filter f) <$> (getDirectoryContents path)
where f filename = filename /= "." && filename /= ".."