Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Utilities for rendering Michelson code in a format compatible with
Octez software (e.g octez-client
)
Synopsis
- class RenderDoc a where
- renderDoc :: RenderContext -> a -> Doc
- isRenderable :: a -> Bool
- newtype Prettier a = Prettier a
- printDoc :: Bool -> Doc -> LText
- printDocB :: Bool -> Doc -> Builder
- printDocS :: Bool -> Doc -> String
- printRenderDoc :: (RenderDoc a, FromSimpleDoc b) => Bool -> a -> b
- renderOps :: RenderDoc op => Bool -> NonEmpty op -> Doc
- renderOpsList :: (RenderDoc op, Foldable f) => Bool -> f op -> Doc
- renderOpsListNoBraces :: (RenderDoc op, Foldable f) => Bool -> f op -> Doc
- renderAnyBuildable :: Buildable a => a -> Doc
- wrapInParens :: RenderContext -> NonEmpty Doc -> Doc
- buildRenderDoc :: RenderDoc a => a -> Doc
- buildRenderDocExtended :: RenderDoc a => a -> Doc
- renderDocList :: RenderDoc a => RenderContext -> [a] -> Doc
- data RenderContext
- needsParens :: RenderContext
- doesntNeedParens :: RenderContext
- addParens :: RenderContext -> Doc -> Doc
- addParensMultiline :: RenderContext -> Doc -> Doc
- assertParensNotNeeded :: RenderContext -> a -> a
Documentation
class RenderDoc a where Source #
Generalize converting a type into a Doc
. Used to pretty print Michelson
code and define Buildable
instances.
renderDoc :: RenderContext -> a -> Doc Source #
isRenderable :: a -> Bool Source #
Whether a value can be represented in Michelson code.
Normally either all values of some type are renderable or not renderable.
However, in case of instructions we have extra instructions which should
not be rendered.
Note: it's not sufficient to just return mempty
for such instructions,
because sometimes we want to print lists of instructions and we need to
ignore them complete (to avoid putting redundant separators).
Instances
Deprecated: This has no actual effect nowadays
A new type that can wrap values so that the RenderDoc instances of the combined value can have a different behavior for the pretty printer.
Prettier a | Deprecated: This has no actual effect nowadays |
printDoc :: Bool -> Doc -> LText Source #
Deprecated: Use printRenderDoc instead
Convert Doc
to LText
with a line width of 80.
printRenderDoc :: (RenderDoc a, FromSimpleDoc b) => Bool -> a -> b Source #
Convert anything renderable to some text format with line width of 80.
renderOps :: RenderDoc op => Bool -> NonEmpty op -> Doc Source #
Deprecated: Use renderOpsList instead
Generic way to render the different op types that get passed to a contract.
renderOpsList :: (RenderDoc op, Foldable f) => Bool -> f op -> Doc Source #
Render a comma-separated list of items in braces
renderOpsListNoBraces :: (RenderDoc op, Foldable f) => Bool -> f op -> Doc Source #
Render a semi-colon-separated list of items without braces
renderAnyBuildable :: Buildable a => a -> Doc Source #
Deprecated: Use build instead
wrapInParens :: RenderContext -> NonEmpty Doc -> Doc Source #
Wrap documents in parentheses if there are two or more in the list.
buildRenderDoc :: RenderDoc a => a -> Doc Source #
buildRenderDocExtended :: RenderDoc a => a -> Doc Source #
Deprecated: RenderDoc
already implies Buildable
, use build
if you can
Works as buildRenderDoc
above, but doesn't group
.
renderDocList :: RenderDoc a => RenderContext -> [a] -> Doc Source #
Renders a list of RenderDoc
elements surrounded with square brackets,
separated by a comma and a space.
Smart parentheses
data RenderContext Source #
Environment carried during recursive rendering.
needsParens :: RenderContext Source #
Constructors for RenderContext
doesntNeedParens :: RenderContext Source #
Constructors for RenderContext
addParens :: RenderContext -> Doc -> Doc Source #
Add parentheses if needed.
addParensMultiline :: RenderContext -> Doc -> Doc Source #
Add parentheses if needed, multiline if necessary.
assertParensNotNeeded :: RenderContext -> a -> a Source #
Ensure parentheses are not required, for case when you cannot sensibly wrap your expression into them.