mirror of
https://github.com/mrdomino/hsnock.git
synced 2024-10-05 17:47:44 +03:00
Cabal-ize and readline-ize
This commit is contained in:
parent
bfd063fa5a
commit
ed06289366
12
hsnock.cabal
Normal file
12
hsnock.cabal
Normal 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
31
nock.hs
@ -1,28 +1,23 @@
|
|||||||
#!/usr/bin/env runhaskell
|
#!/usr/bin/env runhaskell
|
||||||
{-# LANGUAGE ScopedTypeVariables #-}
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
|
import Prelude hiding (catch)
|
||||||
|
|
||||||
import Nock5K.Parse
|
import Nock5K.Parse
|
||||||
import Nock5K.Spec
|
import Nock5K.Spec
|
||||||
import Control.Exception
|
import Control.Exception
|
||||||
import System.Exit
|
import System.Console.Readline
|
||||||
import System.IO
|
|
||||||
import System.IO.Error (isEOFError)
|
|
||||||
import Text.ParserCombinators.Parsec (parse)
|
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
|
where
|
||||||
srpa = s >> r >>= pa
|
ep n = (print . nock) n `catch` (\(e :: SomeException) -> print e)
|
||||||
s = putStr "nock " >> hFlush stdout
|
|
||||||
r = getLine
|
|
||||||
pa l = case parse noun "" l of
|
|
||||||
Left e -> hPrint stderr e >> srpa
|
|
||||||
Right n -> return n
|
|
||||||
|
|
||||||
repl = rep `catches` hs >> repl
|
main = 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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user