Render a syntax tree as a pretty-printable document (simply showing the resultant doc produces a nice, well formatted String).
Moduleghc-9.10.3GHC2021
GHC.JS.Ppr
Domain and Purpose
GHC.JS.Ppr defines the code generation facilities for the JavaScript backend. That is, this module exports a function from the JS backend IR to JavaScript compliant concrete syntax that can readily be executed by nodejs or called in a browser.
Design
This module follows the architecture and style of the other backends in GHC: it intances Outputable for the relevant types, creates a class that describes a morphism from the IR domain to JavaScript concrete Syntax and then generates that syntax on a case by case basis.
How to use
The key functions are
renderJS,jsToDoc, and theRenderJSrecord. Use theRenderJSrecord andjsToDocto define a custom renderers for specific parts of the backend, for example inGHC.StgToJS.Linker.Opta custom renderer ensures allIdentgenerated by the linker optimization pass are prefixed differently than the default. UserenderJSto generate JavaScript concrete syntax in the general case, suitable for human consumption.
- 1 type
- 2 classes
- 9 values
- Packageghc-9.10.3
- Exports12
- LanguageGHC2021
- LicenceBSD-3-Clause
- SourcePpr.hs
Render a syntax tree as a pretty-printable document, using a given prefix to all generated names. Use this with distinct prefixes to ensure distinct generated names between independent calls to render(Prefix)Js.
Instances6JsToDoc
JsRender controls the differences in whitespace between HLine and SDoc. Generally, this involves the indentation and newlines in the human-readable SDoc implementation being replaced in the HLine version by the minimal whitespace required for valid JavaScript syntax.
Methods
(<+?>) :: doc -> doc -> docConcatenate with an optional single space
($$$) :: doc -> doc -> docConcatenate with an optional newline
jcat :: [doc] -> docConcatenate these
docs, either vertically (SDoc) or horizontally (HLine)jnest :: doc -> docOptionally indent the following
addSemi :: doc -> docAppend semi-colon (and line-break in HLine mode)
The structure `{body}`, optionally indented over multiple lines
The structure `hdr {body}`, optionally indented over multiple lines