hnock

A Nock interpreter.
git clone git://git.jtobin.io/hnock.git
Log | Files | Refs | README | LICENSE

Main.hs (554B)


      1 {-# LANGUAGE OverloadedStrings #-}
      2 
      3 module Main where
      4 
      5 import Control.Monad (when)
      6 import qualified Data.Text as T
      7 import qualified Data.Text.IO as T
      8 import Nock
      9 import System.Exit (exitSuccess)
     10 
     11 main :: IO ()
     12 main = do
     13   input <- T.getContents
     14 
     15   when (T.length input == 0) $ do
     16     T.putStrLn "USAGE: echo EXPR | ./hnock"
     17     exitSuccess
     18 
     19   case parse input of
     20     Left parseErr -> T.putStrLn (T.pack (show parseErr))
     21     Right e -> case eval e of
     22       Left err   -> T.putStrLn (T.pack (show err))
     23       Right noun -> T.putStrLn (T.pack (show noun))
     24