module-management-0.17.1: Clean up module imports, split and merge modules

Safe HaskellNone

Language.Haskell.Modules.Fold

Description

foldModule is a utility function used to implement the clean, split, and merge operations.

Synopsis

Documentation

foldModuleSource

Arguments

:: forall r . Show r 
=> (String -> r -> r)

Receives the space before the first pragma.

-> (ModulePragma -> String -> String -> String -> r -> r)

Called once for each pragma. In this and the similar arguments below, the three string arguments contain the comments and space preceding the construct, the text of the construct and the space following it.

-> (ModuleName -> String -> String -> String -> r -> r)

Called with the module name.

-> (WarningText -> String -> String -> String -> r -> r)

Called with the warning text between module name and export list

-> (String -> r -> r)

Called with the export list open paren

-> (ExportSpec -> String -> String -> String -> r -> r)

Called with each export specifier

-> (String -> r -> r)

Called with the export list close paren and where keyword

-> (ImportDecl -> String -> String -> String -> r -> r)

Called with each import declarator

-> (Decl -> String -> String -> String -> r -> r)

Called with each top level declaration

-> (String -> r -> r)

Called with comments following the last declaration

-> ModuleInfo

Parsed module

-> r

Fold initialization value

-> r

Result

Given the result of parseModuleWithComments and the original module text, this does a fold over the parsed module contents, calling the seven argument functions in order. Each function is passed the AST value, the text of the space and comments leading up to the element, and the text for the element. Note that not everything passed to the pre argument of the functions will be comments and space - for example, the module keyword will be passed in the pre argument to the ModuleName function.

foldHeader :: forall r. Show r => (String -> r -> r) -> (ModulePragma -> String -> String -> String -> r -> r) -> (ModuleName -> String -> String -> String -> r -> r) -> (WarningText -> String -> String -> String -> r -> r) -> ModuleInfo -> r -> rSource

Do just the header portion of foldModule.

foldExports :: forall r. Show r => (String -> r -> r) -> (ExportSpec -> String -> String -> String -> r -> r) -> (String -> r -> r) -> ModuleInfo -> r -> rSource

Do just the exports portion of foldModule.

foldImports :: forall r. Show r => (ImportDecl -> String -> String -> String -> r -> r) -> ModuleInfo -> r -> rSource

Do just the imports portion of foldModule.

foldDecls :: forall r. Show r => (Decl -> String -> String -> String -> r -> r) -> (String -> r -> r) -> ModuleInfo -> r -> rSource

Do just the declarations portion of foldModule.

echo :: Monoid m => t -> m -> m -> m -> Seq m -> Seq mSource

This can be passed to foldModule to include the original text in the result

echo2 :: Monoid m => m -> Seq m -> Seq mSource

Similar to echo, but used for the two argument separator functions

ignore :: t -> m -> m -> m -> r -> rSource

This can be passed to foldModule to omit the original text from the result.

ignore2 :: m -> r -> rSource

Similar to ignore, but used for the two argument separator functions