Skip to content

michaelmillar/desugar

Repository files navigation

desugar

Build your own programming language from zero.

desugar is a browser-hosted compiler studio that walks you through building a real programming language. You start with raw text, grow a working compiler pass by pass, and finish with a programming language you can eject as its own standalone project. The language track is ML/Gleam-inspired, but the programming language you build is yours.

desugar compiler studio showing the three-pane workspace with guide, editor, and test output

What desugar is for

Most compiler material either stays academic or drops you into a half-built codebase. desugar takes a different approach: you build a complete programming language, end to end.

  • start from raw text and produce your first tokens
  • grow a real programming language instead of working through disconnected exercises
  • give your programming language a name, file extension, and CLI identity
  • test, benchmark, and unlock the next milestone in the browser
  • eject the finished programming language into its own repo

Today, the repo already includes:

  • a browser UI for milestone and lesson progression
  • learner onboarding that creates a named programming language workspace
  • single-file editing with save, reset, run-all, and per-test reruns
  • lesson-wide hints with score penalties
  • fixed benchmark tiers with bonus points
  • repo-local progress persistence in .desugar/desugar.db
  • export of the finished programming language into exports/<slug>/

desugar growth path from text to standalone programming language

How it works

The current repo is organized around three layers:

  • crates/desugar/: the web app, progression engine, workspace API, scoring, and eject flow
  • templates/ml-canonical/: the canonical seed programming language that gets personalised into languages/<slug>/
  • desugar-challenges/ and desugar-solutions/: lesson fixtures and references that power the current challenge flow

When a learner creates a profile, desugar generates a working programming language workspace like this:

languages/aster/
|-- Cargo.toml
`-- compiler/
    |-- Cargo.toml
    |-- src/
    |   `-- lib.rs
    |-- stub.rs
    `-- tests/
        |-- benchmark_compile.rs
        |-- evaluate_expressions.rs
        |-- parse_expressions.rs
        `-- text_and_tokens.rs

That generated workspace is the programming language you grow over time. The long-term direction is a full compiler journey from foundational text processing through parsing, typing, modules, lowering, backends, and eventually ejecting a usable programming language repo.

Quickstart

Prerequisites

  • Rust toolchain with cargo
  • Node.js if you want to run the browser-side test file

Shared Frontend Workspace

The browser UI source now lives in the sibling shared workspace at:

/home/markw/projects/studying/studying-ui

For frontend-only iteration:

pnpm --dir /home/markw/projects/studying/studying-ui run dev:desugar

To sync the latest built bundle back into this Rust app:

pnpm --dir /home/markw/projects/studying/studying-ui run build:all

Run the studio

cargo run -p desugar

Then open:

http://127.0.0.1:4001

Working example

This is the smallest useful loop in the current build.

1. Start desugar

cargo run -p desugar

2. Create your programming language in the browser

Use a profile like:

  • language name: Aster
  • slug: aster
  • file extension: .ast
  • CLI name: aster
  • package namespace: aster

That will generate languages/aster/ inside the repo.

3. Edit the generated compiler

Open the first lesson and work in:

languages/aster/compiler/src/lib.rs

The starter file is intentionally tiny. A first concrete implementation can be as small as:

pub fn compile(source: &str) -> String {
    source.split_whitespace().collect::<Vec<_>>().join(" ")
}

You can run the generated language tests directly from the terminal:

cargo test --manifest-path languages/aster/Cargo.toml -p aster-compiler

4. Progress and eject

Once the core lesson is completed, the studio can export your language into:

exports/aster/

That gives you a standalone programming language repo you can take further on its own.

Verification

These are the current project checks:

cargo fmt
cargo test -p desugar
node --test crates/desugar/static/app.test.mjs
pnpm --dir /home/markw/projects/studying/studying-ui test

Current direction

desugar is being shaped into a programming language incubator:

  • foundations first: text, tokens, parsing, and simple evaluation
  • one canonical ML/Gleam-like programming language track
  • light personalisation without forking the curriculum
  • backends that can graduate over time, starting from the simplest useful path
  • eject the programming language into a separate repo once it is strong enough

The current implementation already supports the studio workflow, generated programming language workspaces, scoring, persistence, and export. The broader compiler journey is the next layer to build on top of that foundation.

About

Build a programming language from zero; learn compilers

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors