file support
This commit is contained in:
parent
44f39a7cf2
commit
7242b1b9d1
1 changed files with 10 additions and 1 deletions
11
app/Main.hs
11
app/Main.hs
|
|
@ -2,6 +2,7 @@ import Lox.Scanner
|
||||||
import Lox.Parser
|
import Lox.Parser
|
||||||
import Lox.Interpreter
|
import Lox.Interpreter
|
||||||
import System.IO
|
import System.IO
|
||||||
|
import System.Environment
|
||||||
|
|
||||||
run :: String -> IO ()
|
run :: String -> IO ()
|
||||||
run source = do
|
run source = do
|
||||||
|
|
@ -16,5 +17,13 @@ run source = do
|
||||||
Left ExpectedSemicolonError -> putStrLn "Expected semicolon"
|
Left ExpectedSemicolonError -> putStrLn "Expected semicolon"
|
||||||
Right statements -> runStatements statements
|
Right statements -> runStatements statements
|
||||||
|
|
||||||
|
repl :: IO ()
|
||||||
|
repl = putStr ">> " >> hFlush stdout >> getLine >>= run
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = putStr ">> " >> hFlush stdout >> getLine >>= run
|
main = getArgs >>= fs
|
||||||
|
|
||||||
|
fs :: [String] -> IO ()
|
||||||
|
fs [] = repl
|
||||||
|
fs [s] = readFile s >>= run
|
||||||
|
fs _ = putStrLn "Usage: lox [file]"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue