@@ -28,9 +28,7 @@ module Development.IDE.GHC.ExactPrint
28
28
TransformT ,
29
29
Anns ,
30
30
Annotate ,
31
- mkBindListT ,
32
31
setPrecedingLinesT ,
33
- everywhereM' ,
34
32
)
35
33
where
36
34
@@ -56,6 +54,7 @@ import Development.Shake (RuleResult, Rules)
56
54
import Development.Shake.Classes
57
55
import qualified GHC.Generics as GHC
58
56
import Generics.SYB
57
+ import Generics.SYB.GHC
59
58
import Ide.PluginUtils
60
59
import Language.Haskell.GHC.ExactPrint
61
60
import Language.Haskell.GHC.ExactPrint.Parsers
@@ -67,8 +66,7 @@ import Parser (parseIdentifier)
67
66
import Data.Traversable (for )
68
67
import Data.Foldable (Foldable (fold ))
69
68
import Data.Bool (bool )
70
- import Data.Monoid (All (All ), Any (Any ), getAll )
71
- import Data.Functor.Compose (Compose (Compose ))
69
+ import Data.Monoid (All (All ), getAll )
72
70
import Control.Arrow
73
71
74
72
@@ -328,21 +326,6 @@ graftWithM dst trans = Graft $ \dflags a -> do
328
326
)
329
327
a
330
328
331
- -- | A generic query intended to be used for calling 'smallestM' and
332
- -- 'largestM'. If the current node is a 'Located', returns whether or not the
333
- -- given 'SrcSpan' is a subspan. For all other nodes, returns 'Nothing', which
334
- -- indicates uncertainty. The search strategy in 'smallestM' et al. will
335
- -- continue searching uncertain nodes.
336
- genericIsSubspan ::
337
- forall ast .
338
- Typeable ast =>
339
- -- | The type of nodes we'd like to consider.
340
- Proxy (Located ast ) ->
341
- SrcSpan ->
342
- GenericQ (Maybe Bool )
343
- genericIsSubspan _ dst = mkQ Nothing $ \ case
344
- (L span _ :: Located ast ) -> Just $ dst `isSubspanOf` span
345
-
346
329
-- | Run the given transformation only on the smallest node in the tree that
347
330
-- contains the 'SrcSpan'.
348
331
genericGraftWithSmallestM ::
@@ -370,15 +353,6 @@ genericGraftWithLargestM proxy dst trans = Graft $ \dflags ->
370
353
largestM (genericIsSubspan proxy dst) (trans dflags)
371
354
372
355
373
- -- | Lift a function that replaces a value with several values into a generic
374
- -- function. The result doesn't perform any searching, so should be driven via
375
- -- 'everywhereM' or friends.
376
- --
377
- -- The 'Int' argument is the index in the list being bound.
378
- mkBindListT :: forall b m . (Data b , Monad m ) => (Int -> b -> m [b ]) -> GenericM m
379
- mkBindListT f = mkM $ fmap join . traverse (uncurry f) . zip [0 .. ]
380
-
381
-
382
356
graftDecls ::
383
357
forall a .
384
358
(HasDecls a ) =>
@@ -432,12 +406,6 @@ graftDeclsWithM dst toDecls = Graft $ \dflags a -> do
432
406
modifyDeclsT (fmap DL. toList . go) a
433
407
434
408
435
- everywhereM' :: forall m . Monad m => GenericM m -> GenericM m
436
- everywhereM' f = go
437
- where
438
- go :: GenericM m
439
- go = gmapM go <=< f
440
-
441
409
class (Data ast , Outputable ast ) => ASTElement ast where
442
410
parseAST :: Parser (Located ast )
443
411
maybeParensAST :: Located ast -> Located ast
@@ -547,76 +515,3 @@ render dflags = showSDoc dflags . ppr
547
515
parenthesize :: LHsExpr GhcPs -> LHsExpr GhcPs
548
516
parenthesize = parenthesizeHsExpr appPrec
549
517
550
-
551
- ------------------------------------------------------------------------------
552
- -- Custom SYB machinery
553
- ------------------------------------------------------------------------------
554
-
555
- -- | Generic monadic transformations that return side-channel data.
556
- type GenericMQ r m = forall a . Data a = > a -> m (r , a )
557
-
558
- ------------------------------------------------------------------------------
559
- -- | Apply the given 'GenericM' at all every node whose children fail the
560
- -- 'GenericQ', but which passes the query itself.
561
- --
562
- -- The query must be a monotonic function when it returns 'Just'. That is, if
563
- -- @s@ is a subtree of @t@, @q t@ should return @Just True@ if @q s@ does. It
564
- -- is the True-to-false edge of the query that triggers the transformation.
565
- --
566
- -- Why is the query a @Maybe Bool@? The GHC AST intersperses 'Located' nodes
567
- -- with data nodes, so for any given node we can only definitely return an
568
- -- answer if it's a 'Located'. See 'genericIsSubspan' for how this parameter is
569
- -- used.
570
- smallestM :: forall m . Monad m => GenericQ (Maybe Bool ) -> GenericM m -> GenericM m
571
- smallestM q f = fmap snd . go
572
- where
573
- go :: GenericMQ Any m
574
- go x = do
575
- case q x of
576
- Nothing -> gmapMQ go x
577
- Just True -> do
578
- it@ (r, x') <- gmapMQ go x
579
- case r of
580
- Any True -> pure it
581
- Any False -> fmap (Any True ,) $ f x'
582
- Just False -> pure (mempty , x)
583
-
584
- ------------------------------------------------------------------------------
585
- -- | Apply the given 'GenericM' at every node that passes the 'GenericQ', but
586
- -- don't descend into children if the query matches. Because this traversal is
587
- -- root-first, this policy will find the largest subtrees for which the query
588
- -- holds true.
589
- --
590
- -- Why is the query a @Maybe Bool@? The GHC AST intersperses 'Located' nodes
591
- -- with data nodes, so for any given node we can only definitely return an
592
- -- answer if it's a 'Located'. See 'genericIsSubspan' for how this parameter is
593
- -- used.
594
- largestM :: forall m . Monad m => GenericQ (Maybe Bool ) -> GenericM m -> GenericM m
595
- largestM q f = go
596
- where
597
- go :: GenericM m
598
- go x = do
599
- case q x of
600
- Just True -> f x
601
- Just False -> pure x
602
- Nothing -> gmapM go x
603
-
604
- newtype MonadicQuery r m a = MonadicQuery
605
- { runMonadicQuery :: m (r , a )
606
- }
607
- deriving stock (Functor )
608
- deriving Applicative via Compose m ((,) r )
609
-
610
-
611
- ------------------------------------------------------------------------------
612
- -- | Like 'gmapM', but also returns side-channel data.
613
- gmapMQ ::
614
- forall f r a . (Monoid r , Data a , Applicative f ) =>
615
- (forall d . Data d => d -> f (r , d )) ->
616
- a ->
617
- f (r , a )
618
- gmapMQ f = runMonadicQuery . gfoldl k pure
619
- where
620
- k :: Data d => MonadicQuery r f (d -> b ) -> d -> MonadicQuery r f b
621
- k c x = c <*> MonadicQuery (f x)
622
-
0 commit comments