file support

This commit is contained in:
Oleg Sobolev 2025-12-30 04:01:20 +03:00
parent 44f39a7cf2
commit 7242b1b9d1

View file

@ -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]"