hnock

A Nock interpreter.
Log | Files | Refs | README | LICENSE

commit 6971fa430951247ca8a86564891c72c185ac9ae0
parent 215a3500a73456b4ebeb615881fdd1de09ff9b27
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri,  1 Feb 2019 05:01:06 +1300

Use 'Integer' rather than 'Int' for atoms.

Diffstat:
Mhnock.cabal | 2+-
Mlib/Nock.hs | 2+-
Mlib/Nock/Language.hs | 4++--
Mlib/Nock/Parse.hs | 19+++++++++----------
4 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/hnock.cabal b/hnock.cabal @@ -1,5 +1,5 @@ name: hnock -version: 0.2.0 +version: 0.3.0 synopsis: A Nock interpreter. description: A Nock interpreter. homepage: https://github.com/jtobin/hnock diff --git a/lib/Nock.hs b/lib/Nock.hs @@ -16,7 +16,7 @@ import Nock.Language as L import Nock.Parse as P hnock :: T.Text -> Noun -hnock input = case runParser expr [] "ghci" input of +hnock input = case P.parse input of Left perr -> error (show perr) Right ex -> case E.eval ex of Left err -> error (show err) diff --git a/lib/Nock/Language.hs b/lib/Nock/Language.hs @@ -4,8 +4,8 @@ module Nock.Language ( ) where data Noun = - Atom !Int - | Cell !Noun !Noun + Atom Integer + | Cell Noun Noun deriving Eq instance Show Noun where diff --git a/lib/Nock/Parse.hs b/lib/Nock/Parse.hs @@ -42,14 +42,13 @@ atom :: Monad m => P.ParsecT T.Text u m Noun atom = do digits <- P.many P.digit case digits of - (h:t) -> case h of - '0' -> case t of - [] -> return (Atom 0) - _ -> fail "atom: bad input" + ('0':t) -> case t of + [] -> return (Atom 0) + _ -> fail "atom: bad input" - _ -> - let nat = read digits - in return (Atom nat) + (_:_) -> + let nat = read digits + in return (Atom nat) [] -> fail "atom: bad input" @@ -57,13 +56,13 @@ cell :: Monad m => P.ParsecT T.Text u m Noun cell = do P.char '[' P.skipMany P.space - leader <- noun + h <- noun P.skipMany P.space - rest <- P.sepBy noun (P.many1 P.space) + t <- P.sepBy noun (P.many1 P.space) P.skipMany P.space P.char ']' - return (toCell (leader : rest)) + return (toCell (h : t)) toCell :: [Noun] -> Noun toCell = loop where