1
1
{-# LANGUAGE PatternGuards #-}
2
2
{-# LANGUAGE PatternSynonyms #-}
3
3
{-# LANGUAGE RecordWildCards #-}
4
+ {-# LANGUAGE MultiWayIf #-}
4
5
5
6
import Control.Applicative
6
7
import Control.Monad
@@ -227,10 +228,10 @@ extractHeader mod = extract
227
228
228
229
-- | A crude classifier looking for lines containing options
229
230
230
- data Status = Deprecated | Unsafe | Safe
231
- deriving (Eq )
231
+ data Safety = Unsafe | Safe deriving ( Eq )
232
+ data Status = Deprecated | Active deriving (Eq )
232
233
233
- classify :: FilePath -> [String ] -> [String ] -> Exc Status
234
+ classify :: FilePath -> [String ] -> [String ] -> Exc ( Safety , Status )
234
235
classify fp hd ls
235
236
-- We start with sanity checks
236
237
| isUnsafe && safe = throwError $ fp ++ contradiction " unsafe" " safe"
@@ -239,11 +240,12 @@ classify fp hd ls
239
240
| isWithK && not withK = throwError $ fp ++ missingWithK
240
241
| not (isWithK || cubicalC) = throwError $ fp ++ uncategorized " as relying on K" " cubical-compatible"
241
242
-- And then perform the actual classification
242
- | deprecated = pure $ Deprecated
243
- | isUnsafe = pure $ Unsafe
244
- | safe = pure $ Safe
245
- -- We know that @not (isUnsafe || safe)@, all cases are covered
246
- | otherwise = error " IMPOSSIBLE"
243
+ | otherwise = do
244
+ let safety = if | safe -> Safe
245
+ | isUnsafe -> Unsafe
246
+ | otherwise -> error " IMPOSSIBLE"
247
+ let status = if deprecated then Deprecated else Active
248
+ pure (safety, status)
247
249
248
250
where
249
251
@@ -280,18 +282,20 @@ classify fp hd ls
280
282
data LibraryFile = LibraryFile
281
283
{ filepath :: FilePath -- ^ FilePath of the source file
282
284
, header :: [String ] -- ^ All lines in the headers are already prefixed with \"-- \".
283
- , status :: Status -- ^ Safety options used by the module
285
+ , safety :: Safety
286
+ , status :: Status -- ^ Deprecation status options used by the module
284
287
}
285
288
286
289
analyse :: FilePath -> IO LibraryFile
287
290
analyse fp = do
288
291
ls <- lines <$> readFileUTF8 fp
289
292
hd <- runExc $ extractHeader fp ls
290
- cl <- runExc $ classify fp hd ls
293
+ (sf, st) <- runExc $ classify fp hd ls
291
294
return $ LibraryFile
292
- { filepath = fp
293
- , header = hd
294
- , status = cl
295
+ { filepath = fp
296
+ , header = hd
297
+ , safety = sf
298
+ , status = st
295
299
}
296
300
297
301
checkFilePaths :: String -> [FilePath ] -> IO ()
@@ -356,7 +360,7 @@ main = do
356
360
unlines [ header
357
361
, " {-# OPTIONS --safe --guardedness #-}\n "
358
362
, mkModule safeOutputFile
359
- , format $ filter ((Unsafe /= ) . status ) libraryfiles
363
+ , format $ filter ((Unsafe /= ) . safety ) libraryfiles
360
364
]
361
365
362
366
-- | Usage info.
0 commit comments