-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.hs
More file actions
executable file
·43 lines (38 loc) · 1.19 KB
/
Copy pathMain.hs
File metadata and controls
executable file
·43 lines (38 loc) · 1.19 KB
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
33
34
35
36
37
38
39
40
41
42
43
import Shiny.Runner
import Shiny.Eval
import Shiny.Structure
import Shiny.Symbol
import Shiny.Standard
import Shiny.Parser
import System.Environment
import System.IO
import Control.Monad
import Control.Monad.Trans.Except
import Control.Monad.IO.Class
showHelp :: IO ()
showHelp = do
putStrLn "Usage:"
putStrLn " shiny - Open a REPL"
putStrLn " shiny <filename> <args...> - Execute the file, passing the given command line arguments"
putStrLn " shiny --help - Show the help screen"
doREPL :: IO ()
doREPL = do
hSetBuffering stdin NoBuffering
hSetBuffering stdout NoBuffering
hSetBuffering stderr NoBuffering
void . runSymbols standardState . forever $ catchS operation (liftIO . putStrLn)
where operation = do
liftIO $ putStr "> "
x <- liftIO $ getLine
e <- Symbols . ExceptT . pure $ readExpr x
res <- evalSeq e
liftIO $ putStrLn (printable res)
doFile :: FilePath -> [String] -> IO ()
doFile file args = withArgs args (evalFileThenPrint file)
main :: IO ()
main = do
args <- getArgs
case args of
["--help"] -> showHelp
[] -> doREPL
(x:xs) -> doFile x xs