emit-portable: windowed relexing for regex-context lexers (S5a, #57)#66
Merged
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Slice 5a of #57 (portable incremental
edit). Extends windowed relexing (#64, #65) to lexers with regex-vs-division context (regexCtx, no templates — e.g. regexjs):prevText/prevKind/bpText/hasPrev/hasPrev2are rebuilt directly from the token stream at the restart anchor;lastClose/lastBangare recorded per token (their post-emission values) and read back; theparenHeadboolean stack is reconstructed backward from per-token paren depth (pd) plus a head bit (hd) recorded on(tokens — porting thereconstructParensargument from the JS incremental lexer.lastClose/lastBang, and previous-token text. Any mismatch keeps scanning instead of adopting the old suffix.streamEqself-check now compares the recorded state fields too, so an adopted suffix with stale context state cannot survive silently.aturns two divisions into one regex literal;if→fturns a regex back into divisions), an unbalanced-(insertion that must refuse resync, and a)-anchored append whose relex outcome hinges on the restoredlastClosebit.Validation
node test/portable-targets.ts— calc 8/8, javascript 5/5 (still full-relex), regexjs 6/6, envspec 8/8, × 3 targets, allstreamEqtruenode test/check.ts emit-parity— 5/5;node test/newline-mode.ts— 29/29;npx tsc --noEmit— cleanlastCloserestore fails the)-anchor scenario; dropping the paren-stack comparison fails the unbalanced-(scenario — both reverted before commit(inside a regex body (not a real paren), division after], non-head)anchor withlastClose=false, two-batch state inheritance chain — all parity with oracle-derived expectations