From 7242b1b9d156287fee3236b90e555acca307499d Mon Sep 17 00:00:00 2001 From: vvsob Date: Tue, 30 Dec 2025 04:01:20 +0300 Subject: [PATCH] file support --- app/Main.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Main.hs b/app/Main.hs index a4dff38..64d2c8e 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -2,6 +2,7 @@ import Lox.Scanner import Lox.Parser import Lox.Interpreter import System.IO +import System.Environment run :: String -> IO () run source = do @@ -16,5 +17,13 @@ run source = do Left ExpectedSemicolonError -> putStrLn "Expected semicolon" Right statements -> runStatements statements +repl :: IO () +repl = putStr ">> " >> hFlush stdout >> getLine >>= run + 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]"