summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-01-09 01:07:25 -0700
committerJosh Rahm <joshuarahm@gmail.com>2023-01-09 01:07:25 -0700
commita33b80dbf64303fe376419216c1245a0238ea37d (patch)
tree18477f448abe49d9c384ff0b24d1874eb83afdaa /src/Main.hs
parentdef481d234ce5e1671d9faaa539477de8cd14640 (diff)
downloadfiddle-a33b80dbf64303fe376419216c1245a0238ea37d.tar.gz
fiddle-a33b80dbf64303fe376419216c1245a0238ea37d.tar.bz2
fiddle-a33b80dbf64303fe376419216c1245a0238ea37d.zip
Crude compilation pipeline starting to take shape.
This simply does a Stage0 -> Stage1 conversion. Namely, parse the text, check for syntax errors, squeeze the resulting ast and ... that's it.
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/Main.hs b/src/Main.hs
index ea41afe..92e9a1d 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -1,16 +1,19 @@
module Main where
-import qualified Language.Fiddle.Tokenizer
-import qualified Language.Fiddle.Parser
-import Language.Fiddle.Ast
-import qualified Data.Text.IO
-import qualified System.Environment as System
import Control.Monad (forM_)
import Control.Monad.Writer
-import qualified Language.Fiddle.Parser
-import Language.Fiddle.GenericTree (ToGenericSyntaxTree(toGenericSyntaxTree))
import Data.Aeson (encode)
import qualified Data.ByteString.Lazy.Char8 as BL
+import qualified Data.Text.IO
+import GHC.IO.Exception (ExitCode (ExitFailure))
+import Language.Fiddle.Ast
+import Language.Fiddle.Compiler (coloredFormat, compile_, printDiagnostic)
+import Language.Fiddle.Compiler.Stage0
+import Language.Fiddle.GenericTree (ToGenericSyntaxTree (toGenericSyntaxTree))
+import qualified Language.Fiddle.Parser
+import qualified Language.Fiddle.Tokenizer
+import qualified System.Environment as System
+import System.Exit (exitWith)
main :: IO ()
main = do
@@ -18,10 +21,16 @@ main = do
case argv of
[filePath] -> do
- text <- Data.Text.IO.readFile filePath
- case squeeze =<< Language.Fiddle.Parser.parseFiddleText filePath text of
- Left pe -> putStrLn $ "Parse Error: " ++ show pe
- Right ast -> do
- putStrLn (BL.unpack $ encode $ toGenericSyntaxTree $ fmap (const ()) ast)
-
- _ -> putStrLn "Wrong Args"
+ text <- Data.Text.IO.readFile filePath
+ let (diags, ma) = compile_ $ toStage1 =<< toStage0 filePath text
+ forM_ diags printDiagnostic
+ case ma of
+ Just ast -> do
+ putStrLn "\x1b[1;32mCompilation Succeeded:\x1b[0m"
+ putStrLn $ BL.unpack $ encode $ toGenericSyntaxTree ast
+ Nothing -> do
+ putStrLn "\x1b[1;31mCompilation Failed\x1b[0m"
+ exitWith (ExitFailure 1)
+ _ -> do
+ putStrLn "Wrong Args"
+ exitWith (ExitFailure 2)