aboutsummaryrefslogtreecommitdiffstats
path: root/src/BizExpr.hs
diff options
context:
space:
mode:
authordan <[email protected]>2024-04-20 13:58:34 -0400
committerdan <[email protected]>2024-04-20 13:58:34 -0400
commit9331780bedd675ece82aebd1f12ce8b053a618f8 (patch)
tree0904c84c1207aad92585b4c9c2017db570ce4b50 /src/BizExpr.hs
parent77a0492e543af59a2f3ed132e2ce08ac9816d8fc (diff)
downloadbizexp-9331780bedd675ece82aebd1f12ce8b053a618f8.tar.gz
bizexp-9331780bedd675ece82aebd1f12ce8b053a618f8.tar.bz2
bizexp-9331780bedd675ece82aebd1f12ce8b053a618f8.zip
feat: project also builds a "repl" executable
Diffstat (limited to 'src/BizExpr.hs')
-rwxr-xr-xsrc/BizExpr.hs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/BizExpr.hs b/src/BizExpr.hs
index 1026e47..20a25d1 100755
--- a/src/BizExpr.hs
+++ b/src/BizExpr.hs
@@ -12,10 +12,13 @@ type Context = M.Map L.Text L.Text
--import Data.Text as T
repl :: IO ()
-repl = getLine >>= putStrLn . maybe "Failed to evaluate expression" show . (eval M.empty :: String -> Maybe Integer) >> repl
+repl = getLine >>= putStrLn . maybe "Failed to evaluate expression" id . (eval M.empty :: String -> Maybe String) >> repl
+
+maybeHead (x:_) = Just x
+maybeHead _ = Nothing
eval :: CoerceTo a => Context -> String -> Maybe a
-eval c x = coerceTo =<< evalAst . head . fst =<< parseLevel c x
+eval c x = coerceTo =<< evalAst =<< maybeHead . fst =<< parseLevel c x
data Value = IntVal Integer | StrVal String | BoolVal Bool | FloatVal Float
deriving (Show)
@@ -82,6 +85,8 @@ parseLevel c = go "" (Just [])
go prev (Just l) (',' : next) =
let l0 = [Val $ newVal c prev]
in go "" (Just (l ++ l0)) next
+ go prev l (' ' : next) =
+ go "" l next
go "" (Just l) "" =
Just (l, "")
go prev (Just l) "" =