aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
blob: c9de0cc492d3c195177a396a3e07fc91411f5e8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TupleSections #-}
module Main where

import System.Environment (getArgs)
import System.Exit (die, exitFailure)

import Parser


main :: IO ()
main = do
  (source, fname) <- getArgs >>= \case
    [] -> (,"<stdin>") <$> getContents
    [fname] -> (,fname) <$> readFile fname
    _ -> die "Usage: hs-visinter [filename.hs]"

  prog <- case parse fname source of
    This errs -> do
        mapM_ (putStrLn . printErrMsg) errs
        exitFailure
    These errs res -> do
        mapM_ (putStrLn . printErrMsg) errs
        return res
    That res -> return res

  print prog