Safe Haskell | None |
---|---|
Language | Haskell2010 |
Cabal file formatter.
- pretty :: GenericPackageDescription -> Doc
- prettyWithIndent :: Int -> GenericPackageDescription -> Doc
- render :: Int -> Doc -> SimpleDoc
- parseCabalFile :: String -> Result GenericPackageDescription
- readCabalFile :: Maybe FilePath -> String -> IO GenericPackageDescription
- data Result a
- result :: (Maybe LineNo -> String -> b) -> ([PWarning] -> b) -> (a -> b) -> Result a -> b
- printWarnings :: Foldable t => t PWarning -> IO b
- displayError :: Maybe FilePath -> Maybe LineNo -> String -> IO a
- data Doc :: *
- plain :: Doc -> Doc
- displayIO :: Handle -> SimpleDoc -> IO ()
- displayS :: SimpleDoc -> ShowS
Formatting Cabal files
pretty :: GenericPackageDescription -> Doc Source #
pretty pkg
produces a colorized, formatted textual representation of
a given GenericPackageDescription
,
with a default indent width of 2.
To remove syntax highlighting, you can use plain
.
prettyWithIndent :: Int -> GenericPackageDescription -> Doc Source #
Like pretty
, but allows you to specify an indent size.
Parsing utilities
parseCabalFile :: String -> Result GenericPackageDescription Source #
This function is similar to Cabal's own file parser, except that it treats warnings as a separate failure case. There are a wide range of different behaviors accepted by different Cabal parser versions. Parse warnings generally indicate a version-related inconsistency, so we play it safe here.
readCabalFile :: Maybe FilePath -> String -> IO GenericPackageDescription Source #
Shorthand to combine parseCabalFile
and one of printWarnings
or
displayError
. The given FilePath
is used only for error messages and
is not read from.
Like Cabal's ParseResult
, but treats warnings as a separate failure
case.
result :: (Maybe LineNo -> String -> b) -> ([PWarning] -> b) -> (a -> b) -> Result a -> b Source #
Case analysis for Result
.
displayError :: Maybe FilePath -> Maybe LineNo -> String -> IO a Source #
Print a parse error to stderr
, annotated with filepath and line
number (if available), then exit.
Reexports
The abstract data type Doc
represents pretty documents.
More specifically, a value of type Doc
represents a non-empty set of
possible renderings of a document. The rendering functions select one of
these possibilities.
Doc
is an instance of the Show
class. (show doc)
pretty
prints document doc
with a page width of 80 characters and a
ribbon width of 32 characters.
show (text "hello" <$> text "world")
Which would return the string "hello\nworld", i.e.
hello world
displayIO :: Handle -> SimpleDoc -> IO () #
(displayIO handle simpleDoc)
writes simpleDoc
to the file
handle handle
. This function is used for example by hPutDoc
:
hPutDoc handle doc = displayIO handle (renderPretty 0.4 80 doc)
Any ANSI colorisation in simpleDoc
will be output.
displayS :: SimpleDoc -> ShowS #
(displayS simpleDoc)
takes the output simpleDoc
from a
rendering function and transforms it to a ShowS
type (for use in
the Show
class).
showWidth :: Int -> Doc -> String showWidth w x = displayS (renderPretty 0.4 w x) ""
ANSI color information will be discarded by this function unless you are running on a Unix-like operating system. This is due to a technical limitation in Windows ANSI support.