4 Pretty-Printing
This library provides facilities for pretty-printing JavaScript source. It can be required via:
(require javascript/print) | package: javascript |
This library depends on the pprint package, which can be required via:
(require pprint)
See the documentation for pprint for information on how to use it.
4.1 Formatting Terms
procedure
(format-term term) → doc?
term : Term/X?
procedure
(format-source-element element) → doc?
element : SourceElement?
procedure
(format-variable-initializer init) → doc?
init : VariableInitializer?
procedure
(format-declaration decl) → doc?
decl : Declaration?
procedure
(format-expression expr) → doc?
expr : Expression/X?
procedure
(format-subexpression expr parent) → doc?
expr : Expression? parent : Expression?
procedure
(format-statement stmt) → doc?
stmt : Statement/X?
procedure
(format-nested-substatement stmt) → doc?
stmt : SubStatement/X?
procedure
(format-substatement stmt) → doc?
stmt : SubStatement/X?
procedure
(format-case-clause clause) → doc?
clause : CaseClause?
procedure
(format-property property) → doc?
property : Property?
procedure
(format-identifier id) → doc?
id : Identifier?
4.2 Configuration Parameters
value
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.
value
formatters/Expression : (parameter/c (listof (any -> doc?)))
value
formatters/Statement : (parameter/c (listof (any -> doc?)))
value
formatters/ExpressionList : (parameter/c (listof (any -> doc?)))
value
formatters/StatementList : (parameter/c (listof (any -> doc?)))
procedure
(format-map f elts param) → c
f : (a -> c) elts : (or (listof a) b) param : (parameter/c (b -> c))