aboutsummaryrefslogtreecommitdiff
path: root/bin/Main.hs
blob: 2942566b2b59150b4e4dea87fd5d4b43b26ee324 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Main where

import           Evaluator                     (eval)
import           Parser                        (Expr (..), parseLispValue)
import           System.Console.Readline
import           Text.ParserCombinators.Parsec

readExpr :: String -> Expr
readExpr inp =
    case parse parseLispValue "(unknown)" inp of
      Left err  -> StringLiteral $ show err
      Right val -> val

repl :: IO ()
repl = do
    inp <- readline "(lisk)> "
    case inp of
      Nothing -> return ()
      Just ",q" -> return ()
      Just line -> do
          addHistory line
          print . eval . readExpr $ line
          repl

main :: IO ()
main = repl