Added a useful function to Pass for applying a modification function to the Only parts of a Structured
This commit is contained in:
parent
e8189e196b
commit
6a3452f8cd
|
@ -34,6 +34,7 @@ import Errors
|
|||
import Metadata
|
||||
import PrettyShow
|
||||
import TreeUtils
|
||||
import Utils
|
||||
|
||||
-- | The monad in which AST-mangling passes operate.
|
||||
type PassM = ErrorT ErrorReport (StateT CompState (WriterT [WarningReport] IO))
|
||||
|
@ -137,6 +138,13 @@ debugAST p
|
|||
veryDebug $ pshow ps
|
||||
veryDebug $ "}}}"
|
||||
|
||||
applyToOnly :: (Monad m, Data a) => (a -> m a) -> A.Structured a -> m (A.Structured a)
|
||||
applyToOnly f (A.Rep m r s) = applyToOnly f s >>* A.Rep m r
|
||||
applyToOnly f (A.Spec m sp s) = applyToOnly f s >>* A.Spec m sp
|
||||
applyToOnly f (A.ProcThen m p s) = applyToOnly f s >>* A.ProcThen m p
|
||||
applyToOnly f (A.Several m ss) = mapM (applyToOnly f) ss >>* A.Several m
|
||||
applyToOnly f (A.Only m o) = f o >>* A.Only m
|
||||
|
||||
-- | Make a generic rule for a pass.
|
||||
makeGeneric :: (Data t) => (forall s. Data s => s -> PassM s) -> t -> PassM t
|
||||
makeGeneric top
|
||||
|
|
Loading…
Reference in New Issue
Block a user