Mere fmt — written in Mere, running in the browser

Paste a Mere expression or a full file on the left and press Format. The Wasm module on this page tokenizes, parses, and pretty-prints your input — all written in Mere itself, no server round-trip. Top-level let X = … ; / let rec … ; / type T = … ;, nested module declarations, extern fn and extern type declarations all work, with an optional trailing main expression.

Source: lexer.mere, parser.mere, fmt.mere, bridged by selfhost-fmt.mere. The shared AST lives in contrib/parser/ast.mere.

(click Format to see the formatted output)

Pipeline

Three contrib libraries combine into the wasm running on this page:

  1. lexer.mere — source string → tokens
  2. parser.mere — tokens → source AST
  3. fmt.mere — source AST → formatted source

They share the same expr / pattern / ty definitions through ast.mere (Stage 50f-1's refactor), which is what lets a single browser bridge file import both ends and pipe values through with no translation layer.

What this page formats

Single expressions and full files both work. A full file looks like a sequence of let X = e ; / let rec X = e ; / type T = … ; declarations, including nested modules and extern signatures, followed by an optional main expression. Module boundaries and declaration order are preserved. Modules and aliases may use a different layout from the native formatter; the formatted program retains its behavior.

Things to try: arithmetic with precedence, let / let rec bindings, if / match control flow, curried lambdas (the formatter reverses the chain back into \x y -> body shorthand), constructor patterns, list literals, ranges, variant type declarations, annotated lambdas like fn (n: int) -> n + 1, records, parameterized types, nested modules and opaque extern handles.

Limitations

Why this matters

Self-hosting both the parser and the formatter closes the §S1 plan: