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 -> Text
- printDocB :: Bool -> Doc -> Builder
- printDocS :: Bool -> Doc -> String
- renderOps :: RenderDoc op => Bool -> NonEmpty op -> Doc
- renderOpsList :: RenderDoc op => Bool -> [op] -> Doc
- renderOpsListNoBraces :: RenderDoc op => Bool -> [op] -> Doc
- renderAnyBuildable :: Buildable a => a -> Doc
- wrapInParens :: RenderContext -> NonEmpty Doc -> Doc
- buildRenderDoc :: RenderDoc a => a -> Builder
- buildRenderDocExtended :: RenderDoc a => a -> Builder
- 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 Text.PrettyPrint.Leijen.Text.Doc. Used to pretty print Michelson code and define Fmt.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
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 |
Instances
Functor Prettier Source # | |
RenderDoc (Prettier T) Source # | |
Defined in Morley.Michelson.Typed.T | |
RenderDoc (Prettier ParameterType) Source # | |
Defined in Morley.Michelson.Untyped.Type renderDoc :: RenderContext -> Prettier ParameterType -> Doc Source # isRenderable :: Prettier ParameterType -> Bool Source # | |
RenderDoc (Prettier Ty) Source # | |
Defined in Morley.Michelson.Untyped.Type |
renderOps :: RenderDoc op => Bool -> NonEmpty op -> Doc Source #
Generic way to render the different op types that get passed to a contract.
renderOpsList :: RenderDoc op => Bool -> [op] -> Doc Source #
Render a comma-separated list of items in braces
renderOpsListNoBraces :: RenderDoc op => Bool -> [op] -> Doc Source #
Render a semi-colon-separated list of items without braces
renderAnyBuildable :: Buildable a => a -> Doc Source #
wrapInParens :: RenderContext -> NonEmpty Doc -> Doc Source #
Wrap documents in parentheses if there are two or more in the list.
buildRenderDoc :: RenderDoc a => a -> Builder Source #
buildRenderDocExtended :: RenderDoc a => a -> Builder Source #
Works as buildRenderDoc
above, but doesn't force the doc to be printed in one line
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
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.