aboutsummaryrefslogtreecommitdiff
path: root/src/Fun/Compiler.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Fun/Compiler.hs')
-rw-r--r--src/Fun/Compiler.hs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/Fun/Compiler.hs b/src/Fun/Compiler.hs
index f7e5c85..5ceb967 100644
--- a/src/Fun/Compiler.hs
+++ b/src/Fun/Compiler.hs
@@ -4,14 +4,18 @@ import Control.Exception
import Fun.Parser
import Fun.Tree
-parse :: String -> Block -- TODO: Should be tree
-parse file = case block file of
- Nothing -> error "Invalid program"
- Just (a, b) -> a
+parse :: String -> Either String Program -- TODO: Should be tree
+parse file = case program file of
+ Left a -> Left $ "Invalid code around here:\n" ++ case a of
+ Nothing -> "[No context]"
+ Just str -> str
+ Right (a, b) -> Right a
compile :: String -> IO ()
compile path = do
file <- try $ readFile path
case file of
Left exception -> print (exception :: IOError)
- Right file -> putStrLn . show $ parse file
+ Right file -> case parse file of
+ Left err -> putStrLn err
+ Right block -> putStrLn . show $ block