Cabal-ize and readline-ize

This commit is contained in:
Steven Dee 2013-10-20 18:43:55 -04:00
parent bfd063fa5a
commit ed06289366
3 changed files with 27 additions and 18 deletions

2
Setup.hs Normal file
View File

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

12
hsnock.cabal Normal file
View File

@ -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

31
nock.hs
View File

@ -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