Skip to content

fix!(ltk_ritobin): half-open spans and balanced visitor unwinding - #188

Open
Crauzer wants to merge 5 commits into
mainfrom
ritobin/cst-semantics
Open

fix!(ltk_ritobin): half-open spans and balanced visitor unwinding#188
Crauzer wants to merge 5 commits into
mainfrom
ritobin/cst-semantics

Conversation

@Crauzer

@Crauzer Crauzer commented Aug 24, 2026

Copy link
Copy Markdown
Member

Two breaking semantic fixes to the CST layer plus two small walk features, split out so they land ahead of the Locator/Visitor API work (#176, #175) that builds on them. No file overlap with feat/ptch-resolve, which can rebase cleanly after this merges.

Span semantics

  • Span::contains is now half-open, matching intersects (the ltk_ritobin: Add Locator API #176 checkbox): a boundary offset belongs to exactly one of two adjacent spans, and empty spans contain nothing. No in-crate caller relied on the inclusive end; downstream (LSP) finders should re-check boundary handling.
  • Parser "expected ..." error spans are clamped to the source instead of pointing one byte past EOF.

Visitor walk semantics

  • Visit::Stop now unwinds: exit_tree runs exactly once for every entered node, innermost first, wherever the Stop came from (enter_tree, visit_token, a descendant, or exit_tree itself). Previously open ancestors skipped their exits, corrupting downstream scope stacks - the bug noted in ltk_ritobin: Add Locator API #176.
  • Visit::Skip is scoped per callback: from enter_tree it skips the node's children, from visit_token the node's remaining children, and from exit_tree it prunes the parent's remaining children - the sibling-skip that used to happen by accident is now a documented semantic.
  • Cst::walk reports how it ended: WalkOutcome::{Completed, Stopped}, so finders that Stop on success no longer need a found-it flag.
  • Walk internals now run on ControlFlow<Unwind>, and the printer stops writing after its first error.

@Crauzer
Crauzer requested a review from alanpq August 24, 2026 13:19
@Crauzer Crauzer added crate:ltk_ritobin Ritobin text format crate area:api Public API design priority:high High priority labels Aug 24, 2026
@Crauzer Crauzer self-assigned this Aug 24, 2026
@Crauzer
Crauzer force-pushed the ritobin/cst-semantics branch from c9a8f62 to 1af7966 Compare August 24, 2026 13:31

@alanpq alanpq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a Visit::Abort that has the original no-unwind behaviour, and an Aborted outcome as well

@Crauzer
Crauzer requested a review from alanpq August 24, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:api Public API design crate:ltk_ritobin Ritobin text format crate priority:high High priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants