diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/hsnock.cabal b/hsnock.cabal new file mode 100644 index 0000000..7787e9c --- /dev/null +++ b/hsnock.cabal @@ -0,0 +1,12 @@ +name: hsnock +version: 0.1.0.0 +synopsis: Nock 5K interpreter +author: Steven Dee +maintainer: mrdomino@gmail.com +category: Language +build-type: Simple +cabal-version: >=1.8 + +executable hsnock + main-is: nock.hs + build-depends: base ==4.5.*, parsec ==3.1.*, readline diff --git a/nock.hs b/nock.hs index f8b39e2..d7e2279 100755 --- a/nock.hs +++ b/nock.hs @@ -1,28 +1,23 @@ #!/usr/bin/env runhaskell {-# LANGUAGE ScopedTypeVariables #-} +import Prelude hiding (catch) import Nock5K.Parse import Nock5K.Spec import Control.Exception -import System.Exit -import System.IO -import System.IO.Error (isEOFError) +import System.Console.Readline import Text.ParserCombinators.Parsec (parse) -rep = srpa >>= print . nock +repl = do ln <- readline "nock " + case ln of + Nothing -> return () + Just "exit" -> return () + Just s -> do addHistory s + case parse noun "" s of + Left e -> print e + Right n -> ep n + repl where - srpa = s >> r >>= pa - s = putStr "nock " >> hFlush stdout - r = getLine - pa l = case parse noun "" l of - Left e -> hPrint stderr e >> srpa - Right n -> return n + ep n = (print . nock) n `catch` (\(e :: SomeException) -> print e) -repl = rep `catches` hs >> repl - where - hs = [ Handler (\(e :: IOException) -> - if isEOFError e then exitSuccess else hPrint stderr e) - , Handler (\(e :: SomeException) -> hPrint stderr e) ] - -desc = "Nock 5K. ^D to exit." -main = putStrLn desc >> repl +main = repl