| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Text.PrettyPrint.Avh4.Block
Synopsis
- data Line
- space :: Line
- string7 :: String -> Line
- char7 :: Char -> Line
- stringUtf8 :: String -> Line
- lineFromBuilder :: Builder -> Line
- commentByteString :: ByteString -> Line
- data Block
- render :: Block -> Builder
- blankLine :: Block
- line :: Line -> Block
- mustBreak :: Line -> Block
- stack :: NonEmpty Block -> Block
- indent :: Block -> Block
- prefix :: Word -> Line -> Block -> Block
- addSuffix :: Line -> Block -> Block
- prefixOrIndent :: Maybe Line -> Line -> Block -> Block
- rowOrStack :: Maybe Line -> NonEmpty Block -> Block
- rowOrStackForce :: Bool -> Maybe Line -> NonEmpty Block -> Block
- rowOrIndent :: Maybe Line -> NonEmpty Block -> Block
- rowOrIndentForce :: Bool -> Maybe Line -> NonEmpty Block -> Block
- spaceSeparatedOrStack :: NonEmpty Block -> Block
- spaceSeparatedOrStackForce :: Bool -> NonEmpty Block -> Block
- spaceSeparatedOrIndent :: NonEmpty Block -> Block
- spaceSeparatedOrIndentForce :: Bool -> NonEmpty Block -> Block
- stackForce :: Block -> Block -> Block
- andThen :: [Block] -> Block -> Block
- joinMustBreak :: Block -> Block -> Block
Line
A Line is ALWAYS just one single line of text,
and can always be combined horizontally with other Lines.
Spaceis a single horizontal space,Blankis a line with no content.Textbrings any text into the data structure. (UsesBuilderfor the possibility of optimal performance)Rowjoins multiple elements onto one line.
A Line containing a single space. You **must** use this to create
space characters if the spaces will ever be at the start or end of a line that is joined in the context of indentation changes.
string7 :: String -> Line Source #
Creates a Line from the given String.
You must guarantee that all characters in the String are valid 7-bit ASCII characters,
and that the string does not start or end with spaces (use space instead).
char7 :: Char -> Line Source #
Creates a Line from the given Char.
You must guarantee that the given character is a valid 7-bit ASCII character,
and is not a space character (use space instead).
stringUtf8 :: String -> Line Source #
If you know the String only contains ASCII characters, then use string7 instead for better performance.
lineFromBuilder :: Builder -> Line Source #
You must guarantee that the content of the Builder does not contain newlines and does not start with whitespace.
commentByteString :: ByteString -> Line Source #
Block
Block contains Lines (at least one; it can't be empty).
Block either:
- can appear in the middle of a line (Stack someLine [], thus can be joined without problems), or
- has to appear on its own (Stack someLine moreLines OR MustBreak someLine).
Types of Blocks:
SingleLineis a single line, and the indentation level for the line.MustBreakis a single line (and its indentation level)) that cannot have anything joined to its right side. Notably, it is used for `--` comments.Stackcontains two or more lines, and the indentation level for each.
Sometimes (see prefix) the first line of Stack
gets different treatment than the other lines.
convert to
render :: Block -> Builder Source #
Converts a Block into a Builder.
You can then write to a file with writeFile,
or convert to Text with Data.Text.Encoding.decodeUtf8 . toLazyByteString
create
mustBreak :: Line -> Block Source #
Promote a Line into a Block that will always have a newline at the end of it,
meaning that this Line will never have another Line joined to its right side.
combine
stack :: NonEmpty Block -> Block Source #
A vertical stack of Blocks. The left edges of all the Blocks will be aligned.
indent :: Block -> Block Source #
Makes a new Block with the contents of the input Block indented by one additional level.
prefix :: Word -> Line -> Block -> Block Source #
Adds the prefix to the first line,
and pads the other lines with spaces of the given length.
You are responsible for making sure that the given length is the actual length of the content of the given Line.
NOTE: An exceptional case that we haven't really designed for is if the first line of the input Block is indented.
EXAMPLE:
abcde
xyz
----->
myPrefix abcde
xyz
addSuffix :: Line -> Block -> Block Source #
Adds the given suffix to then end of the last line of the Block.
rowOrStack :: Maybe Line -> NonEmpty Block -> Block Source #
This is the same as rowOrStackForce False.
rowOrStackForce :: Bool -> Maybe Line -> NonEmpty Block -> Block Source #
If all given Blocks are single-line and the Bool is False,
then makes a new single-line Block, with the Maybe Line interspersed.
Otherwise, makes a vertical stack of the given Blocks.
rowOrIndent :: Maybe Line -> NonEmpty Block -> Block Source #
Same as rowOrIndentForce False.
rowOrIndentForce :: Bool -> Maybe Line -> NonEmpty Block -> Block Source #
This is the same as rowOrStackForce, but all non-first lines in
the resulting block are indented one additional level.
spaceSeparatedOrStack :: NonEmpty Block -> Block Source #
A convenience alias for `rowOrStack (Just space)`.
spaceSeparatedOrStackForce :: Bool -> NonEmpty Block -> Block Source #
A convenience alias for `rowOrStackForce (Just space)`.
spaceSeparatedOrIndent :: NonEmpty Block -> Block Source #
A convenience alias for `rowOrIndentForce (Just space)`.
spaceSeparatedOrIndentForce :: Bool -> NonEmpty Block -> Block Source #
A convenience alias for `rowOrIndentForce (Just space)`.