SMLFORMAT(1)

SMLFORMAT(1) πŸ’–

okay bestie, welcome to the General Commands Manual section, page 1, and today's main character is smlformat β€” the pretty printer generator for SML# ✨ (yes, that's literally what the NAME says, we're not skipping anything here 🫢)


✨ NAME ✨

smlformat β€” the pretty printer generator for SML# πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

smlformat [--stdout|--output=file] [--with-line-directive] filename ...

like. look at it. so clean. so iconic. πŸ‘‘


🌸 DESCRIPTION 🌸

okay so here's the tea, bestie πŸ“ SMLFormat generates pretty printing functions for ML types and datatypes. That's the whole vibe.

The input file is an SML# program, and every type and datatype in it is annotated by formatting comments ✍️. The smlformat command interprets the definition of types and its formatting comments, and then inserts formatting functions into the input program. So it's giving "glow-up but for your source code" ✨. And the generated programs can be compiled by the SML# compiler, no cap πŸ”₯.

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. (so ex.ppg becomes ex.ppg.sml, cute right? πŸŽ€)


πŸ’… OPTIONS πŸ’…

  • --stdout β€” Output the result to the standard output. straight to your terminal, no file, no drama 🌈
  • --output=filename β€” Output the result to the specified file. you pick the name, you pick the destiny ✨
  • --with-line-directive β€” Insert comments about the line number of the input file into the output. receipts, but for line numbers 🧾
  • --separate=structureName β€” Output formatters in a separate structure. formatters get their own little apartment 🏠

πŸ¦‹ EXAMPLES πŸ¦‹

okay this is the part where it gets real. 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. yes bestie, that tiny little comment is doing SO much work 😭

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. it just slips in there. ate. πŸ’…

heads up bestie!! 🚨 To compile the generated program, you need to write an interface file ex.ppg.smi by yourself. no autopilot for this one, sorry. 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

like. gorgeous. no notes. 🌟


🌈 SEE ALSO 🌈


and that's the whole page babes, from the SMLFORMAT(1) up top all the way down to that little SMLFORMAT(1) footer at the bottom β€” that's the man page name stamped on the last line, the version/source line of the General Commands Manual πŸ’– go forth and pretty-print, you absolute icon πŸ‘‘βœ¨πŸŽ€

πŸ“¦ where this page comes from