# Layer 4 — Incremental Parser (15000 lines target) ## What This Layer Does Tree-sitter / GLR incremental parser with error recovery. Parses the rope from Layer 3 into a concrete syntax tree (CST). Re-parses only changed regions on each keystroke — O(edit size * grammar size), not O(file size). ## Repos That Contribute | Repo | What to pull | |------|-------------| | **snapkitty-resonance-isa** | Abjad VM IR bytecode — maps directly to parser stack machine | | **snapkitty-resonance-bridge** | proof→SUBLEQ encoding — extract as parser IR substrate (EXTRACT) | | **j-matrix-twin** | SUBLEQ attention + WASM (EXTRACT) — alternative parser substrate for browser | | **systemic-intelligence** | GLR skeleton in OCaml section | ## What to Build First 1. Grammar representation — rule table, terminal/nonterminal IDs (use Layer 0 intern) 2. GLR parse table — state machine over the grammar 3. Incremental reparse — diff the rope edit, re-enter parser at affected range 4. Error recovery — skip/insert tokens, maintain partial tree 5. SUBLEQ substrate port — from j-matrix-twin for WASM browser path 6. Abjad VM IR — from snapkitty-resonance-isa as the hot-path parser stack ## Key Design Constraints - CST nodes in Layer 0 arena; GC via arena reset between full reparses - Edit regions from Layer 3 rope trigger incremental reparse only - Grammar tables are WORM-sealed after load (bifrost pattern from Layer 0) - Parser must run in O(n log n) worst case, not O(n^2)