-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArgumentParser.hs
51 lines (41 loc) · 1.36 KB
/
ArgumentParser.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
-- simplify-bkg
-- Marek Beňo
-- xbenom01
{-|
Module : ArgumentParser
Description : Parser module for program arguments
Module which uses optparse-aplicative for parsing program arguments
-}
module ArgumentParser where
import Options.Applicative
import Data.Semigroup ((<>))
import Control.Monad
import Types
-- | parses program arguments into @Arguments@ structure
argumentParser :: Parser Arguments
argumentParser = Arguments
<$> (dumpParser <|> alg1Parser <|> alg2Parser)
<*> argument str (metavar "FILENAME" <> help "Filename of input file" <> value "")
-- | parses @Dump@ action in @Arguments@ structure
dumpParser :: Parser ArgumentAction
dumpParser = flag' Dump
( short 'i'
<> help "specifies action as printing parsed input"
)
-- | parses @Alg1@ action in @Arguments@ structure
alg1Parser :: Parser ArgumentAction
alg1Parser = flag' Alg1
( short '1'
<> help "specifies action as aplying algorithm 4.1 to parsed grammar"
)
-- | parses @Alg2@ action in @Arguments@ structure
alg2Parser :: Parser ArgumentAction
alg2Parser = flag' Alg2
( short '2'
<> help "specifies action as aplying algorithm 4.1 to parsed grammar"
)
-- | provides program info
opts = info (argumentParser <**> helper)
( fullDesc
<> progDesc "parses CFG grammar from input stream and simplifies it."
<> header "Program for simplyfing CFG grammar" )