Skip to content

v11 Pratt parser#240

Draft
dkryaklin wants to merge 6 commits intopostcss:masterfrom
dkryaklin:v11/spec-first-playground
Draft

v11 Pratt parser#240
dkryaklin wants to merge 6 commits intopostcss:masterfrom
dkryaklin:v11/spec-first-playground

Conversation

@dkryaklin
Copy link
Copy Markdown

@dkryaklin dkryaklin commented Apr 22, 2026

What

A decoupled prototype of new calc() internals under playground/pratt/

Why

v10 uses a JISON-generated LR parser and an ad-hoc reducer. It doesn't cover min() / max() / clamp(), typed division (calc(100vw / 1px)), or calc-keyword folding (pi, e, infinity). CSS Values & Units 4 §10 gives a deterministic simplification algorithm — implementing it directly makes correctness reviewable section-by-section rather than invented-and-patched.

How

Five TS modules, each mapped one-to-one to a spec section:

  • tokenizer.ts — §10.1 tokens
  • parser.ts — §10.1 grammar (Pratt + parselet registry)
  • type.ts — §10.2 calculation types
  • simplify.ts — §10.10 simplification
  • serialize.ts — §10.12 output

169 tests (parser / tokenizer / simplify / typed / opaque / serialize / WPT crib), run via pnpm test:pratt. tsx runtime, no build step.

See ROADMAP.md for more details

@dkryaklin dkryaklin changed the title v11 spec-first playground: Pratt parser + §10.10 simplifier v11 Pratt parser Apr 24, 2026
Copy link
Copy Markdown
Collaborator

@ludofischer ludofischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting! How much is AI generated? I am asking because I had thought of trying to use AI to generate a "hand-written" parser, but never tried it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants