summaryrefslogtreecommitdiff
path: root/src/Main.hs
blob: 07733ddb44adc632654f5c9abf4d551b9cf36fe3 (plain) (blame)
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
-- vim: et ts=2 sw=2 ai:
module Main where

import Prelude hiding(lex)
import System.Environment

import Text.Parsec.Error (ParseError)

import SPL.Syntax
import SPL.Lex
import SPL.Parse
import SPL.PrettyPrinter

main :: IO ()
main = do
  args <- getArgs
  contents <- getContents
  case lex contents of
    Nothing  -> putStrLn "Failed to lex"
    Just tks -> if "--parse" `elem` args
      then doParse tks
      else return ()
  where
    doParse :: [Token] -> IO ()
    doParse tks = case parse tks of
      Left e -> do
        putStrLn $ "Failed to parse (" ++ show e ++ "). Tokens were:"
        putStrLn $ show tks
      Right pgm -> putStrLn $ prettyPrint pgm