mirror of
https://github.com/The1Penguin/org-to-mafiauniverse.git
synced 2024-11-24 19:08:11 +00:00
more readable code and moved main to bottom
This commit is contained in:
parent
39f5aa8770
commit
cea8d45ddd
29
app/Main.hs
29
app/Main.hs
@ -8,37 +8,27 @@ import System.Environment
|
|||||||
import System.Exit
|
import System.Exit
|
||||||
import Text.Megaparsec hiding (satisfy)
|
import Text.Megaparsec hiding (satisfy)
|
||||||
import Text.Megaparsec.Char
|
import Text.Megaparsec.Char
|
||||||
import Text.ParserCombinators.ReadP hiding (string)
|
|
||||||
|
|
||||||
type Parser = Parsec Void String
|
type Parser = Parsec Void String
|
||||||
|
|
||||||
|
parseHelper :: Parser String -> String -> String
|
||||||
|
parseHelper parser x = case parse parser "" x of
|
||||||
|
Left bundle -> error $ errorBundlePretty bundle
|
||||||
|
Right text -> text
|
||||||
|
|
||||||
parseFile :: String -> String
|
parseFile :: String -> String
|
||||||
parseFile =
|
parseFile = unlines . map (parseHelper fileParser) . lines
|
||||||
unlines
|
|
||||||
. map
|
|
||||||
( \x -> case parse fileParser "" x of
|
|
||||||
Left bundle -> error ("Error parsing text" ++ errorBundlePretty bundle)
|
|
||||||
Right text -> text
|
|
||||||
)
|
|
||||||
. lines
|
|
||||||
|
|
||||||
fileParser :: Parser String
|
fileParser :: Parser String
|
||||||
fileParser = undefined
|
fileParser = undefined
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = putStr =<< parseCli =<< getArgs
|
|
||||||
|
|
||||||
parseCli :: [String] -> IO String
|
parseCli :: [String] -> IO String
|
||||||
parseCli [] = return usage
|
parseCli [] = return usage
|
||||||
parseCli [x] =
|
parseCli [x] =
|
||||||
if head x /= '-'
|
if head x /= '-'
|
||||||
then parseFile <$> readFile x
|
then parseFile <$> readFile x
|
||||||
else case parse argParse "" x of
|
else return $ useArgs $ parseHelper argParse x
|
||||||
Left bundle -> fail $ "Failed parsing args" ++ errorBundlePretty bundle
|
parseCli [x, _] = return $ useArgs $ parseHelper argParse x
|
||||||
Right text -> return $ useArgs text
|
|
||||||
parseCli [x, _] = case parse argParse "" x of
|
|
||||||
Left bundle -> fail $ "Failed parsing args" ++ errorBundlePretty bundle
|
|
||||||
Right text -> return $ useArgs text
|
|
||||||
parseCli _ = fail "Too many arugemnts"
|
parseCli _ = fail "Too many arugemnts"
|
||||||
|
|
||||||
argParse :: Parser String
|
argParse :: Parser String
|
||||||
@ -56,3 +46,6 @@ usage = "Usage: otm [-hv] [file]"
|
|||||||
|
|
||||||
version :: String
|
version :: String
|
||||||
version = "otm 0.1"
|
version = "otm 0.1"
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = putStr =<< parseCli =<< getArgs
|
||||||
|
Loading…
Reference in New Issue
Block a user