diff options
author | Marvin Borner | 2024-12-29 16:22:54 +0100 |
---|---|---|
committer | Marvin Borner | 2024-12-29 16:22:54 +0100 |
commit | 3da2f9e537dbb379a4fa40c1b47ae56fd479b2e7 (patch) | |
tree | 876c664a7d60df9af507a398970204256551a765 /lllars/parser.hs | |
parent | ac53a2bf106dccd2de463f7c68c2527ee6e08f4e (diff) |
better
Diffstat (limited to 'lllars/parser.hs')
-rw-r--r-- | lllars/parser.hs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lllars/parser.hs b/lllars/parser.hs index f843849..da94ed7 100644 --- a/lllars/parser.hs +++ b/lllars/parser.hs @@ -1,6 +1,7 @@ import Data.Functor ( ($>) ) import Data.List ( intercalate ) import Data.Void +import System.Environment import Text.Megaparsec hiding ( Label , Pos , label @@ -124,13 +125,17 @@ license = string "!!! all rights reserved to lars <3 !!!\n\n" program :: Parser Program program = license *> sepEndBy instr (some $ char '\n') +parseProgram :: String -> IO () +parseProgram p = case runParser (program <* many (char '\n') <* eof) "" p of + Right ps -> + putStrLn $ "{ \"instructions\": [" <> intercalate "," (show <$> ps) <> "]}" + Left err -> putStrLn $ errorBundlePretty err + main :: IO () main = do - f <- readFile "chal.lll" - case runParser (program <* many (char '\n') <* eof) "" f of - Right ps -> - putStrLn - $ "{ \"instructions\": [" - <> intercalate "," (show <$> ps) - <> "]}" - Left err -> putStrLn $ errorBundlePretty err + args <- getArgs + case args of + [file] -> do + p <- readFile file + parseProgram p + _ -> putStrLn "Wrong number of arguments" |