2022-10-26 09:57:55 +00:00
|
|
|
module Main where
|
|
|
|
|
2022-10-26 13:29:48 +00:00
|
|
|
import Control.Applicative
|
2022-10-26 10:37:48 +00:00
|
|
|
import Control.Monad
|
2022-10-26 11:59:46 +00:00
|
|
|
import Data.Functor
|
2022-10-26 10:03:45 +00:00
|
|
|
import System.Environment
|
2022-10-26 10:37:48 +00:00
|
|
|
import System.Exit
|
2022-10-26 13:29:48 +00:00
|
|
|
import Text.Megaparsec hiding (parse, satisfy)
|
2022-10-26 10:37:48 +00:00
|
|
|
import Text.ParserCombinators.ReadP
|
|
|
|
|
2022-10-26 13:29:48 +00:00
|
|
|
parse :: ReadP String -> String -> String
|
|
|
|
parse rules = fst . last . readP_to_S rules
|
2022-10-26 11:59:46 +00:00
|
|
|
|
2022-10-26 13:29:48 +00:00
|
|
|
parseFile :: String -> String
|
|
|
|
parseFile = unlines . map (parse fileParser) . lines
|
2022-10-26 11:59:46 +00:00
|
|
|
|
2022-10-26 13:29:48 +00:00
|
|
|
fileParser :: ReadP String
|
|
|
|
fileParser = undefined
|
2022-10-26 10:03:45 +00:00
|
|
|
|
2022-10-26 09:57:55 +00:00
|
|
|
main :: IO ()
|
2022-10-26 13:29:48 +00:00
|
|
|
main = putStr =<< parseCli =<< getArgs
|
2022-10-26 11:59:46 +00:00
|
|
|
|
2022-10-26 13:29:48 +00:00
|
|
|
parseCli :: [String] -> IO String
|
|
|
|
parseCli [] = return usage
|
|
|
|
parseCli [x] =
|
|
|
|
if head x /= '-'
|
|
|
|
then parseFile <$> readFile x
|
|
|
|
else return $ useArgs $ parse argParse x
|
|
|
|
parseCli [x, _] = return $ useArgs $ parse argParse x
|
|
|
|
parseCli _ = fail "Too many arugemnts"
|
2022-10-26 10:37:48 +00:00
|
|
|
|
|
|
|
argParse :: ReadP String
|
|
|
|
argParse =
|
2022-10-26 13:29:48 +00:00
|
|
|
string "-" >> many1 (satisfy (/= ' '))
|
2022-10-26 10:37:48 +00:00
|
|
|
|
2022-10-26 11:59:46 +00:00
|
|
|
useArgs :: String -> String
|
2022-10-26 13:29:48 +00:00
|
|
|
useArgs [] = ""
|
|
|
|
useArgs ('h' : _) = usage
|
|
|
|
useArgs ('v' : _) = version
|
|
|
|
useArgs (_ : xs) = useArgs xs
|
2022-10-26 10:37:48 +00:00
|
|
|
|
2022-10-26 11:59:46 +00:00
|
|
|
usage :: String
|
2022-10-26 13:29:48 +00:00
|
|
|
usage = "Usage: otm [-hv] [file]"
|
|
|
|
|
2022-10-26 11:59:46 +00:00
|
|
|
version :: String
|
|
|
|
version = "otm 0.1"
|