v11 Pratt parser#240
Conversation
ludofischer
left a comment
There was a problem hiding this comment.
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.
ludofischer
left a comment
There was a problem hiding this comment.
It's good that you are comparing against the csstools output, as I suppose they checked they're fairly spec-compliant. Are you also testing against the current postcss-calc test suite? There's a lot of code here. when do you think it's going to stabilize so I can look at it more thoroughly?
|
|
||
| async function main(): Promise<void> { | ||
| // Dynamic imports so CJS/ESM interop works under tsx. | ||
| const v10Plugin = (await import('../src/index.js')).default as () => AcceptedPlugin; |
There was a problem hiding this comment.
I find the naming (version 10? version 3?) strange, I don't think we need dynamic import either, we can drop Node 20 compatibility if we release a major.
| "fast-check": "^4.7.0", | ||
| "jison-gho": "0.6.1-216", | ||
| "postcss": "^8.5.10", | ||
| "prettier": "^3.8.3", |
There was a problem hiding this comment.
I think you can update TypeScript to the latest version. cssnano is also using it. You could even try TypeScript go.
| "target": "es2022", | ||
| "lib": ["es2022"], | ||
| "module": "esnext", | ||
| "moduleResolution": "bundler", |
There was a problem hiding this comment.
Why are there two tsconfig files?
e362c9e to
16c1db0
Compare
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 tokensparser.ts— §10.1 grammar (Pratt + parselet registry)type.ts— §10.2 calculation typessimplify.ts— §10.10 simplificationserialize.ts— §10.12 output169 tests (parser / tokenizer / simplify / typed / opaque / serialize / WPT crib), run via
pnpm test:pratt.tsxruntime, no build step.See
ROADMAP.mdfor more details