aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorMarvin Borner2024-11-13 16:18:01 +0100
committerMarvin Borner2024-11-13 21:53:37 +0100
commitf60b209eae598160f6cf160415e08ae72658cd32 (patch)
tree3f8db41ec8b0e378b2aa3e2d1c8f827b981cbb32 /app
Initial structure
Diffstat (limited to 'app')
-rw-r--r--app/Main.hs45
1 files changed, 45 insertions, 0 deletions
diff --git a/app/Main.hs b/app/Main.hs
new file mode 100644
index 0000000..b0a3aca
--- /dev/null
+++ b/app/Main.hs
@@ -0,0 +1,45 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main
+ ( main
+ ) where
+
+import Data.Mili ( Term(..) )
+import qualified Data.Text as T
+import Language.Mili.Analyzer ( linearity )
+import Language.Mili.Parser ( parseProgram )
+import Language.Mili.Reducer ( nf )
+import Options.Applicative ( (<**>)
+ , Parser
+ , execParser
+ , fullDesc
+ , header
+ , helper
+ , info
+ )
+
+data ArgMode = ArgEval
+
+newtype Args = Args
+ { _argMode :: ArgMode
+ }
+
+args :: Parser Args
+args = pure $ Args ArgEval
+
+pipeline :: T.Text -> Either String Term
+pipeline program = parseProgram program >>= linearity
+
+actions :: Args -> IO ()
+actions Args { _argMode = ArgEval } = do
+ program <- getContents
+ case pipeline (T.pack program) of
+ Left err -> putStrLn err
+ Right out ->
+ let term = show out
+ normal = show $ nf out
+ in putStrLn $ term <> "\n" <> normal
+
+main :: IO ()
+main = execParser opts >>= actions
+ where opts = info (args <**> helper) (fullDesc <> header "bruijn but linear")