2013-10-20 22:55:30 +00:00
|
|
|
-- Driver for the Lamb programming language
|
|
|
|
-- Copyright (c) 2013 darkf
|
|
|
|
-- Licensed under the terms of the zlib license, see LICENSE for details
|
|
|
|
|
|
|
|
import System.Environment (getArgs)
|
|
|
|
import System.Directory (doesFileExist)
|
|
|
|
import Interp (evalProgram, evalString, Value(UnitV))
|
|
|
|
|
|
|
|
-- returns Nothing if all files exist, or Just path for the first one that doesn't
|
|
|
|
allExist :: [String] -> IO (Maybe String)
|
|
|
|
allExist [] = return Nothing
|
|
|
|
allExist (x:xs) = do
|
|
|
|
exists <- doesFileExist x
|
|
|
|
if exists then allExist xs
|
|
|
|
else return $ Just x
|
|
|
|
|
|
|
|
evalFile :: String -> IO Value
|
|
|
|
evalFile path = do
|
|
|
|
contents <- readFile path
|
2013-10-23 00:24:28 +00:00
|
|
|
evalString contents
|
2013-10-20 22:55:30 +00:00
|
|
|
|
|
|
|
main = do
|
|
|
|
args <- getArgs
|
|
|
|
exist <- allExist args
|
|
|
|
case exist of
|
|
|
|
Just file -> putStrLn $ "error: file " ++ file ++ " doesn't exist"
|
|
|
|
Nothing ->
|
|
|
|
mapM_ evalFile args
|