4 Pretty-Printing
This library provides facilities for pretty-printing JavaScript source. It be can required via:
(require (planet dherman/javascript:6/print)) |
This library depends on the pprint PLaneT package, which can be required via:
(require (planet dherman/pprint:4))
See the documentation for pprint for information on how to use it.
4.1 Formatting Terms
term : Term/X? |
Formats any JavaScript term as a doc for pretty-printing.
element : SourceElement? |
Formats a JavaScript source element as a doc for pretty-printing.
init : VariableInitializer? |
Formats a variable initializer as a doc for pretty-printing.
decl : Declaration? |
Formats a declaration as a doc for pretty-printing.
expr : Expression/X? |
Formats an expression as a doc for pretty-printing.
expr : Expression? |
parent : Expression? |
Formats an expression expr that occurs as an immediate subexpression of parent as a doc for pretty-printing. The parenthesization is determined based on the precedence of the two expressions.
stmt : Statement/X? |
Formats a statement as a doc for pretty-printing. Post-conditions: The statement output includes its own semicolon if appropriate, and statement output is not newline-terminated.
stmt : SubStatement/X? |
Formats a statement that occurs as an indented substatement as a doc for pretty-printing. Post-condition: The indentation level is returned to its previous level after the substatement.
stmt : SubStatement/X? |
Formats a statement that occurs as a substatement as a doc for pretty-printing.
clause : CaseClause? |
Formats a case clause as a doc for pretty-printing.
property : Property? |
Formats an object property as a doc for pretty-printing.
id : Identifier? |
Formats an identifier as a doc for pretty-printing.
4.2 Configuration Parameters
The number of spaces to indent.
(Currently ignored.)
Non-block substatements stay on same line?
4.3 Extending the Pretty-Printer
As described in Extending the Language, it is possible to extend the language with custom forms. The pretty-printer can be extended with extra matchers that recognize just their form types and produce pretty-printed docs. Matchers should simple fail to match (raising the same error as (match) would for anything other than the forms they recognize.
| |
| |
|
f : (a -> c) |
elts : (or (listof a) b) |
param : (parameter (b -> c)) |
Applies a formatter to an extensible list of terms (such as an ExpressionList/X or StatementList/X). If the formatter fails to match, the current value of the param parameter is used to format the elements instead.
4.4 S-Expression Syntax
This module also provides a few utilities for generating an alternative S-expression syntax of JavaScript.
x : any |
Determines whether x is an S-expression.
expr : Expression? |
Creates an S-expression representation of an expression.
stmt : Statement? |
Creates an S-expression representation of a statement.
elt : SourceElement? |
Creates an S-expression representation of a source element.