table of contents
- unstable 4.0.0+git20211227.5af5945b-2
SMLFORMAT(1) | General Commands Manual | SMLFORMAT(1) |
NAME¶
smlformat - the pretty printer generator for SML#
SYNOPSIS¶
smlformat [--stdout|--output=file] [--with-line-directive] filename ...
DESCRIPTION¶
SMLFormat generates pretty printing functions for ML types and datatypes. The input file is an SML# program, each type and datatype of which is annotated by formatting comments. The smlformat command interprets the definition of types and its formatting comments and inserts formatting functions into the input program. Generated programs can be compiled by the SML# compiler.
When multiple input files are given, each input file is separately read and yields a separate program. By default, the output file name is obtained by appending .sml suffix to the input file name.
OPTIONS¶
- --stdout
- Output the result to the standard output.
- --output=filename
- Output the result to the specified file.
- --with-line-directive
- Insert comments about the line number of the input file into the output.
- --separate=structureName
- Output formatters in a separate structure.
EXAMPLES¶
The following is a minimal example of an input file ex.ppg:
(*% *) datatype intlist = NIL | CONS of int * intlist fun pretty_intlist x =
SMLFormat.prettyPrint nil (format_intlist x)
where (*% *) is the formatting comment of the intlist type. By invoking smlformat,
smlformat ex.ppg
it interprets the formatting comment and generates format_intlist function of type intlist -> SMLFormat.format. In the output file ex.ppg.sml, the definition of format_intlist is inserted just after the definition of the intlist type.
To compile the generated program, you need to write an interface file ex.ppg.smi by yourself. In the interface file, the SMLFormat library smlformat-lib.smi must be required. The content of ex.ppg.smi must be as follows:
_require "basis.smi" _require "smlformat-lib.smi" datatype intlist = NIL | CONS of int * intlist val format_intlist : intlist -> SMLFormat.format val pretty_intlist : intlist -> string
SEE ALSO¶
SML# Document, available at https://www.pllab.riec.tohoku.ac.jp/smlsharp/docs/