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 = … ; declarations and a trailing main expression both work.

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 (~336 lines, Stage 50a) — source string → tokens
  2. parser.mere (~1010 lines, Stages 50b–50e) — tokens → AST
  3. fmt.mere (~480 lines, Stage 49b) — 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 followed by a main expression — the same shape Mere itself uses. The output is byte-identical to running mere fmt on the OCaml side for the slice of syntax both formatters cover (see "Limitations" below for what's still out of scope).

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.

Limitations

Why this matters

Self-hosting both the parser and the formatter closes the §S1 plan (paper trial):