cp-15 · Tooling and Diagnostics

A compiler is only as approachable as its error messages. cp-15 builds the tooling layer that wraps the language: a unified minilang CLI (run, fmt, ast, repl), rustc-style structured diagnostics with carets, source-span tracking, and a REPL with multi-line input.

Build & run

cmake -S src/cpp -B build
cmake --build build
./build/tests/test_tooling                       # → 46/46 checks passed

echo 'let x = 1+2*3; print x;' | ./build/minilang run -    # → 7
echo 'let  x= 1 +2;  print  x  ;' | ./build/minilang fmt -
./build/minilang repl
> let x = 10;
> print x * x;
100

What an error looks like:

$ echo 'print 1 +;' | ./build/minilang run -
error[E0202]: expected expression, got `;`
  --> <stdin>:1:10
    |
  1 | print 1 +;
    |          ^
    | help: try a number, a variable, or `(`

Layout

src/cpp/src/
    source.hpp/.cpp   — SourceFile with line index
    diag.hpp/.cpp     — Diagnostic + renderer
    lex.hpp/.cpp      — span-tracking tokenizer
    parse.hpp/.cpp    — recursive-descent parser with error recovery
    format.hpp/.cpp   — AST pretty printer
    eval.hpp/.cpp     — tree-walking evaluator
    repl.hpp/.cpp     — REPL loop with multi-line continuation
    main.cpp          — `minilang` CLI
tests/
    test_tooling.cpp  — 14 tests / 46 checks

Reading order

  1. steps/01-developer-experience-matters.md
  2. steps/02-source-spans-and-locations.md
  3. steps/03-rustc-style-diagnostics.md
  4. steps/04-parser-error-recovery.md
  5. steps/05-pretty-printing-and-formatting.md
  6. steps/06-building-a-repl.md
  7. steps/07-cli-design-and-lsp.md