Skip to main content

Module fsharp

Module fsharp 

Source
Expand description

Rendering the F# CST. Spec §5.

One style: four spaces, F#’s offside rule doing the indentation’s own job, /// for a documentation comment and // for a plain one. F# has no canonical formatter shipped with the compiler the way zig fmt is one, so unlike crate::zig there is no external tool this module’s layout is checked against; the generated file’s own indentation is the only contract, and it is four spaces throughout because F#’s indentation is significant and a generated file that mixed widths would not parse.

Nothing is decided here. An F# type reads left to right and carries its own optionality and dimensionality, so — as in crate::zig and unlike crate::c — there is no declarator to split around a name: a property is a name, a colon, and a type.

§Two things F#’s grammar puts here and nowhere else in this arc

  1. module rec. file() always writes the rec; the module documentation of zerodds_lang_cst::fsharp says why one word replaces a forward-declaration pass.
  2. The loop-break exception. Stmt::Until opens a try around the while it renders and closes it with with :? ZdWire.LoopBreak -> (); Stmt::Leave is the raise inside it. Neither statement carries a name for the other to agree on — the exception type is the coordination, and it is the runtime’s, not this renderer’s invention. Stmt::Guarded and Stmt::GiveBack are the same pair one try further out, for a return the shared walk writes inside a loop body: a filter matches on the exception’s type, so ZdWire.GiveBack passes straight through with :? ZdWire.LoopBreak -> ().

Functions§

decl
Render one declaration, for a caller that has only one.
expr
Render one expression, for a caller — a generator’s harness — that builds a Expr tree and needs its text to splice into a larger, hand-assembled program fragment.
file
Render a whole file.
ident
The identifier a name renders as, for a caller assembling one.
string_text
Escape a string for an F# string literal.
type_
Render one type, for a caller that has only one.