summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-08-24 13:55:41 -0600
committerJosh Rahm <joshuarahm@gmail.com>2024-08-24 13:55:41 -0600
commitf1128c7c60809d1e96009eaed98c0756831fe29f (patch)
tree3cc1957c7436e9efb1d26548b285fa3449574c3a /src/Main.hs
parent21f879cf2ac5f51f827fe76c55915e56edc113b8 (diff)
downloadfiddle-f1128c7c60809d1e96009eaed98c0756831fe29f.tar.gz
fiddle-f1128c7c60809d1e96009eaed98c0756831fe29f.tar.bz2
fiddle-f1128c7c60809d1e96009eaed98c0756831fe29f.zip
Add Stage3 compliation.
I think this is the last phase before sending the refined AST to the backend compiler to be processed.
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 9330df5..f92d6c6 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -5,11 +5,12 @@ import Control.Monad.Writer
import Data.Aeson (encode)
import qualified Data.ByteString.Lazy.Char8 as BL
import qualified Data.Text.IO
-import GHC.IO.Exception (ExitCode (ExitFailure))
+import GHC.IO.Exception (ExitCode (ExitFailure, ExitSuccess))
import Language.Fiddle.Ast
import Language.Fiddle.Compiler (coloredFormat, compile_, printDiagnostic)
import Language.Fiddle.Compiler.Stage0
import Language.Fiddle.Compiler.Stage1
+import Language.Fiddle.Compiler.Stage2
import Language.Fiddle.GenericTree (ToGenericSyntaxTree (toGenericSyntaxTree))
import qualified Language.Fiddle.Parser
import qualified Language.Fiddle.Tokenizer
@@ -23,14 +24,18 @@ main = do
case argv of
[filePath] -> do
text <- Data.Text.IO.readFile filePath
- let (diags, ma) = compile_ $ toStage2 =<< toStage1 =<< toStage0 filePath text
+ let (diags, ma) = compile_ $ toStage3 =<< toStage2 =<< toStage1 =<< toStage0 filePath text
+ ec <-
+ case ma of
+ Just ast -> do
+ putStrLn $ BL.unpack $ encode $ toGenericSyntaxTree ast
+ return ExitSuccess
+ Nothing -> do
+ putStrLn "\x1b[1;31mCompilation Failed\x1b[0m"
+ return (ExitFailure 1)
+
forM_ diags printDiagnostic
- case ma of
- Just ast -> do
- putStrLn $ BL.unpack $ encode $ toGenericSyntaxTree ast
- Nothing -> do
- putStrLn "\x1b[1;31mCompilation Failed\x1b[0m"
- exitWith (ExitFailure 1)
+ exitWith ec
_ -> do
putStrLn "Wrong Args"
exitWith (ExitFailure 2)