Skip to content

Build a Code Formatter

Build a Wadler-style pretty printer like prettier/black/gofmt: parse to AST/CST, define a Doc algebra (text/line/group/nest), make line-break decisions based on width, preserve comments through formatting, support hanging indent + alignment. The toolchain backbone of every modern codebase.

intermediate10 lessons4 chapters10 graded exercisesPython

No sign-up needed for lesson 1 · certificate on completion · sign up to save progress

What you’ll have built

Chapter by chapter. Every step is a graded exercise.

  • Why Formatters
  • Wadler's Algebra
  • Implementation
  • Production
Starts in Python — solve in the language you choose in the editor, same tests either way.

Curriculum

4 chapters, 10 lessons. Each lesson is a short read, one graded exercise, and a quiz.

  1. 1What Formatters SolveRead · exercise · quiz
  2. 2Single-Pass Pretty PrintingRead · exercise · quiz
  3. 3Indentation TrackingRead · exercise · quiz
Loading reference solution…
Build a Code Formatter