-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.hs
More file actions
96 lines (79 loc) · 2.58 KB
/
Copy pathMain.hs
File metadata and controls
96 lines (79 loc) · 2.58 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
-- Matt's Typechecker: Main Program
-- (C) Matt Teichman, 2018
-- You can get started by typing the following at the shell:
-- $ cabal new-exec lambda
-- You can also take a look at the README for more details:
-- $ cat README.txt
module Main where
-- library modules
import Data.Maybe
import System.Environment
import Data.List
-- my modules
import ImperativeFuncs
import LambdaParse
import Latex
import Lexer
import LTerm
-- run program in either normal mode or LaTeX mode
displayMode :: (Maybe (Either String TypedExpression) -> IO a) ->
String -> IO ()
displayMode displayFunc message = do
input <- getInput "LAMBDATERM"
case input of
Nothing -> termError
_ -> do
maybe_lexicon <- getLexicon "DECLARATIONS"
case maybe_lexicon of
Nothing -> lexiconError
Just _ -> do
putStr message
let lexicon = fromJust maybe_lexicon
parse = map (lambdaParse termP lexicon) $ fromJust input
mapM_ displayFunc parse
-- run program in full LaTeX mode
fullLatexMode :: IO ()
fullLatexMode = do
input <- getInput "LAMBDATERM"
case input of
Nothing -> termError
_ -> do
maybe_lexicon <- getLexicon "DECLARATIONS"
case maybe_lexicon of
Nothing -> lexiconError
Just _ -> do
let lexicon = fromJust maybe_lexicon
parse = map (lambdaParse termP lexicon) $ fromJust input
maybeEither = fmap sequence $ sequence parse
case maybeEither of
Nothing -> parseError
Just x -> case x of
Left e -> putStrLn e
Right y -> do
let fullString = intercalate "\\\\\n" $ map latexTE y
putStrLn "Writing LaTeX file..."
writeLatex fullString
-- command line help message
usage :: String
usage =
"\n Welcome to Matt's Typechecker!\n\n" ++
" USAGE:\n\n" ++
" --check-types (normal mode)\n" ++
" --latex (latex mode)\n" ++
" --full-latex (full latex mode)\n\n" ++
" Place your inputs into two text files called:\n\n" ++
" DECLARATIONS (series of lexical entries)\n" ++
" LAMBDATERM (series of lambda terms)\n"
-- command line switchbox
command "--check-types" = do
displayMode displayMaybe "\nHere are the types of your lambda terms:\n\n"
putStr "\n"
command "--latex" = displayMode latexMaybe ""
command "--full-latex" = fullLatexMode
command _ = putStrLn usage
-- main program
main = do
argv <- getArgs
case length argv of
1 -> command $ head argv
_ -> putStrLn usage