Skip to content

Commit

Permalink
Read stdin when no filepaths are given
Browse files Browse the repository at this point in the history
  • Loading branch information
fizruk committed May 29, 2023
1 parent 01c2a01 commit 936c15a
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions rzk/src/Rzk/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ main = do
args <- getArgs
case args of
"typecheck" : paths -> do
modules <- forM paths $ \path -> do
putStrLn ("Loading file " <> path)
result <- Rzk.parseModule <$> readFile path
case result of
Left err -> do
putStrLn ("An error occurred when parsing file " <> path)
error err
Right rzkModule -> return (path, rzkModule)
modules <- case paths of
-- if no paths are given — read from stdin
[] -> do
result <- Rzk.parseModule <$> getContents
case result of
Left err -> do
putStrLn ("An error occurred when parsing stdin")
error err
Right rzkModule -> return [("<stdin>", rzkModule)]
-- otherwise — parse all given files in given order
_ -> forM paths $ \path -> do
putStrLn ("Loading file " <> path)
result <- Rzk.parseModule <$> readFile path
case result of
Left err -> do
putStrLn ("An error occurred when parsing file " <> path)
error err
Right rzkModule -> return (path, rzkModule)
case defaultTypeCheck (typecheckModulesWithLocation modules) of
Left err -> do
putStrLn "An error occurred when typechecking!"
Expand Down

0 comments on commit 936c15a

Please sign in to comment.