65 lines
1.2 KiB
Haskell
65 lines
1.2 KiB
Haskell
module Main where
|
|
|
|
import MyLib (handleFileInput)
|
|
import Options.Applicative
|
|
( Alternative ((<|>)),
|
|
Parser,
|
|
ParserInfo,
|
|
execParser,
|
|
flag',
|
|
fullDesc,
|
|
header,
|
|
help,
|
|
helper,
|
|
info,
|
|
long,
|
|
metavar,
|
|
progDesc,
|
|
short,
|
|
strOption,
|
|
(<**>),
|
|
)
|
|
|
|
data CmdLineInput
|
|
= FileInput FilePath
|
|
| StdInput
|
|
|
|
fileInput :: Parser CmdLineInput
|
|
fileInput =
|
|
FileInput
|
|
<$> strOption
|
|
( long "file"
|
|
<> short 'f'
|
|
<> metavar "FILENAME"
|
|
<> help "Input file with Lox code"
|
|
)
|
|
|
|
stdInput :: Parser CmdLineInput
|
|
stdInput =
|
|
flag'
|
|
StdInput
|
|
( long "stdin"
|
|
<> help "Read from stdin"
|
|
)
|
|
|
|
cmdLineInput :: Parser CmdLineInput
|
|
cmdLineInput = fileInput <|> stdInput
|
|
|
|
handleCmdLineInput :: CmdLineInput -> IO ()
|
|
handleCmdLineInput = \case
|
|
FileInput file -> handleFileInput file
|
|
StdInput -> print "We do not handle stdin yet"
|
|
|
|
main :: IO ()
|
|
main = do
|
|
handleCmdLineInput =<< execParser opts
|
|
where
|
|
opts :: ParserInfo CmdLineInput
|
|
opts =
|
|
info
|
|
(cmdLineInput <**> helper)
|
|
( fullDesc
|
|
<> progDesc "Interpreter for LOX language from Crafting Interpreters"
|
|
<> header "Interpreter for LOX language from Crafting Interpreters"
|
|
)
|