Skip to content

Commit 11a8683

Browse files
authored
CSS static extraction and atomization (#573)
1 parent e538c89 commit 11a8683

731 files changed

Lines changed: 69338 additions & 17812 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cursor/documents/css-property-parser/rule-module-analysis.md

Lines changed: 0 additions & 632 deletions
This file was deleted.

.cursor/documents/lexer/current-state-lexers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ single token system backed by `Tokens.re` and consumed via external tokens in
1616
| System | Lexer Function | Returns | Used By |
1717
|--------|---------------|---------|---------|
1818
| Parser.mly | `get_next_tokens_with_location` | `Tokens.token_with_location` | `driver.re`, menhir parser |
19-
| Tokens.re | `consume` | `Tokens.token` | `css-property-parser` |
19+
| Tokens.re | `consume` | `Tokens.token` | `css-grammar` |
2020

2121
---
2222

@@ -237,9 +237,9 @@ HASH of (string * [`ID | `UNRESTRICTED])
237237
- Selector parsing (needs `DOT`, `COMBINATOR`, `OPERATOR`, `TAG`, etc.)
238238

239239
### Tokens.re tokens are used for:
240-
- CSS property value validation (`css-property-parser` package)
240+
- CSS property value validation (`css-grammar` package)
241241
- `Rule.re` pattern matching on token streams
242-
- `Standard.re` primitive extractors (`length`, `angle`, `percentage`, etc.)
242+
- `Css_value_types.re` primitive extractors (`length`, `angle`, `percentage`, etc.)
243243

244244
---
245245

@@ -292,5 +292,5 @@ Merge `get_next_token` and `consume` into single function returning the unified
292292
| `packages/parser/lib/Parser.mly` | Menhir grammar + token declarations |
293293
| `packages/parser/lib/driver.re` | Parser entry points |
294294
| `packages/parser/test/Lexer_test.re` | Tests for both lexers |
295-
| `packages/css-property-parser/lib/Rule.re` | Token stream parsing monad |
296-
| `packages/css-property-parser/lib/Standard.re` | Primitive value extractors |
295+
| `packages/css-grammar/lib/Rule.re` | Token stream parsing monad |
296+
| `packages/css-grammar/lib/Css_value_types.re` | Primitive value extractors |

.cursor/documents/lexer/lexer-unification-plan.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Remove the `tokenize` API and consolidate around `from_string` for batch tokeniz
1111
| API | Signature | Error Handling | Encoding | Used By |
1212
|-----|-----------|----------------|----------|---------|
1313
| `tokenize` | `string => result(list((token, pos, pos)), string)` | Catches `LexingError`, returns `Error(string)` | Utf8 | `Lexer_test.re`, `lexer_renderer.re` |
14-
| `from_string` | `string => list(token_with_location)` | **Mixed**: soft errors in stream, hard errors raise | Utf8 | `css-property-parser`, `Lexer_from_string_test.re` |
14+
| `from_string` | `string => list(token_with_location)` | **Mixed**: soft errors in stream, hard errors raise | Utf8 | `css-grammar`, `Lexer_from_string_test.re` |
1515
| `get_next_tokens_with_location` | `lexbuf => (token, pos, pos)` | Raises `LexingError` | N/A (caller provides lexbuf) | `driver.re` (menhir parser) |
1616

1717
### Important: `from_string` Has Dual Error Handling
@@ -53,7 +53,7 @@ eval $(opam env --switch=. --set-switch)
5353
make test-parser
5454
make test-ppx-native
5555
make test-css-support
56-
make test-css-property-parser
56+
make test-css-grammar
5757
```
5858

5959
---
@@ -227,7 +227,7 @@ let tokenize:
227227
make test-parser
228228
make test-ppx-native
229229
make test-css-support
230-
make test-css-property-parser
230+
make test-css-grammar
231231
make build
232232
```
233233

@@ -265,7 +265,7 @@ After each phase:
265265
- [ ] `make test-parser` passes
266266
- [ ] `make test-ppx-native` passes
267267
- [ ] `make test-css-support` passes
268-
- [ ] `make test-css-property-parser` passes
268+
- [ ] `make test-css-grammar` passes
269269

270270
---
271271

.cursor/hooks/state/continual-learning.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

.cursor/rules/md-documents.mdc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.cursor/rules/testing.mdc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ alwaysApply: true
99
File structure and test commands for each package:
1010

1111
packages
12-
├── css-property-parser
13-
│ └── test (to run those tests `make test-css-property-parser`)
12+
├── css-grammar
13+
│ ├── lib
14+
│ ├── ppx
15+
│ └── test (to run those tests `make test-css-grammar`)
1416
│ ├── Combinators_test.re
1517
│ ├── Modifiers_test.re
1618
│ ├── Rules_test.re
1719
│ ├── Runner.re
1820
│ ├── Standard_test.re
19-
│ ├── Types_test.re
20-
│ ├── dune
21-
│ └── snapshots
21+
│ ├── Parser_test.re
22+
│ ├── Interpolation_extraction_test.re
23+
│ └── dune
2224
├── css-spec-parser
2325
│ └── test (to run those tests `make test-css-spec-parser`)
2426
│ ├── dune

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ jobs:
8888
chmod +x "$OPAM_PATH"
8989
dirname "$OPAM_PATH" >> "$GITHUB_PATH"
9090
91+
- name: Pin dependencies
92+
run: make pin
93+
9194
- name: Install dependencies
9295
run: make install
9396

.ocamlformat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version=0.28.1
21
quiet=true
32
profile=default
43

.opencode/package-lock.json

Lines changed: 0 additions & 115 deletions
This file was deleted.

AGENTS.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,18 @@ The project consists of three main components:
3030
- Record observed failures with enough context (command, exit code, snippet of output) for reproducibility.
3131

3232
## Architecture Orientation
33-
- **Parser & Type Checker** (`packages/parser`, `packages/css-property-parser`): builds the CSS AST, validates properties via generated combinators (`[%value.rec ...]`), and produces rich error messages for invalid CSS.
33+
- **Parser & Type Checker** (`packages/parser`, `packages/css-grammar`): builds the CSS AST, validates properties via generated combinators (`[%spec ...]`), and produces rich error messages for invalid CSS.
3434
- **PPX Transformer** (`packages/ppx/src/ppx.re`): exposes interfaces like `[%styled.tag]`, `[%cx]`, `[%css]`, `[%cx2]`, and `[%keyframes]`; orchestrates parsing, validation, and code generation.
3535
- **Property → Runtime Bridge** (`packages/ppx/src/Property_to_runtime.re`): maps validated properties to runtime constructors, preserves interpolations, and decides extraction vs runtime emission.
3636
- **Runtimes** (`packages/runtime/native`, `.../melange`, `.../rescript`): emit CSS for native servers, JS environments, and ReScript compatibility. Shared types live in `packages/runtime/native/shared/Css_types.ml`.
3737
- **Extraction Pipeline**: `[%cx2]` is the only statically extracted path today; it generates CSS assets during compilation for zero runtime overhead.
3838

39-
## Common Tasks & Playbooks
40-
- **Feature work**: locate the relevant package, add parser rules or runtime constructors, extend PPX mapping, and update tests.
41-
- **Bug fixes**: reproduce with minimal repro (fixture or snapshot), craft targeted patches, and add regression coverage.
42-
- **Docs**: keep developer guides (like this file) up to date; cross-link to tooling instructions and testing docs.
43-
- **Reviews**: inspect diffs critically, reason about downstream impact (compile-time + runtime), and recommend follow-up tests when missing.
39+
## Reference Documents
40+
- Consult `documents/design.md` before making structural changes across `packages/parser`, `packages/css-grammar`, `packages/ppx`, or the runtime pipeline.
41+
- Consult `documents/primitives.md` for the shared glossary and preferred terminology used by humans and agents in architecture discussions.
4442

4543
## Troubleshooting Tips
4644
- Regenerate snapshots via the appropriate dune alias if expect tests fail after legitimate changes.
4745
- If opam tooling appears missing, double-check the `_opam` switch integrity before troubleshooting dune.
4846
- Watch for generated code churn; understand the source generator before editing outputs directly.
4947
- When PPX errors are opaque, reproduce with `dune exec -- <binary>` or `dune build --verbose` to capture the PPX invocation.
50-
51-
## Reference
52-
- Repository root: `/Users/davesnx/Code/github/davesnx/styled-ppx`
53-
- Dune binary: `/Users/davesnx/Code/github/davesnx/styled-ppx/_opam/bin/dune`
54-
- Key docs: `AGENT.md` (this guide), `testing.mdc` (testing policies), `docs/` (additional design notes), `packages/*` (source code).
55-
- Prefer absolute paths in tool calls and explanations so transcripts remain unambiguous.
56-
57-
Stay curious, verify assumptions, and leave the repo healthier than you found it.

0 commit comments

Comments
 (0)