-
Notifications
You must be signed in to change notification settings - Fork 197
/
Extension.hs
62 lines (53 loc) · 2.48 KB
/
Extension.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
52
53
54
55
56
57
58
59
60
61
62
module Extension(
defaultExtensions,
configExtensions,
extensionImpliedEnabledBy,
extensionImplies
) where
import Data.List.Extra
import qualified Data.Map as Map
import GHC.LanguageExtensions.Type
import qualified Language.Haskell.GhclibParserEx.GHC.Driver.Session as GhclibParserEx
badExtensions =
reallyBadExtensions ++
[ Arrows -- steals proc
, UnboxedTuples, UnboxedSums -- breaks (#) lens operator
, QuasiQuotes -- breaks [x| ...], making whitespace free list comps break
, {- DoRec , -} RecursiveDo -- breaks rec
]
reallyBadExtensions =
[ TransformListComp -- steals the group keyword
, StaticPointers -- steals the static keyword
{- , XmlSyntax , RegularPatterns -} -- steals a-b and < operators
, AlternativeLayoutRule -- Does not play well with 'MultiWayIf'
, NegativeLiterals -- Was not enabled by HSE and enabling breaks tests.
, StarIsType -- conflicts with TypeOperators. StarIsType is currently enabled by default,
-- so adding it here has no effect, but it may not be the case in future GHC releases.
]
-- | Extensions we turn on by default when parsing. Aim to parse as
-- many files as we can.
defaultExtensions :: [Extension]
defaultExtensions = enumerate \\ badExtensions
-- | Extensions we turn on when reading config files, don't have to deal with the whole world
-- of variations - in particular, we might require spaces in some places.
configExtensions :: [Extension]
configExtensions = enumerate \\ reallyBadExtensions
-- | This extension implies the following extensions are
-- enabled/disabled.
extensionImplies :: Extension -> ([Extension], [Extension])
extensionImplies = \x ->Map.findWithDefault ([], []) x mp
where mp = Map.fromList extensionImplications
-- 'x' is implied enabled by the result extensions.
extensionImpliedEnabledBy :: Extension -> [Extension]
extensionImpliedEnabledBy = \x -> Map.findWithDefault [] x mp
where
mp = Map.fromListWith (++) [(b, [a]) | (a, (bs, _)) <- extensionImplications, b <- bs]
-- 'x' is implied disabled by the result extensions. Not called at this time.
_extensionImpliedDisabledBy :: Extension -> [Extension]
_extensionImpliedDisabledBy = \x -> Map.findWithDefault [] x mp
where
mp = Map.fromListWith (++) [(b, [a]) | (a, (_, bs)) <- extensionImplications, b <- bs]
-- | (a, bs) means extension a implies all of bs. Uses GHC source at
-- DynFlags.impliedXFlags
extensionImplications :: [(Extension, ([Extension], [Extension]))]
extensionImplications = GhclibParserEx.extensionImplications