-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
36 lines (28 loc) · 821 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 where
import Bison.Grammar.Codegen (withFile, productions)
import Control.Monad.Reader
import Options.Applicative
import Data.Version (showVersion)
import Paths_bison_grammar_codegen (version)
data Args = Args {
printVersion :: Bool
} deriving (Show, Read, Eq)
argParser :: Parser Args
argParser = Args
<$> switch (short 'v' <> help "print version information and exit")
readArgs :: IO Args
readArgs = execParser pInfo
where
pInfo = info (argParser <**> helper) fullDesc
runVersion :: IO ()
runVersion = putStrLn (showVersion version)
runCodegen :: IO ()
runCodegen = do
withFile Nothing $ do
ps <- productions
liftIO $ mapM_ (putStrLn . show) ps
main :: IO ()
main = do
args <- readArgs
if printVersion args then runVersion
else runCodegen