{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, ScopedTypeVariables #-}

module Main (main) where

import RAExpr.Row
import RAExpr.RASet
import RAExpr.Value
import RAExpr.Condition
import RAExpr.Expression
import Parser
import Class.Pretty

import System.Environment
import System.IO (hFlush, stdout)
import Text.Parsec (parse)

import qualified System.REPL as REPL
import qualified System.REPL.Command as Command
import Data.Text.Lazy
import System.IO

expressionAsker :: REPL.Asker IO REPL.Verbatim
expressionAsker = REPL.typeAsker (pack "> ") (pack "ERROR!")

main = do
  input <- REPL.ask' expressionAsker
  let expression = (unpack (REPL.fromVerbatim input))
  run $ parseExpression expression
  main

run (Right expression) = putStrLn (pretty result)
  where (Just result) = eval expression
run (Left error) = putStrLn (show error)

