emit-portable: windowed relexing for newline-mode lexers (S4, #57)#65
Merged
Conversation
Newline-only grammars extract lexFrom with flowDepth-aware AlignMeta, resync, and streamEq checks while regex/template grammars keep full fallback. 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 4 of #57 (portable incremental
edit). Extends S3's windowed relexing (#64) from stateless lexers to newline-mode lexers (e.g. envspec):pos,pendingNl,lineStart,emittedContent,flowDepth), the first four hold constant values at every token-emission point — the only one that varies isflowDepth. So each token'sAlignMetanow records the flow depth after its emission (fd), and a windowed scan can restart from any token boundary with state{pos: end(anchor), pendingNl: false, lineStart: false, emittedContent: true, flowDepth: fd(anchor)}.fdto equal the live scan depth — an insertion of(that shifts downstream flow depth correctly refuses to adopt the old suffix (gate scenario dedicated to this). Zero-width NEWLINE tokens sharing an offset with their successor are disambiguated by kind during resync lookup.streamEqself-check comparesfdtoo, so an adopted-but-wrong depth cannot survive as a latent state bomb for the next edit.pendingNl = trueon LF/CR inside flow suspension; the interpreter does not (non-indent newline mode). Removed — direct token-stream comparison against the oracle lexer over flow/newline-heavy inputs is now field-identical. (Latent in S3: CST output doesn't carrynl, and the old envspec edit scenario forced full relex.)relexed ≤ 10, two-batch depth-inheritance chain); 21 scenarios × 3 targets total.Validation
node test/portable-targets.ts— calc 8/8 + javascript 5/5 + envspec 8/8, × 3 targets; allstreamEqtruenode test/check.ts emit-parity— 5/5;node test/newline-mode.ts— 29/29;npx tsc --noEmit— cleanfdresync check makes the depth-shift scenario fail (streamEq:false+ align mismatch), reverted before commit