Skip to content

Commit 630ba49

Browse files
committed
kore-parser options pattern and module must now go together
1 parent bba3857 commit 630ba49

File tree

1 file changed

+82
-19
lines changed

1 file changed

+82
-19
lines changed

kore/src/Kore/OptionsParser.hs

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,20 @@ enableDisableFlag name enabledVal disabledVal defaultVal helpSuffix =
4848
<> help ( "Enable/disable " ++ helpSuffix ) )
4949
<|> pure defaultVal
5050

51-
-- | Main options record
52-
data KoreParserOptions = KoreParserOptions
53-
{ fileName :: !FilePath
54-
-- ^ Name for a file containing a definition to parse and verify
55-
, patternFileName :: !FilePath
51+
52+
data PatternOptions = PatternOptions
53+
{ patternFileName :: !FilePath
5654
-- ^ Name for file containing a pattern to parse and verify
5755
, mainModuleName :: !Text
5856
-- ^ the name of the main module in the definition
57+
}
58+
59+
-- | Main options record
60+
data KoreParserOptions' = KoreParserOptions'
61+
{ fileName :: !FilePath
62+
-- ^ Name for a file containing a definition to parse and verify
63+
, patternOpt :: !(Maybe PatternOptions)
64+
-- ^ Optional options for parsing a pattern
5965
, willPrintDefinition :: !Bool
6066
-- ^ Option to print definition
6167
, willPrintPattern :: !Bool
@@ -66,24 +72,40 @@ data KoreParserOptions = KoreParserOptions
6672
-- ^ Option to print in applicative Kore syntax
6773
}
6874

75+
76+
data KoreParserOptions = KoreParserOptions
77+
{ fileName :: !FilePath
78+
, patternFileName :: !FilePath
79+
, mainModuleName :: !Text
80+
, willPrintDefinition :: !Bool
81+
, willPrintPattern :: !Bool
82+
, willVerify :: !Bool
83+
, appKore :: !Bool
84+
}
85+
6986
-- | Command Line Argument Parser
70-
commandLineParser :: Parser KoreParserOptions
71-
commandLineParser =
72-
KoreParserOptions
87+
commandLineParser' :: Parser KoreParserOptions'
88+
commandLineParser' =
89+
KoreParserOptions'
7390
<$> argument str
7491
( metavar "FILE"
7592
<> help "Kore source file to parse [and verify]" )
76-
<*> strOption
77-
( metavar "PATTERN_FILE"
78-
<> long "pattern"
79-
<> help
80-
"Kore pattern source file to parse [and verify]. Needs --module."
81-
<> value "" )
82-
<*> strOption
83-
( metavar "MODULE"
84-
<> long "module"
85-
<> help "The name of the main module in the Kore definition"
86-
<> value "" )
93+
<*> ( (Just <$>
94+
(PatternOptions
95+
<$> strOption
96+
( metavar "PATTERN_FILE"
97+
<> long "pattern"
98+
<> help "Kore pattern source file to parse [and verify]. Needs --module.")
99+
<*> strOption
100+
( metavar "MODULE"
101+
<> long "module"
102+
<> help "The name of the main module in the Kore definition")
103+
)
104+
)
105+
<|> flag Nothing Nothing
106+
( long "definition-only"
107+
<> help "No Kore pattern may be checked against the definition")
108+
)
87109
<*> enableDisableFlag "print-definition"
88110
True False False
89111
"printing parsed definition to stdout [default disabled]"
@@ -98,3 +120,44 @@ commandLineParser =
98120
( "printing parsed definition in applicative Kore syntax "
99121
++ "[default disabled]"
100122
)
123+
124+
-- TODO (MirceaS): Refactor the code that uses the
125+
-- command line parser so that it uses the new
126+
-- KoreParserOptions options type so that we may
127+
-- remove the terms below
128+
129+
morph :: KoreParserOptions' -> KoreParserOptions
130+
morph kpo
131+
| Nothing <- patternOpt = KoreParserOptions
132+
{ fileName
133+
, patternFileName = ""
134+
, mainModuleName = ""
135+
, willPrintDefinition
136+
, willPrintPattern
137+
, willVerify
138+
, appKore
139+
}
140+
| Just PatternOptions
141+
{ patternFileName
142+
, mainModuleName
143+
} <- patternOpt = KoreParserOptions
144+
{ fileName
145+
, patternFileName
146+
, mainModuleName
147+
, willPrintDefinition
148+
, willPrintPattern
149+
, willVerify
150+
, appKore
151+
}
152+
where
153+
KoreParserOptions'
154+
{ fileName
155+
, patternOpt
156+
, willPrintDefinition
157+
, willPrintPattern
158+
, willVerify
159+
, appKore
160+
} = kpo
161+
162+
commandLineParser :: Parser KoreParserOptions
163+
commandLineParser = morph <$> commandLineParser'

0 commit comments

Comments
 (0)