emit-portable: segment reuse for newline-interleaved entries (#57 S8) - #70
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.
Extends tree reuse (#69) to newline-interleaved entry grammars — the env-spec/dotenv family that is monogram's core use case. Previously these grammars only got the lexer-side incremental path (windowed relexing) and always reported
reused: 0.Shape B eligibility
Reuse eligibility now also accepts entries of the form
[opt(rule)] star(seq(tok, opt(rule)))(envspec'sProgram = [opt(Stmt), many(Newline, opt(Stmt))]). The reuse unit becomes a segment — one star iteration (Newlineleaf + optionalStmt), or the optional head statement. Segments are bookkeeping only: the CST keeps its flat[Stmt?, Newline, Stmt?, …]children and the JSON output is byte-identical to master.The reuse decision is the same algorithm as #69, applied to segments: keep-prefix by lookahead watermark (
ext <= prefix), keep-suffix bytokStart >= oldN - suffix, exact boundary hit for adoption, zero mutation on every fallback path. Two envspec-specific hazards are pinned by mutation tests:extmust include the failedopt(Stmt)probe after theNewline(span end alone is unsound);Newlinetokens share byte offsets with adjacent statements, so all decisions use token indices; bytes are only used for the adoption shift.Shape A grammars (calc/javascript/…) are untouched — gate numbers and CST bytes are identical to master.
Go lookahead watermark fix (review round)
Cross-target fuzzing during review caught
reuseddiverging between targets (Go one segment higher than TS/Rust) on comment/blank-line documents. Root cause: Go'smatchLit/matchTokreadtoks[pos]directly without updatingmaxLook, while TS/Rust route probes throughpeek(). A failed probe is lookahead — missing it lets keep-prefix admit a segment whose parse examined the damaged region. Benign in the caught instance (treeEqstayed true) but unsound in general; Go matchers now update the watermark, and the three targets agree everywhere the fuzz can reach.Validation
treeEq.