1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-02 18:41:35 +00:00
SixtyPical/src/Main.hs
Cat's Eye Technologies b455709ef1 Analyze bfore mitting
2014-04-04 15:45:49 +01:00

49 lines
1.7 KiB
Haskell

-- encoding: UTF-8
module Main where
import System.IO
import System.Environment
import System.Exit
import SixtyPical.Model
import SixtyPical.Parser (parseProgram)
import SixtyPical.Checker (checkAndTransformProgram)
import SixtyPical.Analyzer (analyzeProgram)
import SixtyPical.Context (ppAnalysis)
import SixtyPical.Emitter (emitProgram)
-- -- -- -- driver -- -- -- --
usage = do
putStrLn "Usage: sixtypical (parse|check|analyze|emit) filename.60p"
exitWith $ ExitFailure 1
main = do
args <- getArgs
case args of
[verb, filename] -> do
programText <- readFile filename
case (verb, parseProgram programText) of
("parse", Right program) -> do
putStrLn $ show $ program
("check", Right program) -> do
case checkAndTransformProgram program of
Just newprog ->
putStrLn $ programSummary newprog
("analyze", Right program) ->
case checkAndTransformProgram program of
Just newprog ->
ppAnalysis newprog (analyzeProgram newprog)
("emit", Right program) ->
case checkAndTransformProgram program of
Just newprog ->
case (length (show (analyzeProgram newprog)) < 9999999) of
True ->
putStr $ emitProgram newprog
(_, Left problem) -> do
hPutStrLn stderr (show problem)
exitWith $ ExitFailure 1
(_, _) -> usage
_ -> usage