aboutsummaryrefslogtreecommitdiff
path: root/app/Main.hs
blob: e5144f1214b5a9b341d952b4dc21fee89c23a0a3 (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
28
29
30
31
32
33
34
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TupleSections #-}
module Main where

import Data.List (intersperse)
import System.Environment (getArgs)
import System.Exit (die, exitFailure)

import HSVIS.Diagnostic
import HSVIS.Parser
import HSVIS.Typecheck


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
    (errs, Nothing) -> do
      sequence_ $ intersperse (putStrLn "") (map (putStrLn . printDiagnostic) errs)
      exitFailure
    (errs, Just res) -> do
      sequence_ $ intersperse (putStrLn "") (map (putStrLn . printDiagnostic) errs)
      return res

  print prog

  let (errs, tprog) = typecheck fname source prog
  sequence_ $ intersperse (putStrLn "") (map (putStrLn . printDiagnostic) errs)

  print tprog