packages feed

ctpl-0.1.0.4: compiler.hs

import System.Environment
import System.IO
import Text.CTPL

comp :: String -> CCConfig -> IO ()
comp str cfg =
  case compileCTPL str cfg of
    Succ a -> putStrLn a
    NoSuchProc nm ->
      hPutStrLn stderr ("Error: No such procedure \""++nm++"\".")
    SyntaxFault ->
      hPutStrLn stderr "Error: Syntax fault."

main = do
  args <- getArgs
  case args of
    ["--old"] -> do
      str <- getContents
      comp str oldConfig
    ["--new"] -> do
      str <- getContents
      comp str newConfig
    ["--old", f] -> do
      str <- readFile f
      comp str oldConfig
    ["--new", f] -> do
      str <- readFile f
      comp str newConfig
    ["--help"] -> do
      putStrLn "ctplc 0.1"
      putStrLn "-------------"
      putStrLn "A compiler for CTPL."
      putStrLn "Synapsis:"
      putStrLn "  ctplc --old [<program-file>]"
      putStrLn "      Compiles the given file (or stdin) for the old (and new) VM."
      putStrLn "  ctplc --new [<program-file>]"
      putStrLn "      Compiles the given file (or stdin) for the new VM only."
    _ -> hPutStrLn stderr "Don't know what to do. See --help for help."