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
- printRenderDoc :: (RenderDoc a, FromSimpleDoc b) => Bool -> a -> b
- renderOpsList :: (RenderDoc op, Foldable f) => Bool -> f op -> Doc
- renderOpsListNoBraces :: (RenderDoc op, Foldable f) => Bool -> f op -> Doc
- wrapInParens :: RenderContext -> NonEmpty Doc -> 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
printRenderDoc :: (RenderDoc a, FromSimpleDoc b) => Bool -> a -> b Source #
Convert anything renderable to some text format with line width of 80.
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
wrapInParens :: RenderContext -> NonEmpty Doc -> Doc Source #
Wrap documents in parentheses if there are two or more in the list.
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.