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:
lexer.mere— source string → tokensparser.mere— tokens → source ASTfmt.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
-
Full native syntax is not covered: for example, visibility markers,
view,dropandsignaturedeclarations remain outside the self-host parser's subset. - Comments and import statements are not preserved.
Why this matters
Self-hosting both the parser and the formatter closes the §S1 plan:
- Stage 49a–b — Mere AST + pretty-printer in Mere
- Stage 49d — early browser demo with hand-coded ASTs
- Stage 50a–e — self-host parser, end-to-end
- Stage 50f-1 — lift AST into shared
ast.mere - Stage 50f-2 — this page: live in-browser
mere fmt