Skip to content

Commit b84f773

Browse files
committed
Fix Read instance of FortranVersion so that it recognises things like Fortran77Extended
1 parent 8204f52 commit b84f773

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/Main.hs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Data.Text.Encoding (encodeUtf8, decodeUtf8With)
88
import Data.Text.Encoding.Error (replace)
99

1010
import Text.PrettyPrint (render)
11+
import Text.Read
1112

1213
import System.Console.GetOpt
1314

@@ -211,8 +212,8 @@ options :: [OptDescr (Options -> Options)]
211212
options =
212213
[ Option ['v']
213214
["fortranVersion"]
214-
(ReqArg (\v opts -> opts { fortranVersion = Just $ read v }) "VERSION")
215-
"Fortran version to use, format: Fortran[66/77/77Extended/90]"
215+
(ReqArg (\v opts -> opts { fortranVersion = readMaybe v }) "VERSION")
216+
"Fortran version to use, format: Fortran[66/77/77Legacy/77Extended/90]"
216217
, Option ['a']
217218
["action"]
218219
(ReqArg (\a opts -> opts { action = read a }) "ACTION")
@@ -260,21 +261,21 @@ compileArgs args =
260261
header = "Usage: forpar [OPTION...] <lex|parse> <file>"
261262

262263
instance Read FortranVersion where
263-
readsPrec _ value =
264-
let options = [ ("66", Fortran66)
265-
, ("77e", Fortran77Extended)
266-
, ("77l", Fortran77Legacy)
267-
, ("77", Fortran77)
268-
, ("90", Fortran90)
269-
, ("95", Fortran95)
270-
, ("03", Fortran2003)
271-
, ("08", Fortran2008)
272-
] in
273-
tryTypes options
274-
where
275-
tryTypes [] = []
276-
tryTypes ((attempt,result):xs) =
277-
if attempt `isInfixOf` value then [(result, "")] else tryTypes xs
264+
readsPrec _ value = tryTypes options
265+
where
266+
value' = map toLower value
267+
options = [ ("66" , Fortran66)
268+
, ("77e", Fortran77Extended)
269+
, ("77l", Fortran77Legacy)
270+
, ("77" , Fortran77)
271+
, ("90" , Fortran90)
272+
, ("95" , Fortran95)
273+
, ("03" , Fortran2003)
274+
, ("08" , Fortran2008) ]
275+
tryTypes [] = []
276+
tryTypes ((attempt,result):xs)
277+
| attempt `isInfixOf` value' = [(result, "")]
278+
| otherwise = tryTypes xs
278279

279280
instance {-# OVERLAPPING #-} Show [ FixedForm.Token ] where
280281
show = unlines . lines'

0 commit comments

Comments
 (0)