-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
35 lines (28 loc) · 856 Bytes
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Main (main) where
import Ast (Program)
import Json (toJsonProgram)
import Lexer (lexer)
import Parser (flecha)
import System.Environment (getArgs)
import Mamarracho (compile)
main :: IO ()
main = do
args <- getArgs
case args of
(filename:options) -> do
file <- readFile filename
printResult file options
_ ->
error "Invalid arguments.\nUsage: cabal run flecha -- example.flecha"
printResult :: String -> [String] -> IO ()
printResult file ("--ast":_) = printAST $ parse file
printResult file ("--json":_) = printJSON $ parse file
printResult file _ = printMAM $ parse file
parse :: String -> Program
parse = flecha . lexer
printAST :: Program -> IO ()
printAST = print
printJSON :: Program -> IO ()
printJSON = putStrLn . toJsonProgram
printMAM :: Program -> IO ()
printMAM = putStrLn . compile